Qt hide minimize, maximize and close buttons

陌路散爱 提交于 2019-11-27 03:20:57

问题


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


回答1:


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




回答2:


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



回答3:


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();
}



回答4:


Just watch how Window Flags Example works!




回答5:


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

this also works for a window item

flags: Qt.Window | Qt.WindowTitleHint



来源:https://stackoverflow.com/questions/3211272/qt-hide-minimize-maximize-and-close-buttons

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!