QObject::connect(mainWindow,
&QMainWindow::windowIconChanged,
titleBarWidget.iconButton,
&QPushButton::setIcon);
QObject::connect(titleBarWidget.iconButton,
&QPushButton::clicked, mainWindow, [mainWindow] () {
#ifdef WIN32
HWND hwnd = (HWND)QGuiApplication::platformNativeInterface()->nativeResourceForWindow(QByteArrayLiteral("handle"), mainWindow->windowHandle());
//mainWindow->winId()
HMENU systemMenu = ::GetSystemMenu(hwnd, FALSE);
if (systemMenu) {
// Open system menu in the left top corner of window.
double pos_x = static_cast<double>(mainWindow->pos().x()) * mainWindow->devicePixelRatioF();
double pos_y = static_cast<double>(mainWindow->pos().y() + mainWindow->menuWidget()->height()) * mainWindow->devicePixelRatioF();
TrackPopupMenu(systemMenu, TPM_LEFTALIGN | TPM_LEFTBUTTON,
pos_x, pos_y, NULL,
hwnd, 0);
}
#endif
});
However I don't know how to show this when user right-click titlebar as well, any idea?