资源简介

QT 自定义无边框窗体,支持边缘拖拽缩放。搬运自http://www.cnblogs.com/xufeiyang/p/3313104.html,稍改了些代码,供参考

资源截图

代码片段和文件信息

#include “dialog.h“
#include “ui_dialog.h“

Dialog::Dialog(QWidget *parent) :
    QDialog(parent)
    ui(new Ui::Dialog)
{
    ui->setupUi(this);

    isLeftPressDown = false;
    this->dir = NONE;
    this->setMinimumHeight(100);
    this->setMinimumWidth(150);
    this->setWindowFlags(Qt::framelessWindowHint|Qt::WindowSystemMenuHint );
    this->setMouseTracking(true);
    this->setstyleSheet(“QDialog{background:url(:/bg_main.png)}“);
}

Dialog::~Dialog()
{
    delete ui;
}
void Dialog::mouseReleaseEvent(QMouseEvent *event)
{
    if(event->button() == Qt::LeftButton) {
        isLeftPressDown = false;
        //if(dir != NONE) {
            this->releaseMouse();
            this->setCursor(QCursor(Qt::ArrowCursor));
        //}
    }
}

void Dialog::mousePressEvent(QMouseEvent *event)
{
    switch(event->button()) {
    case Qt::LeftButton:
        isLeftPressDown = true;
        if(dir != NONE) {
            this->mouseGrabber();
        } else {
            dragPosition = event->globalPos() - this->frameGeometry().topLeft();
        }
        break;
    case Qt::RightButton:
        this->close();
        break;
    default:
        QDialog::mousePressEvent(event);
    }
}

void Dialog::mouseMoveEvent(QMouseEvent *event)
{
    QPoint gloPoint = event->globalPos();
    QRect rect = this->rect();
    QPoint tl = mapToGlobal(rect.topLeft());
    QPoint rb = mapToGlobal(rect.bottomRight());

    if(!isLeftPressDown) {
        this->region(gloPoint);
    } else {

        if(dir != NONE) {
            QRect rMove(tl rb);

            switch(dir) {
            case LEFT:
                if(rb.x() - gloPoint.x() <= this->minimumWidth())
                    rMove.setX(tl.x());
                else
                    rMove.setX(gloPoint.x());
                break;
            case RIGHT:
                rMove.setWidth(gloPoint.x() - tl.x());
                break;
            case UP:
                if(rb.y() - gloPoint.y() <= this->minimumHeight())
                    rMove.setY(tl.y());
                else
                    rMove.setY(gloPoint.y());
                break;
            case DOWN:
                rMove.setHeight(gloPoint.y() - tl.y());
                break;
            case LEFTTOP:
                if(rb.x() - gloPoint.x() <= this->minimumWidth())
                    rMove.setX(tl.x());
                else
                    rMove.setX(gloPoint.x());
                if(rb.y() - gloPoint.y() <= this->minimumHeight())
                    rMove.setY(tl.y());
                else
                    rMove.setY(gloPoint.y());
                break;
            case RIGHTTOP:
                rMove.setWidth(gloPoint.x() - tl.x());
                if(rb.y() - gloPoint.y() <= this->minimumHeight())
                    rMove.setY(tl.y());
                else
                    rMove.setY(gloPoint.y());
                break;
       

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件    1034026  2013-02-25 13:58  Sizableframe\bg_main.png

     文件       5724  2016-04-20 15:37  Sizableframe\dialog.cpp

     文件        809  2013-09-10 16:57  Sizableframe\dialog.h

     文件        441  2013-09-10 13:53  Sizableframe\dialog.ui

     文件         90  2013-09-10 13:54  Sizableframe\image.qrc

     文件        179  2013-09-10 13:53  Sizableframe\main.cpp

     文件        413  2016-04-20 10:33  Sizableframe\Sizableframe.pro

     文件      34022  2016-04-20 16:49  Sizableframe\Sizableframe.pro.user

     文件      17738  2013-09-10 13:57  Sizableframe\Sizableframe.pro.user.3.0-pre1

     目录          0  2016-04-20 16:49  Sizableframe

----------- ---------  ---------- -----  ----

              1093442                    10


评论

共有 条评论