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. Use a statusTip on a QAction disabled
QtWS25 Last Chance

Use a statusTip on a QAction disabled

Scheduled Pinned Locked Moved Unsolved General and Desktop
11 Posts 4 Posters 3.8k 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.
  • H Offline
    H Offline
    hizoka
    wrote on last edited by
    #1

    Hi,

    I would like show a statusTip message on a QAction of a QMenu of a QMenuBar, enabled or disabled...

    When enabled, no problem.

    But when it is disable (setEnabled(false)), no message...

    I tryed to use installEventFilter on the QAction, QMenu and QMenuBar, but without succes...

    Any idea ?

    Thank you !

    A 1 Reply Last reply
    0
    • H hizoka

      Hi,

      I would like show a statusTip message on a QAction of a QMenu of a QMenuBar, enabled or disabled...

      When enabled, no problem.

      But when it is disable (setEnabled(false)), no message...

      I tryed to use installEventFilter on the QAction, QMenu and QMenuBar, but without succes...

      Any idea ?

      Thank you !

      A Offline
      A Offline
      ambershark
      wrote on last edited by ambershark
      #2

      @hizoka I threw it in an example app I wrote for someone on the forums the other day and it works just fine when disabled. So you'll have to share some more info so we can try to figure out why yours is not working..

      0_1520997821513_statustip.png

      Here was the code I used:

      MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
      {
      	resize(600, 400);
      
      	auto *tw = new QTabWidget();
      	auto *w = new QWidget();
      	auto *layout = new QVBoxLayout();
      	w->setLayout(layout);
      
      	layout->addWidget(new QLabel("Some Widget"));
      	layout->addWidget(new MyWizard());
      
      	tw->addTab(w, "Test");
      	setCentralWidget(tw);
      
              // CODE ADDED FOR STATUSTIP TEST
      	auto *act = new QAction("test");
      	auto *tb = addToolBar("test");
      	act->setStatusTip("this is a test");
      	tb->addAction(act);
      	act->setEnabled(false);
      	statusBar();
      }
      

      My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

      1 Reply Last reply
      0
      • H Offline
        H Offline
        hizoka
        wrote on last edited by
        #3

        Hi, thanks for the reply.

        With my pyqt code :

        #!/usr/bin/python3 -u
        # -*- coding: utf-8 -*-
        import sys
        from PyQt5.QtGui import *
        
        from PyQt5.QtWidgets import *
        
        from PyQt5.QtCore import *
        
        class caca(QMainWindow):
            def __init__(self, parent=None):
                super(caca, self).__init__(parent)
        
                self.resize(600, 400)
        
                self.statusbar = QStatusBar(self)
                self.setStatusBar(self.statusbar)
        
                w = QWidget()
                layout = QVBoxLayout()
                w.setLayout(layout)
        
                l = QLabel("Some Widget")
                layout.addWidget(QLabel("Some Widget"))
        
                self.setCentralWidget(w)
        
                self.menubar = QMenuBar(self)
        
                menu = QMenu(self.menubar)
                menu.setTitle("youpi")
                action = QAction("test", menu)
                action.setStatusTip("this is a test")
                action.setEnabled(False)
                action2 = QAction("test2", menu)
                action2.setStatusTip("this is a test 2")
                menu.addAction(action)
                menu.addAction(action2)
                action3 = QAction("test3", menu)
                action3.setStatusTip("this is a test 3")
                action3.setEnabled(False)
                action4 = QAction("test4", menu)
                action4.setStatusTip("this is a test 4")
                self.menubar.addAction(menu.menuAction())
                self.menubar.addAction(action3)
                self.menubar.addAction(action4)
                self.setMenuBar(self.menubar)
        
                self.show()
        
        
        app = QApplication(sys.argv)
        cacaClass = caca()
        cacaClass.setAttribute(Qt.WA_DeleteOnClose)
        sys.exit(app.exec())
        

        0_1521056247190_QActionStatusTip.gif

        JonBJ 1 Reply Last reply
        0
        • H hizoka

          Hi, thanks for the reply.

          With my pyqt code :

          #!/usr/bin/python3 -u
          # -*- coding: utf-8 -*-
          import sys
          from PyQt5.QtGui import *
          
          from PyQt5.QtWidgets import *
          
          from PyQt5.QtCore import *
          
          class caca(QMainWindow):
              def __init__(self, parent=None):
                  super(caca, self).__init__(parent)
          
                  self.resize(600, 400)
          
                  self.statusbar = QStatusBar(self)
                  self.setStatusBar(self.statusbar)
          
                  w = QWidget()
                  layout = QVBoxLayout()
                  w.setLayout(layout)
          
                  l = QLabel("Some Widget")
                  layout.addWidget(QLabel("Some Widget"))
          
                  self.setCentralWidget(w)
          
                  self.menubar = QMenuBar(self)
          
                  menu = QMenu(self.menubar)
                  menu.setTitle("youpi")
                  action = QAction("test", menu)
                  action.setStatusTip("this is a test")
                  action.setEnabled(False)
                  action2 = QAction("test2", menu)
                  action2.setStatusTip("this is a test 2")
                  menu.addAction(action)
                  menu.addAction(action2)
                  action3 = QAction("test3", menu)
                  action3.setStatusTip("this is a test 3")
                  action3.setEnabled(False)
                  action4 = QAction("test4", menu)
                  action4.setStatusTip("this is a test 4")
                  self.menubar.addAction(menu.menuAction())
                  self.menubar.addAction(action3)
                  self.menubar.addAction(action4)
                  self.setMenuBar(self.menubar)
          
                  self.show()
          
          
          app = QApplication(sys.argv)
          cacaClass = caca()
          cacaClass.setAttribute(Qt.WA_DeleteOnClose)
          sys.exit(app.exec())
          

          0_1521056247190_QActionStatusTip.gif

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by JonB
          #4

          @hizoka
          This may (well) be irrelevant, but I note that your code disables the action before adding it to the menubar, while @ambershark's code disables it after it is added. I don't suppose that affects the tooltip behaviour, does it...? Or, his is QToolBar while yours is QMenuBar..., if that affects actions' tooltips (unlikely)?

          1 Reply Last reply
          0
          • H Offline
            H Offline
            hizoka
            wrote on last edited by hizoka
            #5

            This may (well) be irrelevant, but I note that your code disables the action before adding it to the menubar, while @ambershark's code disables it after it is added. I don't suppose that affects the tooltip behaviour, does it...?
            Nope, no change :)

            Or, his is QToolBar while yours is QMenuBar..., if that affects actions' tooltips (unlikely)?
            Maybe... I use QtDesigner for create some dialogs and it use QMenuBar...
            I will try with QToolBar

            EDIT : Yes that works with QToolBar but I can't create QMenu in this widget...

            JonBJ 1 Reply Last reply
            0
            • H hizoka

              This may (well) be irrelevant, but I note that your code disables the action before adding it to the menubar, while @ambershark's code disables it after it is added. I don't suppose that affects the tooltip behaviour, does it...?
              Nope, no change :)

              Or, his is QToolBar while yours is QMenuBar..., if that affects actions' tooltips (unlikely)?
              Maybe... I use QtDesigner for create some dialogs and it use QMenuBar...
              I will try with QToolBar

              EDIT : Yes that works with QToolBar but I can't create QMenu in this widget...

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by
              #6

              @hizoka

              EDIT : Yes that works with QToolBar but I can't create QMenu in this widget...

              OK, so now this is a QMenuBar versus QToolBar issue... You'll have to ask @ambershark nicely to retry his code with the former... :)

              1 Reply Last reply
              0
              • H Offline
                H Offline
                hizoka
                wrote on last edited by hizoka
                #7

                @JonB said in Use a statusTip on a QAction disabled:

                OK, so now this is a QMenuBar versus QToolBar issue...

                Not really same widgets, I just want use QMenuBar like I said "I would like show a statusTip message on a QAction of a QMenu of a QMenuBar" :)

                JonBJ 1 Reply Last reply
                0
                • H hizoka

                  @JonB said in Use a statusTip on a QAction disabled:

                  OK, so now this is a QMenuBar versus QToolBar issue...

                  Not really same widgets, I just want use QMenuBar like I said "I would like show a statusTip message on a QAction of a QMenu of a QMenuBar" :)

                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on last edited by JonB
                  #8

                  @hizoka
                  Yes, I understand. I mean, we have established (from @ambershark) that the behaviour for disabled tooltips appears to differ depending on whether the actions are hosted in a toolbar vs a menubar. Someone has to establish whether that difference is inevitable/intentional/bug or whether you can do anything about it.

                  1 Reply Last reply
                  0
                  • H Offline
                    H Offline
                    hizoka
                    wrote on last edited by
                    #9

                    Yes :)
                    I wait more informations :)
                    Thank you

                    A 1 Reply Last reply
                    0
                    • H hizoka

                      Yes :)
                      I wait more informations :)
                      Thank you

                      A Offline
                      A Offline
                      ambershark
                      wrote on last edited by
                      #10

                      @hizoka Tested it with a QAction in a QMenu and it works the same as yours.

                      So in that case you will need to override QMenu and deal with the mouseover of a disabled menu item yourself. When you mouseover the item, just force show it's tool tip.

                      That's a lot of work for a disabled item though. Typically you wouldn't really expect a tooltip from a disabled item since it is disabled and not usable anyway.

                      You can submit as a bug/feature request to the Qt team as well, but my feeling on the menu item not showing tooltip/statustip is that it is by design and not a bug.

                      My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

                      1 Reply Last reply
                      1
                      • M Offline
                        M Offline
                        mwestphal
                        wrote on last edited by
                        #11

                        Here is the solution if anyone needs it :

                        //-----------------------------------------------------------------------------
                        class myActiveDisabledStyle : public QProxyStyle
                        {
                        public:
                        int styleHint(StyleHint hint, const QStyleOption* option = 0, const QWidget* widget = 0,
                        QStyleHintReturn* returnData = 0) const override
                        {
                        return hint == QStyle::SH_Menu_AllowActiveAndDisabled ? 1 : QProxyStyle::styleHint(
                        hint, option, widget, returnData);
                        }
                        };

                        // Make sure disabled actions are still considered active
                        menu.setStyle(new myActiveDisabledStyle);

                        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