2008-09-17 110 views

回答

45

默认情况下,Qt :: WindowContextHelpButtonHint标志被添加到对话框中。 您可以使用参数WindowFlags来控制此对话框构造函数。如果添加了的Qt :: WindowContextHelpButtonHint标志你将得到帮助按钮回来

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

例如,您可以通过做只指定TitleHintSystemMenu标志。

在PyQt的你可以这样做:在窗口标志

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

更多细节可以在Qt文档中WindowType enum找到。

+2

见下面rrwick的答案。如果你没有的Qt :: WindowCloseButtonHint添加到您的标志,你会禁用的关闭按钮,默认情况下启用。 – Dan 2015-01-12 21:54:49

+1

这里是一个链接PyQt4中指定的窗口标志,http://pyqt.sourceforge.net/Docs/PyQt4/qt.html#WindowType-enum如果你想关闭按钮 – Barmaley 2015-06-09 20:43:53

+1

同时添加标志'的Qt :: WindowCloseButtonHint`被激活。 – 2016-09-30 16:25:20

26

好的,我找到了一种方法来做到这一点。

它处理窗口标志。所以这里是我使用的代码:

Qt::WindowFlags flags = windowFlags() 

Qt::WindowFlags helpFlag = 
Qt::WindowContextHelpButtonHint; 

flags = flags & (~helpFlag); 
setWindowFlags(flags); 

但是通过这样做,有时对话框的图标被重置。所以要确保对话框的图标不会改变,你可以添加两行。

QIcon icon = windowIcon(); 

Qt::WindowFlags flags = windowFlags(); 

Qt::WindowFlags helpFlag = 
Qt::WindowContextHelpButtonHint; 

flags = flags & (~helpFlag); 

setWindowFlags(flags); 

setWindowIcon(icon); 
3

这里列出的工作,但你自己回答这个问题的答案,我建议你运行该示例程序$QTDIR/examples/widgets/windowflags。这将允许您测试窗口标志及其效果的所有配置。非常有用的搞清楚松鼠windowflags问题。

0

我找不到插槽,但您可以覆盖虚拟winEvent函数。

#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 
8

我就遇到了这个问题,在Windows 7中,Qt的5.2,而工作最适合我的标志组合是这样的:

的Qt :: WindowTitleHint | Qt :: WindowCloseButtonHint

这给了我一个工作关闭按钮,但没有问号帮助按钮。只使用Qt :: WindowTitleHint或Qt :: WindowSystemMenuHint摆脱了帮助按钮,但它也禁用了关闭按钮。

正如Michael Bishop所建议的那样,它正在使用windowflags例子来演示这种组合。谢谢!

20
// remove question mark from the title bar 
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); 
0

通过以下方式默认情况下,在应用程序中所有的对话框中删除问号可用于:

附上以下事件过滤器QApplication在程序开始的地方:

bool eventFilter (QObject *watched, QEvent *event) override 
    { 
    if (event->type() == QEvent::Create) 
     { 
     if (watched->isWidgetType()) 
      { 
      auto w = static_cast<QWidget *> (watched); 
      w->setWindowFlags (w->windowFlags() & (~Qt::WindowContextHelpButtonHint)); 
      } 
     } 
    return QObject::eventFilter (watched, event); 
    } 
相关问题