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. How to capture the click on the question mark '?' button in dialog
Forum Updated to NodeBB v4.3 + New Features

How to capture the click on the question mark '?' button in dialog

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 2.6k 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.
  • S Offline
    S Offline
    Sprezzatura
    wrote on 31 May 2019, 20:34 last edited by
    #1

    I have a dialog that has the question mark '?' button in the title bar. When the user clicks on the button, I want to launch a Help topic.

    This button seems to be associated with the QWhatsThis thing. But this is about more than displaying a tooltip. When the user clicks on the '?', I need the code to call my function so I can display the Help topic.

    Does anyone have a code sample they can share, or a suggestion for how to do this?

    0_1559334635359_294ec49e-57ad-42d0-bb66-8e3012f73e96-image.png

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 31 May 2019, 21:25 last edited by
      #2

      Hi,

      I haven't used that yet but from the documentation of QWhatsThis you can set the Qt::WA_CustomWhatsThis attribute to keep the widget in normal mode.

      I don't know if this will work but then you could connect the triggered signal of the action created by QWhatsThis::createAction to show your help.

      Hope it helps

      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 3 Jun 2019, 02:54
      3
      • S SGaist
        31 May 2019, 21:25

        Hi,

        I haven't used that yet but from the documentation of QWhatsThis you can set the Qt::WA_CustomWhatsThis attribute to keep the widget in normal mode.

        I don't know if this will work but then you could connect the triggered signal of the action created by QWhatsThis::createAction to show your help.

        Hope it helps

        S Offline
        S Offline
        Sprezzatura
        wrote on 3 Jun 2019, 02:54 last edited by
        #3

        @SGaist I had a sense that those are the functions I would use, but I needed an example that tied it all together. I was provided with this:

        MainWindow::MainWindow(QWidget *parent) :
            QMainWindow(parent),
            ui(new Ui::MainWindow)
        {
            ui->setupUi(this);
        
            // Ensure the Help button is displayed
            setWindowFlags(Qt::WindowCloseButtonHint | Qt::WindowContextHelpButtonHint);
        
            // Set up the event filter
            qApp->installEventFilter(this);
        }
        
        MainWindow::~MainWindow()
        {
            delete ui;
        }
        
        /// Filter the events
        bool MainWindow::eventFilter(QObject *object, QEvent *event) {
            if (event->type() == QEvent::EnterWhatsThisMode) {
                _handleWhatsThisEntry(QApplication::activeWindow());
                return true;
            }
            return QObject::eventFilter(object, event);
        }
        
        /// Handle the EnterWhatsThisMode event
        void MainWindow::_handleWhatsThisEntry(QWidget * /*sender*/) {
            qDebug() << "What's This Mode Entered";
        
            // Launch help file using default system viewer
            //QDesktopServices::openUrl(QUrl("file:///C:/path/to/help/file.chm", QUrl::TolerantMode));
        }
        
        class MainWindow : public QMainWindow
        {
            Q_OBJECT
        
        public:
            explicit MainWindow(QWidget *parent = 0);
            ~MainWindow();
        
        protected:
            /// Filter events
            virtual bool eventFilter(QObject *object, QEvent *event);
        
        private:
            Ui::MainWindow *ui;
        
            /// Handle the EnterWhatsThisMode event
            void _handleWhatsThisEntry(QWidget * /*sender*/);
        };
        

        Works for dialogs too.

        Thanks for your help.

        1 Reply Last reply
        2

        1/3

        31 May 2019, 20:34

        • Login

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