PDA

View Full Version : A Photoshop-like Toolbar



avis_phoenix
2nd August 2013, 02:51
I've tried using QMenu, to generate a list of options like in photoshop toolbar, but I failed to assign the action is selected as visible action in the toolbar or properly mark the last action selected.

If you do not understand what I mean I want to do what you see in this video between 2:05 and 2:20 minutes:

https://www.youtube.com/watch?v=W0nzWANu9UE

Hopefully somebody can help me.

Thanks

ChrisW67
2nd August 2013, 05:46
// Can check the menu items
QAction *actionA = new QAction("AAA", this);
actionA->setCheckable(true);
QAction *actionB = new QAction("BBB", this);
actionB->setCheckable(true);
QAction *actionC = new QAction("CCC", this);
actionC->setCheckable(true);
// only one at a time
QActionGroup *group = new QActionGroup(this);
group->setExclusive(true);
group->addAction(actionA);
group->addAction(actionB);
group->addAction(actionC);
// build a menu of them
QMenu *menu = new QMenu(this);
menu->addAction(actionA);
menu->addAction(actionB);
menu->addAction(actionC);
// and a tool button to put the menu on
QToolButton *button = new QToolButton(this);
button->setDefaultAction(actionA);
button->setMenu(menu);
connect(menu, SIGNAL(triggered(QAction*)), button, SLOT(setDefaultAction(QAction*))); // << magic sauce
// put it on the tool bar
QToolBar *toolBar = new QToolBar(this);
toolBar->addWidget(button);
addToolBar(Qt::TopToolBarArea, toolBar);

avis_phoenix
2nd August 2013, 15:01
Thank you so much for your help!!

I add this:


button->setPopupMode(QToolButton::MenuButtonPopup);

In order to add a indepedent arrow button, to show the menu.

Again Thanks you so much