Skip to content

macOS 扩展屏下,在不同屏幕启动,窗口行为不一致 #100

@L-Super

Description

@L-Super

环境:

  • Mac macOS 14.4.1
  • CPU M3
  • CLion IDE
  • Qt 5.15.14
  • 4K分辨率扩展屏

在Mac主屏,使用CLion运行启动程序:

image

在扩展屏,使用CLion运行启动程序:

image

即,程序出现在主屏或者扩展屏,窗口将会不一样。

#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;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghelp wantedExtra attention is needed

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions