Maximize window maintaining taskbar limits
<p>I want to create a Qt application without the windows title bar (I want to create a customized one).</p>

<p>I've created three buttons for minimizing, maximizing and closing the window. Everything works except for considering that when I maximize the window, application doesn't take into account the taskbar, and the maximized window takes the entire screen, going under the taskbar. A normal maximize command from windows instead maximizes the application window avoiding to go under the taskbar.</p>

<p>If I don't use the <code>Qt::CustomizeWindowHint</code> the window title bar appears, and maximizing behaviour is correct; but if I use this flag, the title bar disappears and the application goes under the window: here you can find two screenshots explaning the behaviour:</p>

<p>With Windows title:
<a href="https://i.stack.imgur.com/8vm4O.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8vm4O.png" alt="enter image description here"></a></p>

<p>Without Windows title:
<a href="https://i.stack.imgur.com/CjTMF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/CjTMF.png" alt="enter image description here"></a></p>

<p>As you can see in latter case che "Close" button goes inside the taskbar because the application takes the entire screen.</p>

<p>How can I avoid this behaviour without using windows title bar? I want to recreate the same behaviour as with the window title bar.</p>

<p>SampleWindow.h</p>

<pre><code>#ifndef SAMPLEWINDOW_H_
#define SAMPLEWINDOW_H_

#include &lt;QMainWindow&gt;
#include &lt;QPushButton&gt;
#include &lt;QHBoxLayout&gt;

class SampleWindow : public QMainWindow {

  Q_OBJECT

public:
  SampleWindow();
  virtual ~SampleWindow() = default;
};

#endif // !SAMPLEWINDOW_H_
</code></pre>

<p>SampleWindow.cpp</p>

<pre><code>#include "SampleWindow.h"
#include &lt;QCoreApplication&gt;

SampleWindow::SampleWindow() :
QMainWindow() {
  // With uncommenting this line the title bar disappears
  // but application goes under the taskbar when maximized
  //
  //setWindowFlags(Qt::CustomizeWindowHint);
  auto centralWidget = new QWidget(this);
  auto layout = new QHBoxLayout(this);
  auto minimizeButton = new QPushButton("Minimize", this);
  auto maximizeButton = new QPushButton("Maximize", this);
  auto closeButton = new QPushButton("Close", this);
  layout-&gt;addWidget(minimizeButton);
  layout-&gt;addWidget(maximizeButton);
  layout-&gt;addWidget(closeButton);
  centralWidget-&gt;setLayout(layout);
  setCentralWidget(centralWidget);
  connect(closeButton, &amp;QPushButton::clicked, [=]() {QCoreApplication::quit();});
  connect(minimizeButton, &amp;QPushButton::clicked, this, [=]() {setWindowState(Qt::WindowMinimized);});
  connect(maximizeButton, &amp;QPushButton::clicked, this, [=]() {setWindowState(Qt::WindowMaximized);});
}
</code></pre>

<p>Main.cpp</p>

<pre><code>#include &lt;QApplication&gt;
#include "SampleWindow.h"

int main(int argc, char* argv[]) {
  QApplication app(argc, argv);
  SampleWindow mainWindow;
  mainWindow.show();
  return app.exec();
}
</code></pre>