add APIs to disable Mac window std buttons

This commit is contained in:
Altair Wei 2021-11-13 00:15:13 +08:00
parent 57610634d6
commit 7b82375543
2 changed files with 30 additions and 0 deletions

View File

@ -79,6 +79,9 @@ FRAMELESSHELPER_API Qt::MouseButtons getMacMouseButtons();
FRAMELESSHELPER_API bool setStandardWindowButtonsVisibility(QWindow *w, bool visible);
FRAMELESSHELPER_API bool setStandardWindowButtonsPosition(QWindow *w, const QPoint &pos);
FRAMELESSHELPER_API QSize standardWindowButtonsSize(QWindow *w);
FRAMELESSHELPER_API bool setCloseBtnEnabled(QWindow *w, bool enable = true);
FRAMELESSHELPER_API bool setMinBtnEnabled(QWindow *w, bool enable = true);
FRAMELESSHELPER_API bool setZoomBtnEnabled(QWindow *w, bool enable = true);
#endif // Q_OS_MAC
}

View File

@ -264,6 +264,33 @@ QSize standardWindowButtonsSize(QWindow *w)
return QSize(width, height);
}
bool setStandardWindowButtonEnabled(QWindow *w, NSWindowButton name, bool enable = true)
{
NSWindow* nswindow = getNSWindow(w);
if (nswindow == nullptr)
return false;
NSButton* btn = [nswindow standardWindowButton:name];
[btn setEnabled: enable ? YES : NO];
return true;
}
bool setCloseBtnEnabled(QWindow *w, bool enable)
{
return setStandardWindowButtonEnabled(w, NSWindowCloseButton, enable);
}
bool setMinBtnEnabled(QWindow *w, bool enable)
{
return setStandardWindowButtonEnabled(w, NSWindowMiniaturizeButton, enable);
}
bool setZoomBtnEnabled(QWindow *w, bool enable)
{
return setStandardWindowButtonEnabled(w, NSWindowZoomButton, enable);
}
} // namespace Utilities
FRAMELESSHELPER_END_NAMESPACE