View Full Version : Qt Toolbutton with button stack

12th June 2012, 13:59

Here is what I am trying to do:

I need a toolbar, with toolbuttons, some of these tool buttons are button stacks. i.e the button icon appears along with a right arrow, right clicking on this button whould open a grid layout of buttons. I looked at the QToolButton function setMenu, this opens up a popup menu alright, but it does not show me this arrow symbol that I am looking for alongside the icon to indicate to the user that this is a special tool button stack. Here is the code snippet I used:

fileToolBar = addToolBar(tr("File"));

tb2 = new QToolButton(fileToolBar);
QMenu test(tb2);

openAct = new QAction(QIcon(":/images/open.png"), tr("&Open..."), this);


tb2->setIcon(QPixmap( ":/images/open.png"));

In the above case I dont see the button icon on the toolbutton, instead I see only the down arrow symbol, clicking which opens up the popup menu. If the skip the setArrowType line, I can see only the icon and not the arrow. How can I achieve both the icon as well as the arrow on a toolbutton? I can manually draw this arrow within the paint Event of the button, but this is not called on the toolbar resize when the extension widgets appear (when we shrink the toolbar so that the toolbutton stack is not visible), so its of no use.

Any help here would be greatly appreciated.

Thanks in advance,

12th June 2012, 14:35
Objects created on the stack (like your "test") go out of scope when the block they are declared in ends.