void tst_QMenu::statusTip() { //check that the statustip of actions inserted into the menu are displayed QMainWindow w; connect(w.statusBar(), SIGNAL(messageChanged(QString)), SLOT(onStatusMessageChanged(QString)));; //creates the status bar QToolBar tb; QAction a("main action", &tb); a.setStatusTip("main action"); QMenu m(&tb); QAction subact("sub action", &m); subact.setStatusTip("sub action"); m.addAction(&subact); a.setMenu(&m); tb.addAction(&a); w.addToolBar(&tb); w.show(); QVERIFY(QTest::qWaitForWindowExposed(&w)); QRect rect1 = tb.actionGeometry(&a); QToolButton *btn = qobject_cast<QToolButton*>(tb.childAt(rect1.center())); QVERIFY(btn != NULL); //because showMenu calls QMenu::exec, we need to use a singleshot //to continue the test QTimer::singleShot(200,this, SLOT(onStatusTipTimer())); btn->showMenu(); QVERIFY(statustip.isEmpty()); }
void tst_QToolBar::actionTriggered() { QToolBar tb; connect(&tb, SIGNAL(actionTriggered(QAction *)), SLOT(slot(QAction *))); QAction action1(0); QAction action2(0); QAction action3(0); QAction action4(0); tb.addAction(&action1); tb.addAction(&action2); tb.addAction(&action3); tb.addAction(&action4); tb.show(); #ifdef Q_WS_X11 qt_x11_wait_for_window_manager(&tb); #endif QList<QToolBarExtension *> extensions = tb.findChildren<QToolBarExtension *>(); QRect rect01; QRect rect02; QRect rect03; QRect rect04; QMenu *popupMenu; if (extensions.size() != 0) { QToolBarExtension *extension = extensions.at(0); if (extension->isVisible()) { QRect rect0 = extension->geometry(); QTest::mouseClick( extension, Qt::LeftButton, 0, rect0.center(), -1 ); QApplication::processEvents(); popupMenu = qobject_cast<QMenu *>(extension->menu()); rect01 = popupMenu->actionGeometry(&action1); rect02 = popupMenu->actionGeometry(&action2); rect03 = popupMenu->actionGeometry(&action3); rect04 = popupMenu->actionGeometry(&action4); } } QRect rect1 = tb.actionGeometry(&action1); QRect rect2 = tb.actionGeometry(&action2); QRect rect3 = tb.actionGeometry(&action3); QRect rect4 = tb.actionGeometry(&action4); QAbstractButton *button1; QAbstractButton *button2; QAbstractButton *button3; QAbstractButton *button4; if (!rect01.isValid()) { button1 = qobject_cast<QAbstractButton *>(tb.childAt(rect1.center())); QVERIFY(button1 != 0); } if (!rect02.isValid()) { button2 = qobject_cast<QAbstractButton *>(tb.childAt(rect2.center())); QVERIFY(button2 != 0); } if (!rect03.isValid()) { button3 = qobject_cast<QAbstractButton *>(tb.childAt(rect3.center())); QVERIFY(button3 != 0); } if (!rect04.isValid()) { button4 = qobject_cast<QAbstractButton *>(tb.childAt(rect4.center())); QVERIFY(button4 != 0); } ::triggered = 0; if (!rect01.isValid()) QTest::mouseClick(button1, Qt::LeftButton); else QTest::mouseClick(popupMenu, Qt::LeftButton, 0, rect01.center(), -1 ); QCOMPARE(::triggered, &action1); ::triggered = 0; if (!rect02.isValid()) QTest::mouseClick(button2, Qt::LeftButton); else QTest::mouseClick(popupMenu, Qt::LeftButton, 0, rect02.center(), -1 ); QCOMPARE(::triggered, &action2); ::triggered = 0; if (!rect03.isValid()) QTest::mouseClick(button3, Qt::LeftButton); else QTest::mouseClick(popupMenu, Qt::LeftButton, 0, rect03.center(), -1 ); QCOMPARE(::triggered, &action3); ::triggered = 0; if (!rect04.isValid()) QTest::mouseClick(button4, Qt::LeftButton); else QTest::mouseClick(popupMenu, Qt::LeftButton, 0, rect04.center(), -1 ); QCOMPARE(::triggered, &action4); }
void tst_QToolBar::actionGeometry() { QToolBar tb; QAction action1(0); QAction action2(0); QAction action3(0); QAction action4(0); tb.addAction(&action1); tb.addAction(&action2); tb.addAction(&action3); tb.addAction(&action4); tb.show(); #ifdef Q_WS_X11 qt_x11_wait_for_window_manager(&tb); #endif QList<QToolBarExtension *> extensions = tb.findChildren<QToolBarExtension *>(); QRect rect01; QRect rect02; QRect rect03; QRect rect04; QMenu *popupMenu; if (extensions.size() != 0) { QToolBarExtension *extension = extensions.at(0); if (extension->isVisible()) { QRect rect0 = extension->geometry(); QTest::mouseClick( extension, Qt::LeftButton, 0, rect0.center(), -1 ); QApplication::processEvents(); popupMenu = qobject_cast<QMenu *>(extension->menu()); rect01 = popupMenu->actionGeometry(&action1); rect02 = popupMenu->actionGeometry(&action2); rect03 = popupMenu->actionGeometry(&action3); rect04 = popupMenu->actionGeometry(&action4); } } QRect rect1 = tb.actionGeometry(&action1); QRect rect2 = tb.actionGeometry(&action2); QRect rect3 = tb.actionGeometry(&action3); QRect rect4 = tb.actionGeometry(&action4); QVERIFY(rect1.isValid()); QVERIFY(!rect1.isNull()); QVERIFY(!rect1.isEmpty()); QVERIFY(rect2.isValid()); QVERIFY(!rect2.isNull()); QVERIFY(!rect2.isEmpty()); QVERIFY(rect3.isValid()); QVERIFY(!rect3.isNull()); QVERIFY(!rect3.isEmpty()); QVERIFY(rect4.isValid()); QVERIFY(!rect4.isNull()); QVERIFY(!rect4.isEmpty()); if (rect01.isValid()) QCOMPARE(popupMenu->actionAt(rect01.center()), &action1); else QCOMPARE(tb.actionAt(rect1.center()), &action1); if (rect02.isValid()) QCOMPARE(popupMenu->actionAt(rect02.center()), &action2); else QCOMPARE(tb.actionAt(rect2.center()), &action2); if (rect03.isValid()) QCOMPARE(popupMenu->actionAt(rect03.center()), &action3); else QCOMPARE(tb.actionAt(rect3.center()), &action3); if (rect04.isValid()) QCOMPARE(popupMenu->actionAt(rect04.center()), &action4); else QCOMPARE(tb.actionAt(rect4.center()), &action4); }