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. QMenu with tearoff enabled and with QWidgetAction
Forum Updated to NodeBB v4.3 + New Features

QMenu with tearoff enabled and with QWidgetAction

Scheduled Pinned Locked Moved General and Desktop
qmenu
3 Posts 2 Posters 2.5k Views 2 Watching
  • 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.
  • T Offline
    T Offline
    TheKodz
    wrote on last edited by TheKodz
    #1

    Implemented QMenu with QWidgetAction as one of the menu item along with many QAction's in it. Also enabled the tear off (setTearOffEnabled(true) ).

    On executing the app and doing tearoff of menu, this QWidgetAction (which is a QLabel) is blank. Is this a bug in QT? If yes, is there any alternative to make the QWidgetAction visible?

    Thanks.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      What version of Qt are you using ? On which OS ?

      Can you share the code where you setup that menu ?

      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
      0
      • T Offline
        T Offline
        TheKodz
        wrote on last edited by
        #3

        Thanks SGaist for replay.
        I took the example itself from Qt : examples\activeqt\menus\main.cpp, menus.cpp

        I updated menus.cpp and added following code:

        QMenus::QMenus(QWidget *parent) 
            : QMainWindow(parent, 0) 
        {
            QAction *action;
        
            QMenu *file = new QMenu(this);
            file->setTearOffEnabled(true);  //<= MY CHANGE
        
            action = new QAction(QPixmap((const char**)fileopen), "&Open", this);
            action->setShortcut(tr("CTRL+O"));
            connect(action, SIGNAL(triggered()), this, SLOT(fileOpen()));
            file->addAction(action);
        
            action = new QAction(QPixmap((const char**)filesave),"&Save", this);
            action->setShortcut(tr("CTRL+S"));
            connect(action, SIGNAL(triggered()), this, SLOT(fileSave()));
            file->addAction(action);
                                                                            //<= MY CHANGE
            file->addSeparator();                                           //<= MY CHANGE
            QWidgetAction* waction1 = new QWidgetAction(this);              //<= MY CHANGE
            QLabel*        label  = new QLabel("My Data");                  //<= MY CHANGE
            label->setAlignment(Qt::AlignHCenter);                          //<= MY CHANGE
            waction1->setDefaultWidget(label);                              //<= MY CHANGE
            file->addAction(waction1);                                      //<= MY CHANGE
                                                                            //<= MY CHANGE
            QWidgetAction* waction2 = new QWidgetAction(this);              //<= MY CHANGE
            QCheckBox*        chk  = new QCheckBox("Personal Data");        //<= MY CHANGE
            waction2->setDefaultWidget(chk);                                //<= MY CHANGE
            file->addAction(waction2);                                      //<= MY CHANGE
        
        

        So, after tearoff, Label and checkbox are missing/hidden. Further I found following defect which looks to be not addressed yet.
        https://bugreports.qt.io/browse/QTBUG-1017

        I tried 4.8.6 and 5.5. Is there any way out for this?

        1 Reply Last reply
        0

        • Login

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