用任意一个按键模拟TAB键的功能void tab_simulate()
{ QKeyEvent event(QEvent::KeyPress, Qt::Key_Tab, Qt::NoModifier); QApplication::sendEvent(this, &event); QWidget* widget = this->focusWidget(); QPushButton* pushbutton = dynamic_cast<QPushButton*>(widget); while (pushbutton == 0) { QKeyEvent event(QEvent::KeyPress, Qt::Key_Tab, Qt::NoModifier); QApplication::sendEvent(this, &event); widget = this->focusWidget(); pushbutton = dynamic_cast<QPushButton*>(widget); } } 把它作为一个槽函数,用一个按钮的click()信号来和它connect起来即可 |
|