PDA

View Full Version : QMenuBar's setCornerWidget() on the left overlaps the widget with the menus



ComServant
6th January 2015, 06:21
I have a QWidget that I'm wanting to fix to the left of the QMainWindow's QMenuBar.

My code looks like this:


this->leftCornerMenuWidget = new LeftCornerMenuWidget();
this->ui->menubar->setCornerWidget(this->leftCornerMenuWidget, Qt::TopLeftCorner);
this->rightCornerMenuWidget = new RightCornerMenuWidget();
this->ui->menubar->setCornerWidget(this->rightCornerMenuWidget, Qt::TopRightCorner);

Both corner widgets display fine, but the one on the left overlaps with the menu items. How can I fix that?

My widget is a QtDesigner 'QWidget' of fixed size and height with a single QPushButton of fixed size and height, styled with stylesheets. The button displays and reacts fine.

Here's a screenshot:
10870

I'm on Win8.1 and using Qt 5.4.0 for MinGW x64

Added after 7 minutes:

Oops, I didn't see that QtCreator was outputting an error message:

setGeometryDp: Unable to set geometry 60x20+810+495 on QWidgetWindow/'LeftCornerMenuWidgetWindow'. Resulting geometry: 124x20+810+495 (frame: 8, 31, 8, 8, custom margin: 0, 0, 0, 0, minimum size: 60x20, maximum size: 60x20).

The problem was that my "QWidget" that contained the "QPushButton" was a fixed size, and the QMenuBar was trying to resize it and failed. By making it have a non-fixed size, giving it a layout, but leaving my QPushButton a fixed size, everything ends up working fine.

Added after 4 minutes:

Ugh, but even though my QPushButton (with a fixed width) displays fine, and receives hover events fine, but doesn't receive mouse clicks (except for one pixel's worth of width).
Except... this is weird... My right corner widget is a QWidget that has, among other things, a QTabBar. My left cornerwidget's QPushButton receives all hover events fine, but only properly receives mouse clicks when the QTabBar in the right corner-widget is set to a tab other than the first one. If I switch to a different tab and then switch back to the first one, it can no longer receive mouse clicks again.

Now I'm really confused. In terms of behavior, that sounds like a bad pointer... but I don't see how or where. I don't think it's a pointer issue.

Any ideas about what's wrong?

ComServant
7th January 2015, 05:19
If I swap the left and right widgets, it's still my QPushButton that fails to receive mousepresses (unless the tabbar's tab isn't index 0!), even if it's on the right. If I remove the QTabBar from the menu, the pushbutton still doesn't receive the mouseclicks.

It's really weird. So I removed the QMenuBar, created my own toolbar widget (since I was removing the menus anyway, replacing them with tabs and other such stuff). The QPushButton still failed to click except on certain tabs. So I added a second plain generic QPushButton to the new toolbar, nothing touches its pointers. It doesn't work either.

So I transform my original QPushButton into a QToolButton and it works fine. :confused:

For some reason, my promoted QTabBar seems to be interfering with any nearby QPushButtons, though I don't have a clue why. Anyway, since my button works fine as a QToolButton, my immediate problem is solved. I'm curious as to what is causing the QTabBar issue though.