Due to some reasons I need to implement specific menu in QToolBar. My target is to save the default design of a button with drop-down menu (icon + triangle), but I want to show my own QDialog (it looks like a tree) when I press this triangle.
So, now I have something like this:
class CustomMenu : public QMenu
{
Q_OBJECT;
public:
CustomMenu(QWidget *parent);
signals:
void showMyMenu();
};
This is how I create this menu and connects it with needed slots:
CustomMenu *menu = new CustomMenu(tb);
connect(menu, SIGNAL(aboutToShow()), menu, SIGNAL(showMyMenu()));
connect(menu, SIGNAL(showMyMenu()), this, SLOT(execMyMenu()));
tbButton->setMenu(menu);
tb->addAction(tbButton);
Here's the slot:
void MyProjectClass::execMyMenu()
{
CustomMenu *cm = (CustomMenu*)sender();
CustomMenuWidget* myMenu = new CustomMenuWidget();
myMenu->exec();
cm->hide();
delete myMenu;
}
The problem here is that calling hide()
for CustomMenu
doesn't make triangle become unpressed and it still holds a focus on the button. That makes impossible to click something else until you don't get rid of the focus from that button.
Everything I want is to substitute default drop-down menu with my custom one.
It seems to be very easy, but I probably missed something. What am I doing wrong?
I'm using Qt 4.8.6