Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
L-Super opened this issue Jun 14, 2024 · 2 comments
Open

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

L-Super opened this issue Jun 14, 2024 · 2 comments

Comments

@L-Super
Copy link

L-Super commented Jun 14, 2024

环境:

  • 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;
}
@L-Super
Copy link
Author

L-Super commented Jun 14, 2024

另外,如果图一是正确的预期行为,那么需要自行实现标题栏的拖动?

@EdnY1
Copy link

EdnY1 commented Sep 19, 2024

I have some helpful information.
When using extended display, QWindowKit is gonna work properly if your app is launched on your "Main display", but if you launch your application on your "Extended Display" QWindowKit is not gonna work resulting on system setting up the Default Native System Titlebar.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants