資源簡介
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??Sizablefr
?????文件???????5724??2016-04-20?15:37??Sizablefr
?????文件????????809??2013-09-10?16:57??Sizablefr
?????文件????????441??2013-09-10?13:53??Sizablefr
?????文件?????????90??2013-09-10?13:54??Sizablefr
?????文件????????179??2013-09-10?13:53??Sizablefr
?????文件????????413??2016-04-20?10:33??Sizablefr
?????文件??????34022??2016-04-20?16:49??Sizablefr
?????文件??????17738??2013-09-10?13:57??Sizablefr
?????目錄??????????0??2016-04-20?16:49??Sizablefr
-----------?---------??----------?-----??----
??????????????1093442????????????????????10
- 上一篇:Qt5-嵌入百度地圖
- 下一篇:Qt5使用百度地圖test
評論
共有 條評論