A
A
Alexander2011-11-29 11:27:25
Qt
Alexander, 2011-11-29 11:27:25

QAction::setMenu()?

Good afternoon, colleagues!
As you guessed, the question is about Qt.
The problem is this: the QMenu associated with the QAction (QAction::setMenu) displayed in the toolbar does not appear immediately when the mouse is clicked, but after a delay, i.e. you need to press and hold the button for a couple of seconds, then it will appear. Nobody faced? Googling didn't help.
Qt4.7.4, WinXP, Win7
UPD (resolved):

// Создаем меню
    QMenu * menu = new QMenu(this);
    menu->addAction("Act1");
    menu->addAction("Act2");
    menu->addAction("Act3");
    menu->addAction("Act4");
    menu->addAction("Act5");
//привязываем к действию, предварительно прикрепленному к ToolBar'у
    ui->actionTest->setMenu(menu);
// теперь вытаскиваем из тулбара виджет, соответствующий действию
    if(QToolButton * btn = qobject_cast<QToolButton *>(ui->mainToolBar->widgetForAction(ui->actionTest)))
//выставляем нужный popup-режим
        btn->setPopupMode(QToolButton::InstantPopup);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Sidorov, 2011-11-29
@ncix

There is some bug in the design of QToolBar, as a result of which it is impossible to change the role that is set to a QToolButton that occurs when an action is added to the panel.
doc.qt.nokia.com/latest/qtoolbutton.html#ToolButtonPopupMode-enum
You can influence it either by first adding the menu to the action and then adding it to the panel or vice versa.
Well, perhaps you can pull out the pointer to the QToolButton generated as a result of addAction.
But in general, this is a design flaw in QToolBar.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question