Advertisement

MouseEvent

阅读量:

1、mousePressEvent事件

在头文件中定义布尔型变量 isLeftPressDown 用于记录状态,同时声明 QPoint 类型的变量 m_movePoint 用以存储坐标信息;
初始化操作将 isLeftPressDown 的初始值设置为 false;

复制代码
    void MusicWidget::mousePressEvent(QMouseEvent *event)
    {
    switch(event->button())
    {
        case Qt::LeftButton:
            isLeftPressDown = true;
    
            m_movePoint = event->globalPos() - this->frameGeometry().topLeft();
                //globalPos()鼠标全局位置,topLeft()窗口左上角的位置
            }
            break;
        case Qt::RightButton:
            this->setWindowState(Qt::WindowMinimized);
            break;
        default:

全部评论 (0)

还没有任何评论哟~