Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Use a statusTip on a QAction disabled



  • 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 !


  • Moderators

    @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();
    }
    


  • 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



  • @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)?



  • 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...



  • @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... :)



  • @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" :)



  • @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.



  • Yes :)
    I wait more informations :)
    Thank you


  • Moderators

    @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.



  • 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);


Log in to reply