virtual bool eventFilter(QObject *o, QEvent *e) { QToolButton *button = qobject_cast<QToolButton *>(o); if (!button) return false; if (button->isEnabled()) return false; ToolBar *toolbar = qobject_cast<ToolBar *>(button->parentWidget()); if (!toolbar) return false; switch (e->type()) { case QEvent::MouseButtonPress: toolbar->widgetPressed(); return true; case QEvent::MouseMove: { QMouseEvent event(QEvent::MouseMove, toolbar->mapFromGlobal(QCursor::pos()), Qt::NoButton, ((QMouseEvent *)e)->buttons(), ((QMouseEvent *)e)->modifiers()); toolbar->mouseMoveEvent(&event); return event.isAccepted(); } case QEvent::ContextMenu: { QContextMenuEvent event(QContextMenuEvent::Mouse, toolbar->mapFromGlobal(QCursor::pos())); toolbar->contextMenuEvent(&event); return event.isAccepted(); } default: return false; } }
void KSelectAction_UnitTest::testRequestWidgetMenuModeWidgetParentSeveralActions() { KSelectAction selectAction("selectAction", 0); selectAction.setToolBarMode(KSelectAction::MenuMode); selectAction.addAction(new QAction("action1", &selectAction)); selectAction.addAction(new QAction("action2", &selectAction)); selectAction.addAction(new QAction("action3", &selectAction)); QToolBar toolBar; toolBar.addAction(&selectAction); QWidget* widget = toolBar.widgetForAction(&selectAction); QVERIFY(widget); QToolButton* toolButton = qobject_cast<QToolButton*>(widget); QVERIFY(toolButton); QVERIFY(toolButton->isEnabled()); QVERIFY(toolButton->autoRaise()); QCOMPARE((int)toolButton->focusPolicy(), (int)Qt::NoFocus); QCOMPARE(toolButton->defaultAction(), (QAction*)&selectAction); QCOMPARE(toolButton->actions().count(), 4); QCOMPARE(toolButton->actions().at(0)->text(), QString("selectAction")); QCOMPARE(toolButton->actions().at(1)->text(), QString("action1")); QCOMPARE(toolButton->actions().at(2)->text(), QString("action2")); QCOMPARE(toolButton->actions().at(3)->text(), QString("action3")); }
void EmailEditWidgetTest::shouldReadOnly() { EmailEditWidget widget; widget.setReadOnly(true); QLineEdit *lineedit = widget.findChild<QLineEdit *>(QStringLiteral("emailedit")); QToolButton *toolButton = widget.findChild<QToolButton *>(QStringLiteral("editbutton")); QVERIFY(lineedit->isReadOnly()); QVERIFY(!toolButton->isEnabled()); }