void GLSLTextEditorWidget::createToolBar(GLSLEditorEditable *editable) { m_outlineCombo = new QComboBox; m_outlineCombo->setMinimumContentsLength(22); // ### m_outlineCombo->setModel(m_outlineModel); QTreeView *treeView = new QTreeView; treeView->header()->hide(); treeView->setItemsExpandable(false); treeView->setRootIsDecorated(false); m_outlineCombo->setView(treeView); treeView->expandAll(); //m_outlineCombo->setSizeAdjustPolicy(QComboBox::AdjustToContents); // Make the combo box prefer to expand QSizePolicy policy = m_outlineCombo->sizePolicy(); policy.setHorizontalPolicy(QSizePolicy::Expanding); m_outlineCombo->setSizePolicy(policy); QToolBar *toolBar = static_cast<QToolBar*>(editable->toolBar()); QList<QAction*> actions = toolBar->actions(); toolBar->insertWidget(actions.first(), m_outlineCombo); }
QAction * QToolBarProto::insertWidget ( QAction * before, QWidget * widget ) { QToolBar *item = qscriptvalue_cast<QToolBar*>(thisObject()); if (item) return item->insertWidget(before, widget); return 0; }
void tst_QToolBar::insertWidget() { QToolBar tb; QWidget w(&tb); QAction action1(0); QAction action2(0); tb.addAction(&action1); tb.addAction(&action2); QAction *widget = tb.insertWidget(&action2, &w); QCOMPARE(tb.actions().count(), 3); QCOMPARE(tb.actions()[0], &action1); QCOMPARE(tb.actions()[1], widget); QCOMPARE(tb.actions()[2], &action2); // it should be possible to reuse the action returned by // addWidget() to place the widget somewhere else in the toolbar tb.removeAction(widget); QCOMPARE(tb.actions().count(), 2); QCOMPARE(tb.actions()[0], &action1); QCOMPARE(tb.actions()[1], &action2); tb.insertAction(&action1, widget); QCOMPARE(tb.actions().count(), 3); QCOMPARE(tb.actions()[0], widget); QCOMPARE(tb.actions()[1], &action1); QCOMPARE(tb.actions()[2], &action2); tb.clear(); QCOMPARE(tb.actions().count(), 0); { QToolBar tb; QPointer<QWidget> widget = new QWidget; QAction *action = tb.addWidget(widget); QVERIFY(action->parent() == &tb); QToolBar tb2; tb.removeAction(action); tb2.addAction(action); QVERIFY(widget && widget->parent() == &tb2); QVERIFY(action->parent() == &tb2); } }