繁体   English   中英

最小化对话框的frameGeometry(titleBar)

[英]Minimized dialog's frameGeometry (titleBar)

我有一个在其父窗口中最小化的对话框。 当我调用frameGeometry()时,结果是活动对话框的(未最小化)数字。

我想知道titleBar在哪里。 (当对话框最小化时,仅显示对话框的titleBar)

你可以试试这个吗

头文件

#ifndef MYDIALOG_H
#define MYDIALOG_H

#include <QtWidgets/QDialog>
#include <QtWidgets/qmainwindow.h>
class MyDialog : public QDialog
{
    Q_OBJECT

public:
    MyDialog(QWidget *parent = 0);
    ~MyDialog();

protected:
    virtual bool nativeEvent(const QByteArray & eventType, void * message, long * result);

};

class MyWindow : public QMainWindow
{
    Q_OBJECT
public: 
    MyWindow();
    ~MyWindow();

private:
    MyDialog * m_dialog;

};

#endif // MYDIALOG_H

源文件

#include "mydialog.h"
#include <windows.h>
#include <windowsx.h>
#include <QDebug>
#include <QTimer>
MyDialog::MyDialog(QWidget *parent)
    : QDialog(parent)
{
    setStyleSheet("QDialog{background-color: red}");
}

MyDialog::~MyDialog()
{

}

bool MyDialog::nativeEvent(const QByteArray & eventType, void * message, long * result)
{
    MSG* msg = (MSG*)(message);
    if (msg->message == WM_NCLBUTTONDOWN)
    {
        if (isMinimized())
        {
            QTimer::singleShot(50, this, SLOT(showNormal()));
            *result = 0;
            return true;
        }
        else
        {
            int mouseX = GET_X_LPARAM(msg->lParam);
            int mouseY = GET_Y_LPARAM(msg->lParam);

            QRect frame = frameGeometry();
            QRect content = geometry();

            qDebug() << "frame: " << frame;
            qDebug() << "content: " << content;

            if (mouseY < content.y() && mouseY >= frame.y())
            {
                qDebug() << "Hit title bar";
                showMinimized();
            }
        }
    }

    *result = 0;
    return false;
}

MyWindow::MyWindow()
    :QMainWindow()
{
    setStyleSheet("QMainWindow{background-color: blue}");
    showMaximized();
    m_dialog = new MyDialog(this);
    m_dialog->showMinimized();
}

MyWindow::~MyWindow()
{
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM