資源簡介
內容如標題,在QDialog上實現無邊框,圓角,陰影,可拖拽大小,移動位置.
具體界面樣式及實現細節參照我的同名博客文章.

代碼片段和文件信息
#include?“dialog.h“
#include?“ui_dialog.h“
#include?
#include?
#include?
Dialog::Dialog(QWidget?*parent)?:
????QDialog(parent)
????ui(new?Ui::Dialog)
{
????ui->setupUi(this);
????isLeftPressDown?=?false;
????dir?=?NONE;
????setMouseTracking(true);
????setWindowFlags(Qt::framelessWindowHint);//---gtj?無邊框
????setAttribute(Qt::WA_TranslucentBackground);//---gtj?設置窗口透明
????setSizeGripEnabled(true);//---gtj?右下角的小拖拽
????//---------gtj?陰影效果
????QGraphicsDropShadowEffect?*effect?=?new?QGraphicsDropShadowEffect;
????effect->setOffset(44);//產生陰影效果方向,如果dx為負數
????effect->setColor(QColor(00050));//陰影顏色
????effect->setBlurRadius(10);//設定陰影的模糊度
??????ui->widgetBg->setGraphicsEffect(effect);
}
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())
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件??????11608??2018-08-20?10:43??ui_dialog.h
?????文件????????123??2017-11-18?15:34??images\max.png
?????文件????????130??2017-11-18?15:34??images\min.png
?????文件????????168??2017-11-18?15:33??images\quit.png
?????文件????????537??2017-11-18?20:38??images\sereach.png
?????文件?????130046??2017-08-26?19:19??bg.jpg
?????文件???????5769??2018-08-20?10:42??dialog.cpp
?????文件????????915??2018-08-20?10:42??dialog.h
?????文件??????11668??2018-08-20?10:43??dialog.ui
?????文件????????234??2018-08-16?11:19??image.qrc
?????文件????????448??2018-08-16?10:22??Ji_Gui_RoundRectDialog.pro
?????文件????????179??2013-09-10?13:53??main.cpp
?????目錄??????????0??2018-08-16?11:19??images
-----------?---------??----------?-----??----
???????????????161825????????????????????13
- 上一篇:教學系統設計 復習重點 有它不愁?。?/a>
- 下一篇:CPU SPEC 2006
評論
共有 條評論