Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Clicking on QMacToolBar does not close open QMenus
QtWS25 Last Chance

Clicking on QMacToolBar does not close open QMenus

Scheduled Pinned Locked Moved Unsolved General and Desktop
qmactoolbarqmenuqmacnativewidgeqactionqmainwindow
7 Posts 3 Posters 968 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    SajasKK
    wrote on 5 May 2020, 15:40 last edited by SajasKK 5 May 2020, 17:39
    #1

    I have a MainWindow that has a ToolBar(QMacToolBar) and a central widget with a QStackedLayout. Based on the Tool selected in ToolBar the corresponding widget in QStackedLayout should be shown.
    Some of the widgets in the Stacked Layout can open a QMenu(which opens up as a popup). If I click any where in the window(except on any of the ToolItem) the popup closes correctly.

    How can I make the popup close even when I click on the ToolItems?
    In example below there is only two tabs, but in my application there can be multiple tabs which may or may not have a menu popup.
    FirstTab.png
    SecondTab.png
    Switching to First.png

    Code that has been reduced to relevant parts:

    #include <QMacToolBar>
    #include <QMacToolBarItem>
    #include <QStackedLayout>
    #include <QtWidgets>
    
    class MyWidget : public QWidget
    {
    public:
        MyWidget( QWidget * inParent ) : QWidget( inParent )
        {
            mStackLayout = new QStackedLayout();
    
            // first Stack Entry
            auto firstWidget = new QWidget( this );
            firstWidget->setFixedSize( QSize{ 200, 100 } );
            firstWidget->setStyleSheet( "background-color:cyan" );
    
            // second Stack Entry
            auto secondWidget = new QPushButton( "Actions", this );
            auto menu = new QMenu( secondWidget );
            menu->addAction( "Action1" );
            menu->addAction( "Action2" );
            secondWidget->setMenu( menu );
    
            mStackLayout->addWidget( firstWidget );
            mStackLayout->addWidget( secondWidget );
        }
    
        void SwitchToTab( int index )
        {
            mStackLayout->setCurrentIndex( index );
        }
    
    private:
        QStackedLayout * mStackLayout;
    };
    
    MainWindow::MainWindow(QWidget *parent)
        : QMainWindow(parent)
    {
        auto toolBar = new QMacToolBar( this );
        auto centralWidget = new MyWidget(this);
        setCentralWidget( centralWidget );
    
        auto firstItem = toolBar->addItem( QIcon( QPixmap( "/Users/Stack1.png" ) ), "Stack1" );
        firstItem->setSelectable( true );
        connect
        (
            firstItem,
            &QMacToolBarItem::activated,
            [  centralWidget ]
            {
                centralWidget->SwitchToTab( 0 );
            }
        );
    
        auto secondItem = toolBar->addItem( QIcon( QPixmap( "/Users/Stack2.png" ) ), "Stack2" );
        secondItem->setSelectable( true );
        connect
        (
            secondItem,
            &QMacToolBarItem::activated,
            [  centralWidget ]
            {
                centralWidget->SwitchToTab( 1 );
            }
        );
    
        window()->winId();
        toolBar->attachToWindow( window()->windowHandle() );
    }
    

    Qt 5.14
    MacOs Mojave 10.14.6

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 5 May 2020, 16:28 last edited by
      #2

      Hi,

      What version of Qt ?
      What version of macOS ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      S 1 Reply Last reply 5 May 2020, 17:38
      0
      • S SGaist
        5 May 2020, 16:28

        Hi,

        What version of Qt ?
        What version of macOS ?

        S Offline
        S Offline
        SajasKK
        wrote on 5 May 2020, 17:38 last edited by
        #3

        @SGaist
        Qt 5.14
        MacOs Mojave 10.14.6

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 5 May 2020, 21:51 last edited by
          #4

          I can reproduce the same issue on High Sierra, you should go to the bug report system and see if there's something related.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          S 1 Reply Last reply 6 May 2020, 07:08
          1
          • S SGaist
            5 May 2020, 21:51

            I can reproduce the same issue on High Sierra, you should go to the bug report system and see if there's something related.

            S Offline
            S Offline
            SajasKK
            wrote on 6 May 2020, 07:08 last edited by
            #5

            @SGaist Thank you.
            I couldn't find any similar issue reported on QMacToolbar usage.
            So, I have raised on in the board: QTBUG-84022

            1 Reply Last reply
            1
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 6 May 2020, 07:15 last edited by
              #6

              Thanks, just one thing, your code as is cannot be compiled. It would be nice to fix it and add a main function so that that the developer taking a look at it can easily compile it.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              1
              • M Offline
                M Offline
                mpergand
                wrote on 6 May 2020, 11:29 last edited by mpergand 5 Jun 2020, 11:30
                #7

                Old lasting bug ...

                alt text

                alt text

                Funny things happen in full screen ...
                In this screenshots you can see an another bug : the checkmark ✓ doesn't follow the font size of the menu.

                alt text

                1 Reply Last reply
                0

                2/7

                5 May 2020, 16:28

                topic:navigator.unread, 5
                • Login

                • Login or register to search.
                2 out of 7
                • First post
                  2/7
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved