views:

2058

answers:

5

I am using QT Dialogs in one of my application. I need to hide/delete the help button. But i am not able to locate where exactly i get the handle to his help button. Not sure if its a particular flag on the QT window.

Kindly let me know if you know how to achieve this.

+8  A: 

By default the Qt::WindowContextHelpButtonHint flag is added to dialogs. You can control this with the WindowFlags parameter to the dialog constructor.

For instance you can specify only the TitleHint and SystemMenu flags by doing:

QDialog *d = new QDialog(0, Qt::WindowSystemMenuHint | Qt::WindowTitleHint);
d->exec();

If you add the Qt::WindowContextHelpButtonHint flag you will get the help button back.

In PyQt you can do:

from PyQt4 import QtGui, QtCore
app = QtGui.QApplication([])
d = QtGui.QDialog(None, QtCore.Qt.WindowSystemMenuHint | QtCore.Qt.WindowTitleHint)
d.exec_()

More details on window flags can be found on the WindowType enum in the Qt documentation.

amos
+3  A: 

Ok , I found a way to do this.

It does deal with the Window flags. So here is the code i used


Qt::WindowFlags flags = windowFlags()

Qt::WindowFlags helpFlag = Qt::WindowContextHelpButtonHint;

flags = flags & (~helpFlag);

setWindowFlags(flags);


But by doing this sometimes the icon of the dialog gets reset. So to make sure the icon of the dialog does not change you can add two lines.


QIcon icon = windowIcon();

Qt::WindowFlags flags = windowFlags();

Qt::WindowFlags helpFlag = Qt::WindowContextHelpButtonHint;

flags = flags & (~helpFlag);

setWindowFlags(flags);

setWindowIcon(icon);


AJ
+2  A: 

The answers listed here will work, but to answer it yourself, I'd recommend you run the example program $QTDIR/examples/widgets/windowflags. That will allow you to test all the configurations of window flags and their effects. Very useful for figuring out squirrelly windowflags problems.

Michael Bishop
A: 

Its fine to have the context help button dispalyed. then i want some slot/method to be called when i click on that "?" icon. how to acheive that. which event handler to implement or which signal is generated for this. not finding any solution. pls help on this regard.

thanks, ALex

alex
This is not an answer. This should be posted as a question.
Mark Byers
A: 

I couldn't find a slot but you can override the virtual winEvent function.

#if defined(Q_WS_WIN)
bool MyWizard::winEvent(MSG * msg, long * result)
{
    switch (msg->message)
    {
    case WM_NCLBUTTONDOWN:
        if (msg->wParam == HTHELP)
        {

        }
        break;
    default:
        break;
    }
    return QWizard::winEvent(msg, result);
}
#endif