本文整理汇总了C++中QToolBar::widgetForAction方法的典型用法代码示例。如果您正苦于以下问题:C++ QToolBar::widgetForAction方法的具体用法?C++ QToolBar::widgetForAction怎么用?C++ QToolBar::widgetForAction使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QToolBar
的用法示例。
在下文中一共展示了QToolBar::widgetForAction方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: QToolBar
void tst_QToolBar::task197996_visibility()
{
QMainWindow mw;
QToolBar *toolBar = new QToolBar(&mw);
mw.addToolBar(toolBar);
toolBar->addAction(new QAction("Foo", &mw));
QAction *pAction = new QAction("Test", &mw);
toolBar->addAction(pAction);
pAction->setVisible(false);
toolBar->setVisible(false);
toolBar->setVisible(true);
pAction->setVisible(true);
mw.show();
QVERIFY(toolBar->widgetForAction(pAction)->isVisible());
toolBar->setVisible(false);
pAction->setVisible(false);
toolBar->setVisible(true);
pAction->setVisible(true);
QTest::qWait(100);
QVERIFY(toolBar->widgetForAction(pAction)->isVisible());
}
示例2: testAddEntry
void TestGui::testAddEntry()
{
EntryView* entryView = m_dbWidget->findChild<EntryView*>("entryView");
QAction* entryNewAction = m_mainWindow->findChild<QAction*>("actionEntryNew");
QVERIFY(entryNewAction->isEnabled());
QToolBar* toolBar = m_mainWindow->findChild<QToolBar*>("toolBar");
QWidget* entryNewWidget = toolBar->widgetForAction(entryNewAction);
QVERIFY(entryNewWidget->isVisible());
QVERIFY(entryNewWidget->isEnabled());
QTest::mouseClick(entryNewWidget, Qt::LeftButton);
QCOMPARE(m_dbWidget->currentMode(), DatabaseWidget::EditMode);
EditEntryWidget* editEntryWidget = m_dbWidget->findChild<EditEntryWidget*>("editEntryWidget");
QLineEdit* titleEdit = editEntryWidget->findChild<QLineEdit*>("titleEdit");
QTest::keyClicks(titleEdit, "test");
QDialogButtonBox* editEntryWidgetButtonBox = editEntryWidget->findChild<QDialogButtonBox*>("buttonBox");
QTest::mouseClick(editEntryWidgetButtonBox->button(QDialogButtonBox::Ok), Qt::LeftButton);
QCOMPARE(m_dbWidget->currentMode(), DatabaseWidget::ViewMode);
QModelIndex item = entryView->model()->index(1, 1);
Entry* entry = entryView->entryFromIndex(item);
QCOMPARE(entry->title(), QString("test"));
QCOMPARE(entry->historyItems().size(), 0);
// wait for modified timer
QTRY_COMPARE(m_tabWidget->tabText(m_tabWidget->currentIndex()), QString("%1*").arg(m_orgDbFileName));
QAction* entryEditAction = m_mainWindow->findChild<QAction*>("actionEntryEdit");
QVERIFY(entryEditAction->isEnabled());
QWidget* entryEditWidget = toolBar->widgetForAction(entryEditAction);
QVERIFY(entryEditWidget->isVisible());
QVERIFY(entryEditWidget->isEnabled());
QTest::mouseClick(entryEditWidget, Qt::LeftButton);
QCOMPARE(m_dbWidget->currentMode(), DatabaseWidget::EditMode);
QTest::keyClicks(titleEdit, "something");
QTest::mouseClick(editEntryWidgetButtonBox->button(QDialogButtonBox::Ok), Qt::LeftButton);
QCOMPARE(entry->title(), QString("testsomething"));
QCOMPARE(entry->historyItems().size(), 1);
QTest::mouseClick(entryNewWidget, Qt::LeftButton);
QTest::keyClicks(titleEdit, "something 2");
QTest::mouseClick(editEntryWidgetButtonBox->button(QDialogButtonBox::Ok), Qt::LeftButton);
QTest::mouseClick(entryNewWidget, Qt::LeftButton);
QTest::keyClicks(titleEdit, "something 3");
QTest::mouseClick(editEntryWidgetButtonBox->button(QDialogButtonBox::Ok), Qt::LeftButton);
QTRY_COMPARE(entryView->model()->rowCount(), 4);
}
示例3: testSearch
void TestGui::testSearch()
{
QAction* searchAction = m_mainWindow->findChild<QAction*>("actionSearch");
QVERIFY(searchAction->isEnabled());
QToolBar* toolBar = m_mainWindow->findChild<QToolBar*>("toolBar");
QWidget* searchActionWidget = toolBar->widgetForAction(searchAction);
QVERIFY(searchActionWidget->isVisible());
QVERIFY(searchActionWidget->isEnabled());
QTest::mouseClick(searchActionWidget, Qt::LeftButton);
EntryView* entryView = m_dbWidget->findChild<EntryView*>("entryView");
QLineEdit* searchEdit = m_dbWidget->findChild<QLineEdit*>("searchEdit");
QToolButton* clearSearch = m_dbWidget->findChild<QToolButton*>("clearButton");
QTest::keyClicks(searchEdit, "ZZZ");
QTRY_COMPARE(entryView->model()->rowCount(), 0);
QTest::mouseClick(clearSearch, Qt::LeftButton);
QTest::keyClicks(searchEdit, "some");
QTRY_COMPARE(entryView->model()->rowCount(), 2);
QModelIndex item = entryView->model()->index(0, 1);
QRect itemRect = entryView->visualRect(item);
QTest::mouseClick(entryView->viewport(), Qt::LeftButton, Qt::NoModifier, itemRect.center());
QAction* entryEditAction = m_mainWindow->findChild<QAction*>("actionEntryEdit");
QVERIFY(entryEditAction->isEnabled());
QWidget* entryEditWidget = toolBar->widgetForAction(entryEditAction);
QVERIFY(entryEditWidget->isVisible());
QVERIFY(entryEditWidget->isEnabled());
QTest::mouseClick(entryEditWidget, Qt::LeftButton);
QCOMPARE(m_dbWidget->currentMode(), DatabaseWidget::EditMode);
EditEntryWidget* editEntryWidget = m_dbWidget->findChild<EditEntryWidget*>("editEntryWidget");
QDialogButtonBox* editEntryWidgetButtonBox = editEntryWidget->findChild<QDialogButtonBox*>("buttonBox");
QTest::mouseClick(editEntryWidgetButtonBox->button(QDialogButtonBox::Ok), Qt::LeftButton);
QCOMPARE(m_dbWidget->currentMode(), DatabaseWidget::ViewMode);
QModelIndex item2 = entryView->model()->index(1, 0);
QRect itemRect2 = entryView->visualRect(item2);
QTest::mouseClick(entryView->viewport(), Qt::LeftButton, Qt::NoModifier, itemRect2.center());
QAction* entryDeleteAction = m_mainWindow->findChild<QAction*>("actionEntryDelete");
QWidget* entryDeleteWidget = toolBar->widgetForAction(entryDeleteAction);
QVERIFY(entryDeleteWidget->isVisible());
QVERIFY(entryDeleteWidget->isEnabled());
QTest::mouseClick(entryDeleteWidget, Qt::LeftButton);
QWidget* closeSearchButton = m_dbWidget->findChild<QToolButton*>("closeSearchButton");
QTest::mouseClick(closeSearchButton, Qt::LeftButton);
QCOMPARE(entryView->model()->rowCount(), 1);
}
示例4: testRequestWidgetMenuModeWidgetParentSeveralActions
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"));
}
示例5: testRequestWidgetMenuModeWidgetParentRemoveActions
void KSelectAction_UnitTest::testRequestWidgetMenuModeWidgetParentRemoveActions()
{
KSelectAction selectAction("selectAction", 0);
selectAction.setToolBarMode(KSelectAction::MenuMode);
QToolBar toolBar;
toolBar.addAction(&selectAction);
QWidget* widget = toolBar.widgetForAction(&selectAction);
QVERIFY(widget);
QAction* action1 = new QAction("action1", &selectAction);
selectAction.addAction(action1);
QAction* action2 = new QAction("action2", &selectAction);
selectAction.addAction(action2);
QAction* action3 = new QAction("action3", &selectAction);
selectAction.addAction(action3);
delete selectAction.removeAction(action1);
delete selectAction.removeAction(action2);
delete selectAction.removeAction(action3);
QVERIFY(!widget->isEnabled());
QCOMPARE(widget->actions().count(), 1);
QCOMPARE(widget->actions().at(0)->text(), QString("selectAction"));
}
示例6:
QWidget * QToolBarProto::widgetForAction ( QAction * action ) const
{
QToolBar *item = qscriptvalue_cast<QToolBar*>(thisObject());
if (item)
return item->widgetForAction(action);
return 0;
}
示例7: testRequestWidgetComboBoxModeWidgetParent
void KSelectAction_UnitTest::testRequestWidgetComboBoxModeWidgetParent()
{
KSelectAction selectAction("selectAction", 0);
selectAction.setToolBarMode(KSelectAction::ComboBoxMode);
QToolBar toolBar;
toolBar.addAction(&selectAction);
QWidget* widget = toolBar.widgetForAction(&selectAction);
QVERIFY(widget);
KComboBox* comboBox = qobject_cast<KComboBox*>(widget);
QVERIFY(comboBox);
QVERIFY(!comboBox->isEnabled());
}
示例8: widgetAction
void tst_QToolBar::widgetAction()
{
// ensure that a QWidgetAction without widget behaves like a normal action
QToolBar tb;
QWidgetAction *a = new QWidgetAction(0);
a->setIconText("Blah");
tb.addAction(a);
QWidget *w = tb.widgetForAction(a);
QVERIFY(w);
QToolButton *button = qobject_cast<QToolButton *>(w);
QVERIFY(button);
QCOMPARE(a->iconText(), button->text());
delete a;
}
示例9: activeContextStateChanged
void KviIrcContextDisplayAction::activeContextStateChanged()
{
if(m_pActionList)
{
for(QAction * a = m_pActionList->first();a;a = m_pActionList->next())
{
QToolBar *t = (QToolBar*) a->parentWidget();
if(t)
{
KviIrcContextDisplay * w = (KviIrcContextDisplay *) t->widgetForAction(a);
if(w)
w->update();
}
}
}
}
示例10: QVERIFY
void tst_QToolBar::task191727_layout()
{
QMainWindow mw;
QToolBar *toolBar = mw.addToolBar("test");
toolBar->addAction("one");
QAction *action = toolBar->addAction("two");
QLineEdit *lineedit = new QLineEdit;
lineedit->setMaximumWidth(50);
toolBar->addWidget(lineedit);
mw.resize(400, 400);
mw.show();
QWidget *actionwidget = toolBar->widgetForAction(action);
QVERIFY(qAbs(lineedit->pos().x() - (actionwidget->geometry().right() + 1 + toolBar->layout()->spacing())) < 2);
}
示例11: createToolBar
void lmcChatRoomWindow::createToolBar(void) {
QToolBar* pLeftBar = new QToolBar(ui.wgtToolBar);
pLeftBar->setStyleSheet("QToolBar { border: 0px }");
pLeftBar->setIconSize(QSize(16, 16));
ui.toolBarLayout->addWidget(pLeftBar);
pFontAction = pLeftBar->addAction(QIcon(QPixmap(IDR_FONT, "PNG")), "Change Font...",
this, SLOT(btnFont_clicked()));
pFontColorAction = pLeftBar->addAction(QIcon(QPixmap(IDR_FONTCOLOR, "PNG")), "Change Color...",
this, SLOT(btnFontColor_clicked()));
pLeftBar->addSeparator();
pbtnSmiley = new lmcToolButton(pLeftBar);
pbtnSmiley->setIcon(QIcon(QPixmap(IDR_SMILEY, "PNG")));
pbtnSmiley->setPopupMode(QToolButton::InstantPopup);
pbtnSmiley->setMenu(pSmileyMenu);
pLeftBar->addWidget(pbtnSmiley);
pLeftBar->addSeparator();
pSaveAction = pLeftBar->addAction(QIcon(QPixmap(IDR_SAVE, "PNG")), "&Save As...", this, SLOT(btnSave_clicked()));
pSaveAction->setShortcut(QKeySequence::Save);
pSaveAction->setEnabled(false);
ui.lblDividerTop->setBackgroundRole(QPalette::Light);
ui.lblDividerTop->setAutoFillBackground(true);
ui.lblDividerBottom->setBackgroundRole(QPalette::Dark);
ui.lblDividerBottom->setAutoFillBackground(true);
if(groupMode) {
QToolBar* pContactsBar = new QToolBar(ui.wgtContactsBar);
pContactsBar->setStyleSheet("QToolBar { border: 0px }");
pContactsBar->setIconSize(QSize(24, 24));
ui.contactsBarLayout->addWidget(pContactsBar);
addContactAction = pContactsBar->addAction(QIcon(QPixmap(IDR_ADDCONTACT, "PNG")), "&Add Contacts...",
this, SLOT(addContactAction_triggered()));
QToolButton* pButton = (QToolButton*)pContactsBar->widgetForAction(addContactAction);
pButton->setAutoRaise(false);
}
}
示例12: testSetToolTipBeforeRequestingToolButtonWidget
void KSelectAction_UnitTest::testSetToolTipBeforeRequestingToolButtonWidget()
{
KSelectAction selectAction("selectAction", 0);
selectAction.setToolBarMode(KSelectAction::MenuMode);
selectAction.setToolTip("Test");
QToolBar toolBar;
//Don't use requestWidget, as it needs a releaseWidget when used in MenuMode
//(in ComboBoxMode the widget is released automatically when it is
//destroyed). When the action is added to the QToolBar, it requests and
//releases the widget as needed.
toolBar.addAction(&selectAction);
QWidget* widget = toolBar.widgetForAction(&selectAction);
QVERIFY(widget);
QToolButton* toolButton = qobject_cast<QToolButton*>(widget);
QVERIFY(toolButton);
QCOMPARE(toolButton->toolTip(), QString("Test"));
}
示例13: load
void ToolbarEditor::load(QWidget *w, QStringList l, QList<QAction *> actions_list)
{
qDebug("ToolbarEditor::load: '%s'", w->objectName().toUtf8().data());
QAction *action;
for (int n = 0; n < l.count(); n++) {
qDebug("ToolbarEditor::load: loading action %s", l[n].toUtf8().data());
if (l[n] == "separator") {
qDebug("ToolbarEditor::load: adding separator");
QAction *sep = new QAction(w);
sep->setSeparator(true);
w->addAction(sep);
} else {
action = findAction(l[n], actions_list);
if (action) {
w->addAction(action);
if (action->objectName().endsWith("_menu")) {
// If the action is a menu and is in a toolbar, as a toolbutton, change some of its properties
QToolBar *toolbar = qobject_cast<QToolBar *>(w);
if (toolbar) {
QToolButton *button = qobject_cast<QToolButton *>(toolbar->widgetForAction(action));
if (button) {
//qDebug("ToolbarEditor::load: action %s is a toolbutton", action->objectName().toUtf8().constData());
button->setPopupMode(QToolButton::InstantPopup);
//button->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
}
}
}
} else {
qWarning("ToolbarEditor::load: action %s not found", l[n].toUtf8().data());
}
}
}
}
示例14: testRequestWidgetMenuModeWidgetParentAddActions
void KSelectAction_UnitTest::testRequestWidgetMenuModeWidgetParentAddActions()
{
KSelectAction selectAction("selectAction", 0);
selectAction.setToolBarMode(KSelectAction::MenuMode);
QToolBar toolBar;
toolBar.addAction(&selectAction);
QWidget* widget = toolBar.widgetForAction(&selectAction);
QVERIFY(widget);
QVERIFY(!widget->isEnabled());
selectAction.addAction(new QAction("action1", &selectAction));
selectAction.addAction(new QAction("action2", &selectAction));
selectAction.addAction(new QAction("action3", &selectAction));
QVERIFY(widget->isEnabled());
QCOMPARE(widget->actions().count(), 4);
QCOMPARE(widget->actions().at(0)->text(), QString("selectAction"));
QCOMPARE(widget->actions().at(1)->text(), QString("action1"));
QCOMPARE(widget->actions().at(2)->text(), QString("action2"));
QCOMPARE(widget->actions().at(3)->text(), QString("action3"));
}
示例15: testEditEntry
void TestGui::testEditEntry()
{
EntryView* entryView = m_dbWidget->findChild<EntryView*>("entryView");
QModelIndex item = entryView->model()->index(0, 1);
QRect itemRect = entryView->visualRect(item);
QTest::mouseClick(entryView->viewport(), Qt::LeftButton, Qt::NoModifier, itemRect.center());
QAction* entryEditAction = m_mainWindow->findChild<QAction*>("actionEntryEdit");
QVERIFY(entryEditAction->isEnabled());
QToolBar* toolBar = m_mainWindow->findChild<QToolBar*>("toolBar");
QWidget* entryEditWidget = toolBar->widgetForAction(entryEditAction);
QVERIFY(entryEditWidget->isVisible());
QVERIFY(entryEditWidget->isEnabled());
QTest::mouseClick(entryEditWidget, Qt::LeftButton);
EditEntryWidget* editEntryWidget = m_dbWidget->findChild<EditEntryWidget*>("editEntryWidget");
QVERIFY(m_dbWidget->currentWidget() == editEntryWidget);
QDialogButtonBox* editEntryWidgetButtonBox = editEntryWidget->findChild<QDialogButtonBox*>("buttonBox");
QVERIFY(editEntryWidgetButtonBox);
QTest::mouseClick(editEntryWidgetButtonBox->button(QDialogButtonBox::Ok), Qt::LeftButton);
// make sure the database isn't marked as modified
// wait for modified timer
QTRY_COMPARE(m_tabWidget->tabText(m_tabWidget->currentIndex()), m_orgDbFileName);
}