[Question] How do I use `setMaximizeMask()` properly?
kresimirko opened this issue · 5 comments
I've tried using setMaximizeMask()
, and it works... except that it makes my maximize button unclickable.
As you can see here, the tooltip works, but the mask is preventing mouse events.
Usual button behavior.
This is my styleWindow()
code (with some taken from GoodShowCase):
void MainWindow::styleWindow() // todo: adjust these margins a bit + set rects for maximize button (win 11)
{
setMargins(titleBarWidget->height() /*Title bar height*/,
6 + m_icon->width() + 6 /*Icon size*/,
menu_bar->width() /*Left margin*/,
captionButtonsWidget->width() + 3 /*Right margin*/);
setCaptionButtonsHandled(true, Qt::TopRightCorner);
//setRightMask(QRegion(captionButtonsWidget->rect()));
setMaximizeMask(QRegion(m_button_maximize->width() + 3, 0, m_button_maximize->width(), m_button_maximize->height()));
//qDebug() << maximizeMask();
bool maximized = isMaximized();
m_button_maximize->setVisible(!maximized);
m_button_maximize->setEnabled(!maximized);
m_button_restore->setVisible(maximized);
m_button_restore->setEnabled(maximized);
}
What am I doing wrong? (if You need more code, let me know)
@kresimirko: What you are doing wrong? Nothing!
When you specify the minimize, maximize and close button locations to the library, these buttons cannot be clicked because they don't receive any hover or click events, and it's because on Windows, to show the Snap window when the maximize button is hovered, these areas needs to belong to Windows, and your buttons should work in passive mode, receiving it's states with the QGoodWindow::captionButtonStateChanged()
SIGNAL
.
See docs for possible values.
I hope this help you to solve your problem.
Thanks!
Thank You, I'll try this out later!
@antonypro Okay, I've tried doing this, but when I try to do this:
connect(this, &QGoodWindow::captionButtonStateChanged, this, &MainWindow::onCaptionButtonStateChanged);
void onCaptionButtonStateChanged(const QGoodWindow::CaptionButtonState &state)
{
qDebug() << "test";
}
...I get linker errors:
mainwindow.obj:-1: error: LNK2019: unresolved external symbol "public: void __cdecl MainWindow::onCaptionButtonStateChanged(enum QGoodWindow::CaptionButtonState const &)" (?onCaptionButtonStateChanged@MainWindow@@QEAAXAEBW4CaptionButtonState@QGoodWindow@@@Z) referenced in function "public: __cdecl MainWindow::MainWindow(class QWidget *)" (??0MainWindow@@QEAA@PEAVQWidget@@@Z)
moc_mainwindow.obj:-1: error: LNK2001: unresolved external symbol "public: void __cdecl MainWindow::onCaptionButtonStateChanged(enum QGoodWindow::CaptionButtonState const &)" (?onCaptionButtonStateChanged@MainWindow@@QEAAXAEBW4CaptionButtonState@QGoodWindow@@@Z)
How do I fix this?
@kresimirko: I think you need to add MainWindow::
to make onCaptionButtonStateChanged
a class member, as the following:
void MainWindow::onCaptionButtonStateChanged(const QGoodWindow::CaptionButtonState &state)
{
qDebug() << int(state);
}
This was the case, thanks!