Windows タイトル バーのない Qt アプリケーションを作成したい (カスタマイズしたものを作成したい)。
ウィンドウを最小化、最大化、閉じるための 3 つのボタンを作成しました。ウィンドウを最大化すると、アプリケーションはタスクバーを考慮せず、最大化されたウィンドウはタスクバーの下にある画面全体を占めることを除いて、すべてが機能します。代わりに、Windows からの通常の最大化コマンドは、アプリケーション ウィンドウを最大化して、タスクバーの下に移動しないようにします。
Qt::CustomizeWindowHint
ウィンドウのタイトルバーを使用しない場合、表示される最大化動作は正しいです。しかし、このフラグを使用すると、タイトル バーが消え、アプリケーションがウィンドウの下に表示されます。ここでは、動作を説明する 2 つのスクリーンショットを見つけることができます。
後者のケースでわかるように、アプリケーションが画面全体を占めるため、「閉じる」ボタンはタスクバー内に入ります。
Windows のタイトル バーを使用せずにこの動作を回避するにはどうすればよいですか? ウィンドウのタイトル バーと同じ動作を再現したいと考えています。
SampleWindow.h
#ifndef SAMPLEWINDOW_H_
#define SAMPLEWINDOW_H_
#include <QMainWindow>
#include <QPushButton>
#include <QHBoxLayout>
class SampleWindow : public QMainWindow {
Q_OBJECT
public:
SampleWindow();
virtual ~SampleWindow() = default;
};
#endif // !SAMPLEWINDOW_H_
SampleWindow.cpp
#include "SampleWindow.h"
#include <QCoreApplication>
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->addWidget(minimizeButton);
layout->addWidget(maximizeButton);
layout->addWidget(closeButton);
centralWidget->setLayout(layout);
setCentralWidget(centralWidget);
connect(closeButton, &QPushButton::clicked, [=]() {QCoreApplication::quit();});
connect(minimizeButton, &QPushButton::clicked, this, [=]() {setWindowState(Qt::WindowMinimized);});
connect(maximizeButton, &QPushButton::clicked, this, [=]() {setWindowState(Qt::WindowMaximized);});
}
メイン.cpp
#include <QApplication>
#include "SampleWindow.h"
int main(int argc, char* argv[]) {
QApplication app(argc, argv);
SampleWindow mainWindow;
mainWindow.show();
return app.exec();
}