环境:
- Mac macOS 14.4.1
- CPU M3
- CLion IDE
- Qt 5.15.14
- 4K分辨率扩展屏
在Mac主屏,使用CLion运行启动程序:
在扩展屏,使用CLion运行启动程序:
即,程序出现在主屏或者扩展屏,窗口将会不一样。
#include "MainWindow.h"
#include "QWKWidgets/widgetwindowagent.h"
#include "ui_MainWindow.h"
#include <QPushButton>
MainWindow::MainWindow(QWidget *parent) : QWidget(parent), ui(new Ui::MainWindow) {
ui->setupUi(this);
auto titleLabel = new QLabel("hhhhh");
auto minButton = new QPushButton("-");
minButton->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
auto maxButton = new QPushButton("[]");
maxButton->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
auto closeButton = new QPushButton("x");
closeButton->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
// setWindowFlags(Qt::FramelessWindowHint);
auto agent = new QWK::WidgetWindowAgent(this);
agent->setup(this);
windowBar = new QWK::WindowBar();
#if defined(Q_OS_WIN32)
windowBar->setMinButton(minButton);
windowBar->setMaxButton(maxButton);
windowBar->setCloseButton(closeButton);
#endif
windowBar->setTitleLabel(titleLabel);
windowBar->setHostWidget(this);
agent->setTitleBar(windowBar);
#if defined(Q_OS_WIN32)
agent->setSystemButton(QWK::WindowAgentBase::Minimize, windowBar->minButton());
agent->setSystemButton(QWK::WindowAgentBase::Maximize, windowBar->maxButton());
agent->setSystemButton(QWK::WindowAgentBase::Close, windowBar->closeButton());
#endif
// agent->setHitTestVisible(windowBar->menuBar(), true);
#ifdef Q_OS_MAC
agent->setSystemButtonAreaCallback([](const QSize &size) {
static constexpr const int width = 75;
return QRect(QPoint(size.width() - width, 0), QSize(width, size.height()));
});
#endif
#if defined(Q_OS_WIN32)
connect(windowBar, &QWK::WindowBar::minimizeRequested, this, &QWidget::showMinimized);
connect(windowBar, &QWK::WindowBar::maximizeRequested, this, [this, maxButton](bool max) {
if (max) {
showMaximized();
} else {
showNormal();
}
});
connect(windowBar, &QWK::WindowBar::closeRequested, this, &QWidget::close);
#endif
}
MainWindow::~MainWindow() {
delete ui;
}
环境:
在Mac主屏,使用CLion运行启动程序:
在扩展屏,使用CLion运行启动程序:
即,程序出现在主屏或者扩展屏,窗口将会不一样。