1 Star 4 Fork 5

clickto/Qt-FramelessWindow

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
DialogSample.cpp 2.92 KB
一键复制 编辑 原始数据 按行查看 历史
winsoft666 提交于 2020-05-28 18:05 . add new frameless sample
#include "DialogSample.h"
#include <QGraphicsDropShadowEffect>
DialogSample::DialogSample(QWidget* parent /*= nullptr*/)
: FramelessWindow<QDialog>(true, parent), shadow_(nullptr) {
setAttribute(Qt::WA_DeleteOnClose, true);
setupUi();
setWindowTitle("Dialog Sample");
setTitlebar({centralWidget_, labelTitle_});
loadStyleSheetFile(":/QtFramelessWindowSample/Resources/DialogSample.css", this);
setShadowEnable(true);
connect(pushButtonClose_, &QPushButton::clicked, [this]() { close(); });
}
DialogSample::~DialogSample() {}
void DialogSample::setupUi() {
this->setObjectName("SettingWnd");
centralWidget_ = new QWidget();
centralWidget_->setObjectName("centralWidget");
pushButtonClose_ = new QPushButton();
pushButtonClose_->setObjectName("pushButtonClose");
pushButtonClose_->setFixedSize(30, 30);
pushButtonClose_->setCursor(QCursor(Qt::PointingHandCursor));
labelSaveDir_ = new QLabel();
labelSaveDir_->setObjectName("labelWallpaperSaveDir");
labelSaveDir_->setText("Directory: ");
pushButtonSaveDir_ = new QPushButton();
pushButtonSaveDir_->setObjectName("pushButtonWallpaperSaveDir");
pushButtonSaveDir_->setText("C:\\Users\\JEFFERY\\AppData\\Local");
pushButtonSaveDir_->setCursor(QCursor(Qt::PointingHandCursor));
pushButtonSaveDir_->setToolTip(pushButtonSaveDir_->text());
pushButtonChangeSaveDir_ = new QPushButton();
pushButtonChangeSaveDir_->setObjectName("pushButtonChangeWallpaperSaveDir");
pushButtonChangeSaveDir_->setText("Update Directory");
pushButtonChangeSaveDir_->setFixedSize(150, 35);
pushButtonChangeSaveDir_->setCursor(QCursor(Qt::PointingHandCursor));
labelTitle_ = new QLabel();
labelTitle_->setObjectName("labelTitle");
labelTitle_->setText("Dialog Sample");
QHBoxLayout* hlTitle = new QHBoxLayout();
hlTitle->setContentsMargins(0, 0, 0, 0);
hlTitle->setSpacing(0);
hlTitle->addWidget(labelTitle_);
hlTitle->addStretch();
hlTitle->addWidget(pushButtonClose_);
QHBoxLayout* hlSD = new QHBoxLayout();
hlSD->setContentsMargins(0, 0, 0, 0);
hlSD->setSpacing(0);
hlSD->addWidget(labelSaveDir_);
hlSD->addWidget(pushButtonSaveDir_);
hlSD->addStretch();
QVBoxLayout* vLayout = new QVBoxLayout();
vLayout->setSpacing(20);
vLayout->setContentsMargins(20, 0, 10, 0);
vLayout->addLayout(hlTitle);
vLayout->addLayout(hlSD);
vLayout->addWidget(pushButtonChangeSaveDir_);
vLayout->addStretch();
centralWidget_->setLayout(vLayout);
QHBoxLayout* hMain = new QHBoxLayout();
hMain->setContentsMargins(0, 0, 0, 0);
hMain->addWidget(centralWidget_);
this->setLayout(hMain);
this->setContentsMargins(25, 25, 25, 25);
this->setMinimumSize(450, 350);
}
void DialogSample::setShadowEnable(bool enable) {
if (!shadow_) {
shadow_ = new QGraphicsDropShadowEffect();
shadow_->setColor(QColor(2, 122, 255, 255));
shadow_->setBlurRadius(20);
shadow_->setOffset(0.0);
}
centralWidget_->setGraphicsEffect(enable ? shadow_ : nullptr);
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/clickto/Qt-FramelessWindow.git
git@gitee.com:clickto/Qt-FramelessWindow.git
clickto
Qt-FramelessWindow
Qt-FramelessWindow
master

搜索帮助