如何未最大化然后拖动并调整窗口Qt的大小

时间:2019-01-20 11:05:11

标签: c++ qt

我需要最大化设置,然后在单击并移动光标时拖动标题栏 我的代码:

void mousePressEvent(QMouseEvent* event){
        pos_x = event->x();
        pos_y = event->y();
            if(pos_y < 30){
                if(isMaximized()){
                    isMaximizeforfunction = true;
                    max_width = window()->width();
                }else{
                    isMaximizeforfunction = false;
                }
                isMoving= true;
            }
    }
    void mouseMoveEvent(QMouseEvent* event){
        if(isMoving){
            if(isMaximizeforfunction){
                if(isMaximized()){
                    showNormal();
                }
                if(pos_x > ((max_width / 2) + (window()->width() / 2) + (max_width / 4)) && pos_x < max_width){
                    move(event->globalX() + ((max_width / 2) + (window()->width() / 2)) - pos_x, event->globalY() - pos_y);
                }else{
                    move(event->globalX() - pos_x, event->globalY() - pos_y);
                }
            }else{
                move(event->globalX() - pos_x, event->globalY() - pos_y);
            }
        }
    }
    void mouseReleaseEvent(QMouseEvent* /*event*/){
            isMoving= false;
    }
    void mouseDoubleClickEvent(QMouseEvent* /*event*/){
        maximized_unmaximized();
    }

private:
    int pos_x;
    int pos_y;
    bool isMoving{false};
    bool isMaximizeforfunction{false};
    int max_width;

当我按下标题栏的中间时,我的代码有问题,就像真实的Windows标题栏一样,我的光标和窗口之间有间隙。

0 个答案:

没有答案