Qt hide minimize, maximize and close buttons

后端 未结 6 1037
时光说笑
时光说笑 2020-12-10 03:58

Do you know how to hide minimize, maximize and close buttons of title bar in Qt. I especially need to hide it on QMainWindow.

相关标签:
6条回答
  • 2020-12-10 04:30

    Just watch how Window Flags Example works!

    0 讨论(0)
  • 2020-12-10 04:36

    For the close button, you can override the closeEvent() of QmainWindow

    class MainWindow(QMainWindow):    
        def closeEvent(self, event):
            event.ignore()
            return
    
    0 讨论(0)
  • 2020-12-10 04:39

    Set this window flags Qt::Window | Qt::WindowTitleHint | Qt::CustomizeWindowHint

    Note, that on some platforms it behaves in different way. For example on Mac OS X it Disables, (not hides) close/minimize/maximize buttons

    0 讨论(0)
  • 2020-12-10 04:39

    This can be achived by using an eventFilter on the QEvent::Close event from your MainWindow

    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();
    }
    
    0 讨论(0)
  • 2020-12-10 04:41

    If you are using Qt qml then, to remove minimize, maximize and close button, set the frameless window flag in the window function in your main.qml file, like below:

    flags: Qt.FramelessWindowHint
    
    0 讨论(0)
  • 2020-12-10 04:42

    flags: Qt.Dialog | Qt.WindowCancelButtonHint | Qt.WindowCloseButtonHint

    this also works for a window item

    flags: Qt.Window | Qt.WindowTitleHint

    0 讨论(0)
提交回复
热议问题