event or mousePressEvent functions works for inside of a widget but I want to catch when clicked on a titleBar (upper part of menuBar, contains close button etc.)
How ca
You can override nativeEvent, then get mouse position to compare with geometry (exclude window frame) and frameGeometry (include window frame) to detect if it hits title bar or not
bool MyClass::nativeEvent(const QByteArray & eventType, void * message, long * result)
{
MSG* msg = (MSG*)(message);
if (msg->message == WM_NCLBUTTONDOWN)
{
int mouseX = GET_X_LPARAM(msg->lParam);
int mouseY = GET_Y_LPARAM(msg->lParam);
QRect frame = frameGeometry();
QRect content = geometry();
qDebug() << "mouseX: " << mouseX << "mouseY:" << mouseY;
qDebug() << "frame: " << frame;
qDebug() << "content: " << content;
if (mouseY < content.y() && mouseY >= frame.y())
{
qDebug() << "Hit title bar";
}
}
*result = 0;
return false;
}