Results 1 to 2 of 2

Thread: QMenuBar's setCornerWidget() on the left overlaps the widget with the menus

  1. #1
    Join Date
    Apr 2009
    Location
    www.JaminGrey.com
    Posts
    71
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QMenuBar's setCornerWidget() on the left overlaps the widget with the menus

    I have a QWidget that I'm wanting to fix to the left of the QMainWindow's QMenuBar.

    My code looks like this:
    Qt Code:
    1. this->leftCornerMenuWidget = new LeftCornerMenuWidget();
    2. this->ui->menubar->setCornerWidget(this->leftCornerMenuWidget, Qt::TopLeftCorner);
    3. this->rightCornerMenuWidget = new RightCornerMenuWidget();
    4. this->ui->menubar->setCornerWidget(this->rightCornerMenuWidget, Qt::TopRightCorner);
    To copy to clipboard, switch view to plain text mode 

    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:
    Menu overlap.png

    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?
    Last edited by ComServant; 6th January 2015 at 05:32.

  2. #2
    Join Date
    Apr 2009
    Location
    www.JaminGrey.com
    Posts
    71
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QMenuBar's setCornerWidget() on the left overlaps the widget with the menus

    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.

    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.

Similar Threads

  1. Replies: 10
    Last Post: 9th September 2013, 15:29
  2. how to add widget to QMenubar
    By Prashant Moglaikar in forum Qt Programming
    Replies: 1
    Last Post: 4th May 2011, 11:04
  3. QMenubar in a non mainwindow widget
    By Tito in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 16th August 2010, 15:24
  4. Replies: 10
    Last Post: 29th May 2010, 18:42
  5. Getting QMenuBar of child widget to showup
    By discostu in forum Newbie
    Replies: 7
    Last Post: 6th July 2007, 18:56

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.