YmFzZTY0
YmFzZTY0

Reputation: 109

How can I make a QMenuBar item appear over its QMenu

First of all, I'm fairly new with Qt and Qt Creator so go easy if this is a stupid question.

I was practicing using Qt Creator, playing around with css styles. In particular, I'm trying to get the menubar and its menus to look something like this (on Windows): https://i.sstatic.net/9lMnQ.png.

However, the closest I've been able to get so far is this: https://i.sstatic.net/5Nlen.png.

I've searched online to see if anyone has tried something like this but I wasn't able to find anything.

The only possible solution I can think of is if the menubar item (with no bottom border) could be rendered in above the menu, so that they overlap, covering its top border over the width that they overlap.

If that won't work or is impossible or whatever please do suggest any other solutions/workarounds/hacks.

Thanks in advance!

Upvotes: 0

Views: 650

Answers (1)

Ezee
Ezee

Reputation: 4344

I think that the only good solution is to avoid any tricks and create a new widget:

  • Create a new class inherited from QWidget with Qt::Popup attribute.
  • Place a QMenu into a layout of the widget.
  • Get a position of QMenuBar item which is clicked using QMenuBar::getActionGeometry.
  • Calculate position of the widget and of the tab in the widget to be placed over the menubar item.
  • Customize form of the widget using QWidget::setMask to make it look like a rectangle with a tab.
  • Show your widget instead of QMenu.

Upvotes: 0

Related Questions