QT5 无边框Widget和自定义程序启动画面
2017-04-19 15:51
295 查看
一、简介
模仿QQ设置面板,自定义Widget,并实现了窗体的拖拽,关闭,最小化功能。
二、详解
1、模仿QQ系统设置的无边框界面
(1)代码mainwidget.h:
#ifndef MAINWIDGET_H #define MAINWIDGET_H #include <QWidget> #include <TPPPushButton.h> class MainWidget : public QWidget { Q_OBJECT public: MainWidget(QWidget *parent = 0); ~MainWidget(); protected: void paintEvent(QPaintEvent *event); void resizeEvent(QResizeEvent *event); private: TPPPushButton *minButton; TPPPushButton *closeButton; QRect rectMove; }; #endif // MAINWIDGET_H
mainwidget.cpp:
#include "mainwidget.h" MainWidget::MainWidget(QWidget *parent) : QWidget(parent, Qt::FramelessWindowHint) { resize(700, 500); rectMove = QRect(0, 0, width(), 35); minButton = new TPPPushButton(this); minButton->setPicName(":/titleButtons/min"); minButton->setToolTip(tr("minimize")); connect(minButton, SIGNAL(clicked()), this, SLOT(showMinimized())); closeButton = new TPPPushButton(this); closeButton->setPicName(":/titleButtons/close"); closeButton->setToolTip(tr("close")); connect(closeButton, SIGNAL(clicked()), this, SLOT(close())); } MainWidget::~MainWidget() { } void MainWidget::resizeEvent(QResizeEvent *event) { minButton->move(width() - 27 - closeButton->width(), 6); closeButton->move(width() - 27, 6); QWidget::resizeEvent(event); } void MainWidget::paintEvent(QPaintEvent *event) { QPainter painter(this); painter.setPen(Qt::NoPen); painter.setBrush(QColor("#F0F0F0")); painter.drawRect(this->rect()); painter.setBrush(QColor("#069dd5")); painter.drawRect(rectMove); painter.setPen(QColor("#D7D7D7")); painter.drawLine(0, 70, this->width(), 70); QWidget::paintEvent(event); }
三、总结
(1)相应的代码已上传到csdn http://download.csdn.net/detail/zuoyuexian/9819147 。(2)若有建议,请留言,在此先感谢!
相关文章推荐
- Qt5 程序启动画面图片效果
- Qt5_基本对话框之程序启动画面(QSplashScreen)
- 程序启动画面
- [开发] 四种程序启动画面的制作方法(VC)
- 用C#给程序加启动画面并只允许一个应用程序实例运行
- vc程序启动画面
- VB.Net程序设计:最简单的初始屏幕(程序启动画面)
- 用C#给程序加启动画面并只允许一个应用程序实例运行
- VC程序启动画面
- 在程序启动之前显示一个画面
- 四种程序启动画面的制作方法(VC)
- vc 程序启动画面
- 再谈程序启动画面的制作
- HOW TO:溅射屏幕(Splash Screen),也叫程序启动画面的制作(.NET2005)
- HOW TO:溅射屏幕(Splash Screen),也叫程序启动画面的制作(.NET2005)
- 给程序添加启动画面(C#.net )
- 四种程序启动画面的制作方法(VC)
- HOW TO:溅射屏幕(Splash Screen),也叫程序启动画面的制作(.NET2003)
- 四种程序启动画面的制作方法(VC)
- 程序启动画面的制作方法