Expanded client area in QMainWindow
-
I want my application to occupy the entire available screen (including the titlebar area). Normally I am able to achive this using
ExpandedClientAreaHint
andNoTitleBarBackgroundHint
window flags like the following minimal example:#include <QApplication> #include <QPainter> #include <QMainWindow> class MyWidget : public QWidget { public: MyWidget(QWidget* parent=nullptr) : QWidget(parent) {} void paintEvent(QPaintEvent* event) override { QPainter painter(this); painter.fillRect(rect(), Qt::blue); } }; int main(int argc, char *argv[]) { QApplication a(argc, argv); MyWidget* my_widget = new MyWidget(); my_widget->setWindowFlag(Qt::ExpandedClientAreaHint, true); my_widget->setWindowFlag(Qt::NoTitleBarBackgroundHint, true); my_widget->show(); return a.exec(); }
Which looks like this:
However, when I use a
QMainWindow
as the top level window of the application, the titlebar background is still rendered. Here is a minimal example:#include <QApplication> #include <QPainter> #include <QMainWindow> class MyWidget : public QWidget { public: MyWidget(QWidget* parent=nullptr) : QWidget(parent) {} void paintEvent(QPaintEvent* event) override { QPainter painter(this); painter.fillRect(rect(), Qt::blue); } }; int main(int argc, char *argv[]) { QApplication a(argc, argv); MyWidget* my_widget = new MyWidget(); QMainWindow window; window.setWindowFlag(Qt::ExpandedClientAreaHint, true); window.setWindowFlag(Qt::NoTitleBarBackgroundHint, true); window.setCentralWidget(my_widget); window.show(); return a.exec(); }
and here is how it looks:
How can I achieve the original look while using QMainWindow?
This is on
Qt 6.9.0
on MacOS. -
I want my application to occupy the entire available screen (including the titlebar area). Normally I am able to achive this using
ExpandedClientAreaHint
andNoTitleBarBackgroundHint
window flags like the following minimal example:#include <QApplication> #include <QPainter> #include <QMainWindow> class MyWidget : public QWidget { public: MyWidget(QWidget* parent=nullptr) : QWidget(parent) {} void paintEvent(QPaintEvent* event) override { QPainter painter(this); painter.fillRect(rect(), Qt::blue); } }; int main(int argc, char *argv[]) { QApplication a(argc, argv); MyWidget* my_widget = new MyWidget(); my_widget->setWindowFlag(Qt::ExpandedClientAreaHint, true); my_widget->setWindowFlag(Qt::NoTitleBarBackgroundHint, true); my_widget->show(); return a.exec(); }
Which looks like this:
However, when I use a
QMainWindow
as the top level window of the application, the titlebar background is still rendered. Here is a minimal example:#include <QApplication> #include <QPainter> #include <QMainWindow> class MyWidget : public QWidget { public: MyWidget(QWidget* parent=nullptr) : QWidget(parent) {} void paintEvent(QPaintEvent* event) override { QPainter painter(this); painter.fillRect(rect(), Qt::blue); } }; int main(int argc, char *argv[]) { QApplication a(argc, argv); MyWidget* my_widget = new MyWidget(); QMainWindow window; window.setWindowFlag(Qt::ExpandedClientAreaHint, true); window.setWindowFlag(Qt::NoTitleBarBackgroundHint, true); window.setCentralWidget(my_widget); window.show(); return a.exec(); }
and here is how it looks:
How can I achieve the original look while using QMainWindow?
This is on
Qt 6.9.0
on MacOS. -
@Pl45m4 I want to have MacOS's integrated menubar (the one that is integrated with the system menubar) but I don't want the application titlebar.
@hexo Not really possible with qt... i tried too for way to long. There is a frameless window example that goes into this direction but than u loose the ability for good docking of the window.
-
@StudentScripter I used to be able to do this using custom macos-specific code (see https://github.com/ahrm/sioyek/pull/1015) but it has stopped working in recent Qt versions (I think after 6.8 but I am not 100% sure).