2010-07-09 234 views
8

你知道如何隐藏最小化,最大化和关闭Qt中的标题栏按钮。我特别需要将它隐藏在QMainWindow上。Qt隐藏最小化,最大化和关闭按钮

+1

难道你提到为什么你需要做的是什么? – 2010-07-09 09:29:03

+0

我不想让用户在角落按x关闭我的应用程序。我希望他在退出手术之前做一些过程。 – ufukgun 2010-07-12 06:54:03

回答

2

只要看看Window Flags Example是如何工作的!

+1

谢谢你。其实我的主要问题是隐藏mainWindow上的关闭按钮。 – ufukgun 2010-07-09 09:27:04

14

设置窗口标志Qt::Window | Qt::WindowTitleHint | Qt::CustomizeWindowHint

。注意,在某些平台上,它的行为以不同的方式。例如,在Mac OS X上它禁用,(不隐藏)关闭/最小化/最大化按钮

2

这可以通过使用在QEvent的一个eventFilter ::关闭事件从主窗口

bool MainWindow::eventFilter(QObject *obj, QEvent *event) { 

    if (event->type() == QEvent::Close) { 
     event->ignore(); 
     doWhateverYouNeedToDoBeforeClosingTheApplication(); 
     return true; 
    } 
    return QMainWindow::eventFilter(obj, event); 
} 

void MainWindow::doWhateverYouNeedToDoBeforeClosingTheApplication() { 
    // Do here what ever you need to do 
    // ... 
    // ... 

    // and finally quit 
    qApp->quit(); 
} 
3

如果你被achived使用的是Qt QML然后,除去最小化,最大化和关闭按钮,在设置窗口功能的无框窗标志的main.qml文件,如下图所示:

flags: Qt.FramelessWindowHint 
0

标志:Qt.Dialog | Qt.WindowCancelButtonHint | Qt.WindowCloseButtonHint

这也适用于一个窗口项

标志:Qt.Window | Qt.WindowTitleHint

+0

基于这些名字,我不认为这些是正确的标志......这就是为什么OP有问题找到它吗? – Taegost 2017-11-28 21:42:43

相关问题