Do you know how to hide minimize, maximize and close buttons of title bar in Qt. I especially need to hide it on QMainWindow.
Asked
Active
Viewed 5.0k times
17
-
1Could you mention why you need to do that? – static_rtti Jul 09 '10 at 09:29
-
i dont want user close my application by pressing x on the corner. i want him to make some processes before quit operation. – ufukgun Jul 12 '10 at 06:54
6 Answers
27
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

Kamil Klimek
- 12,884
- 2
- 43
- 58
6
Just watch how Window Flags Example works!
-
1thank u mosg. actually my main problem is hiding close button on mainWindow. – ufukgun Jul 09 '10 at 09:27
2
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();
}
1
For the close button, you can override the closeEvent() of QmainWindow
class MainWindow(QMainWindow):
def closeEvent(self, event):
event.ignore()
return

Mike
- 51
- 5
0
flags: Qt.Dialog | Qt.WindowCancelButtonHint | Qt.WindowCloseButtonHint
this also works for a window item
flags: Qt.Window | Qt.WindowTitleHint

Randall
- 1
- 1
-
Based on those names, I wouldn't think those are the correct flags for this... Is that why the OP was having problems finding it? – Taegost Nov 28 '17 at 21:42