How to capture the click on the question mark '?' button in dialog
-
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?
-
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
-
@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.