Skip to content
New issue

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

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

Already on GitHub? # to your account

禁用标题栏最大化按钮时图标按钮仍旧可以最大化 #163

Closed
pigrich opened this issue Feb 11, 2025 · 1 comment
Closed

禁用标题栏最大化按钮时图标按钮仍旧可以最大化 #163

pigrich opened this issue Feb 11, 2025 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@pigrich
Copy link

pigrich commented Feb 11, 2025

我的代码如下:

Widget::Widget(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::OPLoginWidget)
{
    ui->setupUi(this);
    setWindowFlag(Qt::WindowMaximizeButtonHint, false);
    initTitleBar();
}

Widget::~Widget()
{
    delete ui;
}

void Widget::initTitleBar()
{
    auto agent = new QWK::WidgetWindowAgent(this);
    agent->setup(this);

    auto titleBar = new QWK::WindowBar(this);
    titleBar->setAutoFillBackground(true);
    auto pal = titleBar->palette();
    pal.setColor(QPalette::Window, QColor::fromString("#f4f4f4"));
    titleBar->setPalette(pal);
    // title
    auto titleLabel = new QLabel(windowTitle(), titleBar);
    titleLabel->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
    auto font = titleLabel->font();
    font.setPointSize(10);
    titleLabel->setFont(font);
    titleBar->setTitleLabel(titleLabel);
    // icon
    auto iconBtn = new QWK::WindowButton();
    iconBtn->setObjectName("icon-button");
    iconBtn->setIcon(windowIcon());
    titleBar->setIconButton(iconBtn);
    // min, close buttons
    auto minBtn = new QWK::WindowButton();
    minBtn->setObjectName("min-button");
    titleBar->setMinButton(minBtn);

    auto closeBtn = new QWK::WindowButton();
    closeBtn->setObjectName("close-button");
    titleBar->setCloseButton(closeBtn);

    titleBar->setHostWidget(this);
    connect(titleBar, &QWK::WindowBar::closeRequested, this, &OPLoginWidget::close);
    connect(titleBar, &QWK::WindowBar::minimizeRequested, this, &OPLoginWidget::showMinimized);

    agent->setTitleBar(titleBar);
    agent->setSystemButton(QWK::WidgetWindowAgent::WindowIcon, iconBtn);
    agent->setSystemButton(QWK::WidgetWindowAgent::Minimize, minBtn);
    agent->setSystemButton(QWK::WidgetWindowAgent::Close, closeBtn);

    setMenuWidget(titleBar);
    StyleLoader().prefix("styles").fileName("common.qss").load(titleBar);// 加载qss文件
}
  • 首先使用系统标题栏(即注释掉initTitleBar()一行),效果如下:

Image

  • 然后使用QWK自定义标题栏,效果如下:

Image

可以发现自定义标题栏的图标按钮按下后弹出的菜单的最大化一栏并没有被禁用,导致用户仍然可以通过这个来最大化窗口

@wangwenx190 wangwenx190 self-assigned this Feb 11, 2025
@wangwenx190 wangwenx190 added the bug Something isn't working label Feb 11, 2025
@wangwenx190
Copy link
Collaborator

嗯,感谢报告,估计是内部忘记判断相关flag了

wangwenx190 added a commit that referenced this issue Feb 11, 2025
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants