我正在 QDockWidget 中创建一个简单的虚拟键盘...
当小部件停靠到 QMainWindow 时,选定的小部件(例如 qdoublespinbox)被突出显示,如果我单击虚拟键盘 clearFocus() 工作...
当 QDockWidget 浮动在窗口上方并且我单击一个按钮时,clearFocus 不起作用,我在 QMainWindow 中看不到焦点小部件...
如何强制 QDockWidget 根本没有任何焦点?
谢谢 :-)
这是代码:
// class MyVirtualKeyboard : public QDockWidget
void MyVirtualKeyboard::sendKey(Qt::Key key, Qt::KeyboardModifier mod)
{
this->clearFocus();
QMainWindow *w = dynamic_cast<QMainWindow *>(this->parent());
if(w == NULL) return;
QWidget *widget = w->focusWidget();
QString repr = QKeySequence(key).toString();
QKeyEvent *pressEvent = new QKeyEvent(QEvent::KeyPress, key, mod, repr);
QKeyEvent *releaseEvent = new QKeyEvent(QEvent::KeyRelease, key, mod, repr);
qDebug("%s", pressEvent->text().toAscii().data());
MyApplication *app = MyApplication::myInstance();
app->postEvent(widget, pressEvent);
app->postEvent(widget, releaseEvent);
}
void MyVirtualKeyboard::on_BTN_1_clicked()
{
sendKey(Qt::Key_1);
}
...