Is there a way for a QToolButton to display its associated QMenu on top of it instead of below?
I have seen this answer which pleased me but it's in Python and I don't really know how to port it properly.
I also took a look at the source code for QMenu but it's quite overwhelming so I don't really know how to tackle this issue.
There also is a little arrow on the button showing that it'll pop down.
This is the very bottom of my window so I'd like it to pop up in case it becomes too big to fit.
You could do it using an event filter:
QMenu* yourMenu;
yourButton->setMenu(yourMenu);
yourMenu->installEventFilter(this);
bool yourClass::eventFilter(QObject * obj, QEvent *event)
{
if (event->type() == QEvent::Show && obj == yourButton->menu())
{
QPoint pos = /*the position expected*/;
yourButton->menu()->move(pos);
return true;
}
return false;
}
To remove the little arrow, add this to your stylesheet:
QToolButton::menu-indicator{
image: none;
}