├── .gitattributes ├── .gitignore ├── ReadMe.txt ├── Simu360.pro ├── contentwidget.cpp ├── contentwidget.h ├── images ├── 1.png ├── 2.png ├── 3.png ├── 360AboutLogo.png ├── 4.png ├── 5.png ├── 6.png ├── 7.png ├── 8.png ├── 9.png ├── SkinButtom.png ├── frame.jpg ├── logo.png ├── sys_button_close.png ├── sys_button_max.png ├── sys_button_min.png ├── sys_button_restore.png └── title_bar_menu.png ├── main.cpp ├── mainframe.cpp ├── mainframe.h ├── mainframe.ui ├── mybtn.cpp ├── mybtn.h ├── res.qrc ├── statusbar.cpp ├── statusbar.h ├── titlebar.cpp ├── titlebar.h ├── toolbar.cpp └── toolbar.h /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | *.sln merge=union 7 | *.csproj merge=union 8 | *.vbproj merge=union 9 | *.fsproj merge=union 10 | *.dbproj merge=union 11 | 12 | # Standard to msysgit 13 | *.doc diff=astextplain 14 | *.DOC diff=astextplain 15 | *.docx diff=astextplain 16 | *.DOCX diff=astextplain 17 | *.dot diff=astextplain 18 | *.DOT diff=astextplain 19 | *.pdf diff=astextplain 20 | *.PDF diff=astextplain 21 | *.rtf diff=astextplain 22 | *.RTF diff=astextplain 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ################# 2 | ## Eclipse 3 | ################# 4 | 5 | *.pydevproject 6 | .project 7 | .metadata 8 | bin/ 9 | tmp/ 10 | *.tmp 11 | *.bak 12 | *.swp 13 | *~.nib 14 | local.properties 15 | .classpath 16 | .settings/ 17 | .loadpath 18 | 19 | # External tool builders 20 | .externalToolBuilders/ 21 | 22 | # Locally stored "Eclipse launch configurations" 23 | *.launch 24 | 25 | # CDT-specific 26 | .cproject 27 | 28 | # PDT-specific 29 | .buildpath 30 | 31 | 32 | ################# 33 | ## Visual Studio 34 | ################# 35 | 36 | ## Ignore Visual Studio temporary files, build results, and 37 | ## files generated by popular Visual Studio add-ons. 38 | 39 | # User-specific files 40 | *.suo 41 | *.user 42 | *.sln.docstates 43 | 44 | # Build results 45 | 46 | [Dd]ebug/ 47 | [Rr]elease/ 48 | x64/ 49 | build/ 50 | [Bb]in/ 51 | [Oo]bj/ 52 | 53 | # MSTest test Results 54 | [Tt]est[Rr]esult*/ 55 | [Bb]uild[Ll]og.* 56 | 57 | *_i.c 58 | *_p.c 59 | *.ilk 60 | *.meta 61 | *.obj 62 | *.pch 63 | *.pdb 64 | *.pgc 65 | *.pgd 66 | *.rsp 67 | *.sbr 68 | *.tlb 69 | *.tli 70 | *.tlh 71 | *.tmp 72 | *.tmp_proj 73 | *.log 74 | *.vspscc 75 | *.vssscc 76 | .builds 77 | *.pidb 78 | *.log 79 | *.scc 80 | 81 | # Visual C++ cache files 82 | ipch/ 83 | *.aps 84 | *.ncb 85 | *.opensdf 86 | *.sdf 87 | *.cachefile 88 | 89 | # Visual Studio profiler 90 | *.psess 91 | *.vsp 92 | *.vspx 93 | 94 | # Guidance Automation Toolkit 95 | *.gpState 96 | 97 | # ReSharper is a .NET coding add-in 98 | _ReSharper*/ 99 | *.[Rr]e[Ss]harper 100 | 101 | # TeamCity is a build add-in 102 | _TeamCity* 103 | 104 | # DotCover is a Code Coverage Tool 105 | *.dotCover 106 | 107 | # NCrunch 108 | *.ncrunch* 109 | .*crunch*.local.xml 110 | 111 | # Installshield output folder 112 | [Ee]xpress/ 113 | 114 | # DocProject is a documentation generator add-in 115 | DocProject/buildhelp/ 116 | DocProject/Help/*.HxT 117 | DocProject/Help/*.HxC 118 | DocProject/Help/*.hhc 119 | DocProject/Help/*.hhk 120 | DocProject/Help/*.hhp 121 | DocProject/Help/Html2 122 | DocProject/Help/html 123 | 124 | # Click-Once directory 125 | publish/ 126 | 127 | # Publish Web Output 128 | *.Publish.xml 129 | *.pubxml 130 | 131 | # NuGet Packages Directory 132 | ## TODO: If you have NuGet Package Restore enabled, uncomment the next line 133 | #packages/ 134 | 135 | # Windows Azure Build Output 136 | csx 137 | *.build.csdef 138 | 139 | # Windows Store app package directory 140 | AppPackages/ 141 | 142 | # Others 143 | sql/ 144 | *.Cache 145 | ClientBin/ 146 | [Ss]tyle[Cc]op.* 147 | ~$* 148 | *~ 149 | *.dbmdl 150 | *.[Pp]ublish.xml 151 | *.pfx 152 | *.publishsettings 153 | 154 | # RIA/Silverlight projects 155 | Generated_Code/ 156 | 157 | # Backup & report files from converting an old project file to a newer 158 | # Visual Studio version. Backup files are not needed, because we have git ;-) 159 | _UpgradeReport_Files/ 160 | Backup*/ 161 | UpgradeLog*.XML 162 | UpgradeLog*.htm 163 | 164 | # SQL Server files 165 | App_Data/*.mdf 166 | App_Data/*.ldf 167 | 168 | ############# 169 | ## Windows detritus 170 | ############# 171 | 172 | # Windows image file caches 173 | Thumbs.db 174 | ehthumbs.db 175 | 176 | # Folder config file 177 | Desktop.ini 178 | 179 | # Recycle Bin used on file shares 180 | $RECYCLE.BIN/ 181 | 182 | # Mac crap 183 | .DS_Store 184 | 185 | 186 | ############# 187 | ## Python 188 | ############# 189 | 190 | *.py[co] 191 | 192 | # Packages 193 | *.egg 194 | *.egg-info 195 | dist/ 196 | build/ 197 | eggs/ 198 | parts/ 199 | var/ 200 | sdist/ 201 | develop-eggs/ 202 | .installed.cfg 203 | 204 | # Installer logs 205 | pip-log.txt 206 | 207 | # Unit test / coverage reports 208 | .coverage 209 | .tox 210 | 211 | #Translations 212 | *.mo 213 | 214 | #Mr Developer 215 | .mr.developer.cfg 216 | -------------------------------------------------------------------------------- /ReadMe.txt: -------------------------------------------------------------------------------- 1 | 根据 http://www.cnblogs.com/appsucc/archive/2012/03/14/2395657.html 这篇文章来写的。 2 | 由于那文章里,作者只是给出了只要代码片段,对于qt初学者,可能并不能够真正运行起来。 3 | 这个项目就是让作者的代码完整的运行起来。 4 | -------------------------------------------------------------------------------- /Simu360.pro: -------------------------------------------------------------------------------- 1 | #------------------------------------------------- 2 | # 3 | # Project created by QtCreator 2013-05-29T09:45:54 4 | # 5 | #------------------------------------------------- 6 | 7 | QT += core gui 8 | 9 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 10 | 11 | TARGET = Simu360 12 | TEMPLATE = app 13 | 14 | 15 | SOURCES += main.cpp\ 16 | titlebar.cpp \ 17 | toolbar.cpp \ 18 | contentwidget.cpp \ 19 | statusbar.cpp \ 20 | mainframe.cpp \ 21 | mybtn.cpp 22 | 23 | HEADERS += \ 24 | titlebar.h \ 25 | toolbar.h \ 26 | contentwidget.h \ 27 | statusbar.h \ 28 | mainframe.h \ 29 | mybtn.h 30 | 31 | FORMS += \ 32 | mainframe.ui 33 | 34 | RESOURCES += \ 35 | res.qrc 36 | -------------------------------------------------------------------------------- /contentwidget.cpp: -------------------------------------------------------------------------------- 1 | #include "contentwidget.h" 2 | 3 | ContentWidget::ContentWidget(QWidget *parent) : 4 | QWidget(parent) 5 | { 6 | this->setFixedHeight(50); 7 | m_pLabel = new QLabel(); 8 | m_pLabel->setText(tr("text lalala")); 9 | m_pLayout = new QVBoxLayout(this); 10 | m_pLayout->addWidget(m_pLabel); 11 | this->setLayout(m_pLayout); 12 | m_pLabel->setStyleSheet(""); 13 | } 14 | -------------------------------------------------------------------------------- /contentwidget.h: -------------------------------------------------------------------------------- 1 | #ifndef CONTENTWIDGET_H 2 | #define CONTENTWIDGET_H 3 | 4 | #include 5 | #include 6 | 7 | class ContentWidget : public QWidget 8 | { 9 | Q_OBJECT 10 | public: 11 | explicit ContentWidget(QWidget *parent = 0); 12 | 13 | signals: 14 | 15 | public slots: 16 | private: 17 | QLabel *m_pLabel; 18 | QVBoxLayout* m_pLayout; 19 | }; 20 | 21 | #endif // CONTENTWIDGET_H 22 | -------------------------------------------------------------------------------- /images/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devbian/qt_simu360/c77099a05a95281ee6e111215a92ae569d094942/images/1.png -------------------------------------------------------------------------------- /images/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devbian/qt_simu360/c77099a05a95281ee6e111215a92ae569d094942/images/2.png -------------------------------------------------------------------------------- /images/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devbian/qt_simu360/c77099a05a95281ee6e111215a92ae569d094942/images/3.png -------------------------------------------------------------------------------- /images/360AboutLogo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devbian/qt_simu360/c77099a05a95281ee6e111215a92ae569d094942/images/360AboutLogo.png -------------------------------------------------------------------------------- /images/4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devbian/qt_simu360/c77099a05a95281ee6e111215a92ae569d094942/images/4.png -------------------------------------------------------------------------------- /images/5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devbian/qt_simu360/c77099a05a95281ee6e111215a92ae569d094942/images/5.png -------------------------------------------------------------------------------- /images/6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devbian/qt_simu360/c77099a05a95281ee6e111215a92ae569d094942/images/6.png -------------------------------------------------------------------------------- /images/7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devbian/qt_simu360/c77099a05a95281ee6e111215a92ae569d094942/images/7.png -------------------------------------------------------------------------------- /images/8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devbian/qt_simu360/c77099a05a95281ee6e111215a92ae569d094942/images/8.png -------------------------------------------------------------------------------- /images/9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devbian/qt_simu360/c77099a05a95281ee6e111215a92ae569d094942/images/9.png -------------------------------------------------------------------------------- /images/SkinButtom.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devbian/qt_simu360/c77099a05a95281ee6e111215a92ae569d094942/images/SkinButtom.png -------------------------------------------------------------------------------- /images/frame.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devbian/qt_simu360/c77099a05a95281ee6e111215a92ae569d094942/images/frame.jpg -------------------------------------------------------------------------------- /images/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devbian/qt_simu360/c77099a05a95281ee6e111215a92ae569d094942/images/logo.png -------------------------------------------------------------------------------- /images/sys_button_close.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devbian/qt_simu360/c77099a05a95281ee6e111215a92ae569d094942/images/sys_button_close.png -------------------------------------------------------------------------------- /images/sys_button_max.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devbian/qt_simu360/c77099a05a95281ee6e111215a92ae569d094942/images/sys_button_max.png -------------------------------------------------------------------------------- /images/sys_button_min.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devbian/qt_simu360/c77099a05a95281ee6e111215a92ae569d094942/images/sys_button_min.png -------------------------------------------------------------------------------- /images/sys_button_restore.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devbian/qt_simu360/c77099a05a95281ee6e111215a92ae569d094942/images/sys_button_restore.png -------------------------------------------------------------------------------- /images/title_bar_menu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devbian/qt_simu360/c77099a05a95281ee6e111215a92ae569d094942/images/title_bar_menu.png -------------------------------------------------------------------------------- /main.cpp: -------------------------------------------------------------------------------- 1 | #include "mainframe.h" 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | QApplication a(argc, argv); 7 | MainFrame w; 8 | w.show(); 9 | return a.exec(); 10 | } 11 | -------------------------------------------------------------------------------- /mainframe.cpp: -------------------------------------------------------------------------------- 1 | #include "mainframe.h" 2 | #include "ui_mainframe.h" 3 | 4 | MainFrame::MainFrame(QWidget *parent) : 5 | QFrame(parent), 6 | ui(new Ui::MainFrame) 7 | { 8 | 9 | ui->setupUi(this); 10 | initWindow(); 11 | setWindowCircle(); 12 | connectEvent(); 13 | } 14 | 15 | void MainFrame::initWindow() 16 | { 17 | this->setWindowFlags(Qt::FramelessWindowHint); 18 | m_pContentWidget = new ContentWidget(this); 19 | m_pStatusBar = new StatusBar(this); 20 | m_pTitleBar = new TitleBar(this); 21 | m_pToolBar = new ToolBar(this); 22 | m_pMainLayout = new QVBoxLayout(this); 23 | m_pMainLayout->addWidget(m_pTitleBar); 24 | m_pMainLayout->addWidget(m_pToolBar); 25 | m_pMainLayout->addWidget(m_pContentWidget); 26 | m_pMainLayout->addWidget(m_pStatusBar); 27 | m_pMainLayout->setSpacing(0); 28 | m_pMainLayout->setContentsMargins(0,0,0,0); 29 | 30 | this->setStyleSheet("QFrame#MainFrame {border-image:url(:/res/images/frame.jpg); border:1px solid black;}"); 31 | 32 | this->setMouseTracking(true); 33 | m_bLeftBtnPress = false; 34 | setMinimumWidth(850); 35 | setMinimumHeight(600); 36 | m_bMaxWin = false; 37 | 38 | this->m_pTitleBar->setMouseTracking(true); 39 | this->m_pContentWidget->setMouseTracking(true); 40 | m_bLeftBtnPress = false; 41 | } 42 | 43 | void MainFrame::setWindowCircle() 44 | { 45 | //生成一张位图 46 | QBitmap objBitmap(size()); 47 | //QPainter用于在位图上绘画 48 | QPainter painter(&objBitmap); 49 | //填充位图矩形框(用白色填充) 50 | painter.fillRect(rect(),Qt::white); 51 | painter.setBrush(QColor(0,0,0)); 52 | //在位图上画圆角矩形(用黑色填充) 53 | painter.drawRoundedRect(this->rect(),10,10); 54 | //使用setmask过滤即可 55 | setMask(objBitmap); 56 | } 57 | 58 | MainFrame::~MainFrame() 59 | { 60 | delete ui; 61 | } 62 | 63 | void MainFrame::connectEvent() 64 | { 65 | connect(this->m_pTitleBar, SIGNAL(signal_close()), this, SLOT(close())); 66 | } 67 | 68 | void MainFrame::paintEvent(QPaintEvent *event) 69 | { 70 | setWindowCircle(); 71 | } 72 | 73 | 74 | void MainFrame::mousePressEvent(QMouseEvent *event) 75 | { 76 | if (event->button() == Qt::LeftButton) 77 | { 78 | m_ptPressGlobal = event->globalPos(); 79 | m_bLeftBtnPress = true; 80 | } 81 | } 82 | 83 | void MainFrame::mouseMoveEvent(QMouseEvent *event) 84 | { 85 | if(!m_bLeftBtnPress) 86 | { 87 | m_eDirection = PointValid(event->x(),event->y()); 88 | SetCursorStyle(m_eDirection); 89 | } 90 | else 91 | { 92 | int nXGlobal = event->globalX(); 93 | int nYGlobal = event->globalY(); 94 | SetDrayMove(nXGlobal,nYGlobal,m_eDirection); 95 | m_ptPressGlobal =QPoint(nXGlobal,nYGlobal); 96 | } 97 | } 98 | 99 | void MainFrame::mouseReleaseEvent(QMouseEvent *event) 100 | { 101 | if (event->button() == Qt::LeftButton) 102 | { 103 | m_bLeftBtnPress = false; 104 | m_eDirection = eNone; 105 | } 106 | } 107 | 108 | void MainFrame::mouseDoubleClickEvent(QMouseEvent *event) 109 | { 110 | if (event->button() == Qt::LeftButton && event->y() <= m_pTitleBar->height()) 111 | { 112 | if(!m_bMaxWin) 113 | { 114 | m_rectRestoreWindow = geometry(); 115 | setGeometry(qApp->desktop()->availableGeometry()); 116 | } 117 | else 118 | { 119 | setGeometry(m_rectRestoreWindow); 120 | } 121 | m_bMaxWin = !m_bMaxWin; 122 | } 123 | } 124 | 125 | //确定点的位置方向 126 | MainFrame::enum_Direction MainFrame::PointValid(int nXRelative,int nYRelative) 127 | { 128 | int nTop = qAbs(nYRelative) 5 | #include "contentwidget.h" 6 | #include "statusbar.h" 7 | #include "titlebar.h" 8 | #include "toolbar.h" 9 | #include 10 | 11 | namespace Ui { 12 | class MainFrame; 13 | } 14 | 15 | class MainFrame : public QFrame 16 | { 17 | Q_OBJECT 18 | 19 | public: 20 | explicit MainFrame(QWidget *parent = 0); 21 | ~MainFrame(); 22 | void connectEvent(); 23 | 24 | enum enum_Direction 25 | { 26 | eNone, 27 | eTop = 1, 28 | eRight =2 , 29 | eBottom =4, 30 | eLeft = 8, 31 | eTopRight = eTop + eRight, 32 | eRightBottom = eRight + eBottom, 33 | eBottomLeft = eBottom + eLeft, 34 | eLeftTop = eLeft + eTop 35 | }; 36 | 37 | void paintEvent(QPaintEvent *); 38 | // static MainFrame *Instance(); 39 | // static MainFrame *mainFrameInstance; 40 | 41 | protected: 42 | virtual void mousePressEvent(QMouseEvent *); 43 | virtual void mouseReleaseEvent(QMouseEvent *); 44 | virtual void mouseMoveEvent(QMouseEvent *); 45 | virtual void mouseDoubleClickEvent(QMouseEvent *event); 46 | private: 47 | void initWindow(); 48 | void setWindowCircle(); 49 | void SetCursorStyle(enum_Direction direction); 50 | void SetDrayMove(int nXGlobal,int nYGlobal,enum_Direction direction); 51 | enum_Direction PointValid(int nXRelative,int nYRelative); 52 | Ui::MainFrame *ui; 53 | TitleBar *m_pTitleBar; 54 | ContentWidget *m_pContentWidget; 55 | ToolBar *m_pToolBar; 56 | StatusBar *m_pStatusBar; 57 | QVBoxLayout *m_pMainLayout; 58 | enum_Direction m_eDirection; 59 | QPoint m_ptPressGlobal; 60 | bool m_bLeftBtnPress; 61 | bool m_bMaxWin; 62 | QRect m_rectRestoreWindow; 63 | }; 64 | 65 | #endif // MAINFRAME_H 66 | -------------------------------------------------------------------------------- /mainframe.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | MainFrame 4 | 5 | 6 | 7 | 0 8 | 0 9 | 400 10 | 300 11 | 12 | 13 | 14 | Frame 15 | 16 | 17 | QFrame::StyledPanel 18 | 19 | 20 | QFrame::Raised 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /mybtn.cpp: -------------------------------------------------------------------------------- 1 | #include "mybtn.h" 2 | const int TOOLICON_WH=48; 3 | const int TOOLWIDGET_W=70; 4 | const int TOOLWIDGET_H=80; 5 | MyBtn::MyBtn(const QString &strImage,const QString &strInfo,QWidget *parent): 6 | QToolButton(parent), 7 | m_bOver(false), 8 | m_bPress(false), 9 | m_strImage(strImage), 10 | m_strInfo(strInfo) 11 | { 12 | //文本颜色 13 | QPalette objPalette = palette(); 14 | objPalette.setColor(QPalette::ButtonText, QColor(220,220,220)); 15 | setPalette(objPalette); 16 | //文本粗体 17 | QFont &objFont = const_cast(font()); 18 | objFont.setWeight(QFont::Bold); 19 | //样式 20 | setStyleSheet("QToolButton{border:0px;}"); 21 | //大小 22 | setIconSize(QSize(TOOLICON_WH,TOOLICON_WH)); 23 | resize(TOOLWIDGET_W,TOOLWIDGET_H); 24 | setToolButtonStyle(Qt::ToolButtonTextUnderIcon); 25 | //设置图像文本 26 | setIcon(QPixmap(strImage)); 27 | setText(strInfo); 28 | //连接press信号槽,表示按钮按下时 29 | connect(this,SIGNAL(pressed()),this,SLOT(slot_pressed())); 30 | 31 | } 32 | 33 | 34 | //enterEvent--鼠标移到按钮上事件 35 | void MyBtn::enterEvent(QEvent *event) 36 | { 37 | SetOver(true); 38 | } 39 | //leaveEvent--鼠标离开按钮事件 40 | void MyBtn::leaveEvent(QEvent *event) 41 | { 42 | SetOver(false); 43 | } 44 | //SetOver 45 | void MyBtn::SetOver(bool bEnable) 46 | { 47 | if(bEnable!=m_bOver) 48 | { 49 | //设置m_bOver标志位 50 | m_bOver = bEnable; 51 | //更新 52 | update(); 53 | } 54 | } 55 | 56 | //slot_pressed--槽函数 57 | void MyBtn::slot_pressed() 58 | { 59 | SetPress(true); 60 | emit signal_parent(this); 61 | } 62 | 63 | //SetPress 64 | void MyBtn::SetPress(bool bEnable) 65 | { 66 | if(bEnable!=m_bPress) 67 | { 68 | //设置m_bOver标志位 69 | m_bPress = bEnable; 70 | //更新 71 | update(); 72 | } 73 | } 74 | 75 | //重绘事件 76 | void MyBtn::paintEvent(QPaintEvent *event) 77 | { 78 | QPainter painter(this); 79 | //如果按钮被按下 80 | if(m_bPress) 81 | { 82 | //绘制被按下时的效果 83 | painterinfo(150,200,&painter); 84 | } 85 | else if(m_bOver)//如果按钮没有被按下并且鼠标移到按钮上 86 | { 87 | //绘制鼠标移到按钮上的按钮效果 88 | painterinfo(50,100,&painter); 89 | } 90 | //调用基类的重绘事件以显示图像文本等 91 | QToolButton::paintEvent(event); 92 | } 93 | //绘制背景渐变 94 | void MyBtn::painterinfo(int nTopPartOpacity,int nBottomPartOpacity,QPainter *pPainter) 95 | { 96 | //设置画笔 97 | QPen objPen(Qt::NoBrush,1); 98 | pPainter->setPen(objPen); 99 | //设置渐变画刷 100 | QLinearGradient objLinear(rect().topLeft(),rect().bottomLeft()); 101 | //顶部颜色和透明度 102 | objLinear.setColorAt(0,QColor(150,150,150,nTopPartOpacity)); 103 | //中间颜色和透明度 104 | objLinear.setColorAt(0.5,QColor(50,50,50,255)); 105 | //底部颜色和透明度 106 | objLinear.setColorAt(1,QColor(100,100,100,nBottomPartOpacity)); 107 | QBrush objBrush(objLinear); 108 | pPainter->setBrush(objBrush); 109 | //画圆角矩形 110 | pPainter->drawRoundedRect(rect(),5,5); 111 | } 112 | -------------------------------------------------------------------------------- /mybtn.h: -------------------------------------------------------------------------------- 1 | #ifndef MYBTN_H 2 | #define MYBTN_H 3 | 4 | #include 5 | #include 6 | 7 | class MyBtn : public QToolButton 8 | { 9 | Q_OBJECT 10 | public: 11 | explicit MyBtn(const QString &strImage,const QString &strInfo,QWidget *parent); 12 | void enterEvent(QEvent *event); 13 | void leaveEvent(QEvent *event); 14 | void SetOver(bool bEnable); 15 | void SetPress(bool bEnable); 16 | void paintEvent(QPaintEvent *event); 17 | void painterinfo(int nTopPartOpacity,int nBottomPartOpacity,QPainter *pPainter); 18 | signals: 19 | void signal_parent(MyBtn *); 20 | public slots: 21 | void slot_pressed(); 22 | private: 23 | bool m_bOver, m_bPress; 24 | QString m_strImage, m_strInfo; 25 | }; 26 | 27 | #endif // MYBTN_H 28 | -------------------------------------------------------------------------------- /res.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | images/frame.jpg 4 | images/1.png 5 | images/2.png 6 | images/3.png 7 | images/4.png 8 | images/5.png 9 | images/6.png 10 | images/7.png 11 | images/8.png 12 | images/9.png 13 | images/logo.png 14 | images/360AboutLogo.png 15 | images/SkinButtom.png 16 | images/sys_button_close.png 17 | images/sys_button_max.png 18 | images/sys_button_min.png 19 | images/sys_button_restore.png 20 | images/title_bar_menu.png 21 | 22 | 23 | -------------------------------------------------------------------------------- /statusbar.cpp: -------------------------------------------------------------------------------- 1 | #include "statusbar.h" 2 | 3 | StatusBar::StatusBar(QWidget *parent) : 4 | QWidget(parent) 5 | { 6 | } 7 | -------------------------------------------------------------------------------- /statusbar.h: -------------------------------------------------------------------------------- 1 | #ifndef STATUSBAR_H 2 | #define STATUSBAR_H 3 | 4 | #include 5 | 6 | class StatusBar : public QWidget 7 | { 8 | Q_OBJECT 9 | public: 10 | explicit StatusBar(QWidget *parent = 0); 11 | 12 | signals: 13 | 14 | public slots: 15 | 16 | }; 17 | 18 | #endif // STATUSBAR_H 19 | -------------------------------------------------------------------------------- /titlebar.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "titlebar.h" 3 | #include "mainframe.h" 4 | 5 | const int TITLE_H=32; 6 | TitleBar::TitleBar(QWidget *parent) : 7 | QWidget(parent) 8 | { 9 | this->setFixedHeight(32); 10 | CreateWidget(); 11 | CreateLayout(); 12 | SetWidgetStyle(); 13 | m_bLeftButtonPressed = false; 14 | } 15 | 16 | void TitleBar::mousePressEvent(QMouseEvent *event) 17 | { 18 | if(event->button() == Qt::LeftButton) 19 | { 20 | if(event->y()x()x() < VALUE_DIS) 21 | { 22 | event->ignore(); 23 | return; 24 | } 25 | 26 | m_ptPress = event->globalPos(); 27 | m_bLeftButtonPressed = true; 28 | } 29 | event->ignore(); 30 | } 31 | void TitleBar::mouseMoveEvent(QMouseEvent *event) 32 | { 33 | if(m_bLeftButtonPressed) 34 | { 35 | m_ptMove = event->globalPos(); 36 | MainFrame *pMainFrame = (qobject_cast(parent())); 37 | pMainFrame->move(pMainFrame->pos() + m_ptMove - m_ptPress); 38 | m_ptPress = m_ptMove; 39 | } 40 | event->ignore(); 41 | } 42 | void TitleBar::mouseReleaseEvent(QMouseEvent *event) 43 | { 44 | if(event->button() == Qt::LeftButton) 45 | { 46 | m_bLeftButtonPressed = false; 47 | } 48 | event->ignore(); 49 | } 50 | 51 | //创建子部件 52 | void TitleBar::CreateWidget() 53 | { 54 | //图像标签--logo 55 | m_pLabelIcon = new QLabel(this); 56 | QPixmap objPixmap(":/res/images/360AboutLogo.png"); 57 | m_pLabelIcon->setPixmap(objPixmap.scaled(TITLE_H,TITLE_H)); 58 | //文本标签--标题 59 | m_pLabelTitle = new QLabel(this); 60 | m_pLabelTitle->setText(QString("360 Safe Guard V8.5")); 61 | //文本标签--样式版本 62 | m_pLabelVersion = new QLabel(this); 63 | m_pLabelVersion->setText(QString("Use Class Style")); 64 | //设置鼠标形状 65 | m_pLabelVersion->setCursor(Qt::PointingHandCursor); 66 | //按钮--更换皮肤 67 | m_pBtnSkin = new QToolButton(this); 68 | //设置初始图片 69 | SetBtnIcon(m_pBtnSkin,eBtnStateDefault,true); 70 | //按钮--菜单 71 | m_pBtnMenu = new QToolButton(this); 72 | SetBtnIcon(m_pBtnMenu,eBtnStateDefault,true); 73 | //按钮--最小化 74 | m_pBtnMin = new QToolButton(this); 75 | SetBtnIcon(m_pBtnMin,eBtnStateDefault,true); 76 | //按钮--最大化/还原 77 | m_pBtnMax = new QToolButton(this); 78 | SetBtnIcon(m_pBtnMax,eBtnStateDefault,true); 79 | //按钮--关闭 80 | m_pBtnClose = new QToolButton(this); 81 | SetBtnIcon(m_pBtnClose,eBtnStateDefault,true); 82 | 83 | //获得子部件 84 | const QObjectList &objList = children(); 85 | for(int nIndex=0; nIndex < objList.count(); ++nIndex) 86 | { 87 | //设置子部件的MouseTracking属性 88 | ((QWidget*)(objList.at(nIndex)))->setMouseTracking(true); 89 | //如果是QToolButton部件 90 | if(0==qstrcmp(objList.at(nIndex)->metaObject()->className(),"QToolButton")) 91 | { 92 | //连接pressed信号为slot_btnpress 93 | connect(((QToolButton*)(objList.at(nIndex))),SIGNAL(pressed()),this,SLOT(slot_btnpress())); 94 | //连接clicked信号为slot_btnclick 95 | connect(((QToolButton*)(objList.at(nIndex))),SIGNAL(clicked()),this,SLOT(slot_btnclick())); 96 | 97 | // connect(((QToolButton*)(objList.at(nIndex))),SIGNAL(enterEvent()),this,SLOT(slot_btnclick())); 98 | //设置顶部间距 99 | ((QToolButton*)(objList.at(nIndex)))->setContentsMargins(0,VALUE_DIS,0,0); 100 | } 101 | } 102 | } 103 | 104 | //设置子部件样式(qss) 105 | void TitleBar::SetWidgetStyle() 106 | { 107 | //设置标签的文本颜色,大小等以及按钮的边框 108 | setStyleSheet("QLabel{color:#CCCCCC;font-size:12px;font-weight:bold;border:0px;} QToolButton{border:0px;}"); 109 | //设置左边距 110 | m_pLabelTitle->setStyleSheet("margin-left:6px;"); 111 | //设置右边距以及鼠标移上去时的文本颜色 112 | m_pLabelVersion->setStyleSheet("QLabel{margin-right:10px;}QLabel:hover{color:#00AA00;}"); 113 | } 114 | 115 | //创建设置布局 116 | void TitleBar::CreateLayout() 117 | { 118 | //水平布局 119 | m_pLayout = new QHBoxLayout(this); 120 | //添加部件 121 | m_pLayout->addWidget(m_pLabelIcon); 122 | m_pLayout->addWidget(m_pLabelTitle); 123 | //添加伸缩项 124 | m_pLayout->addStretch(1); 125 | //添加部件 126 | m_pLayout->addWidget(m_pLabelVersion); 127 | m_pLayout->addWidget(m_pBtnSkin); 128 | m_pLayout->addWidget(m_pBtnMenu); 129 | m_pLayout->addWidget(m_pBtnMin); 130 | m_pLayout->addWidget(m_pBtnMax); 131 | m_pLayout->addWidget(m_pBtnClose); 132 | //设置Margin 133 | m_pLayout->setContentsMargins(0,0,VALUE_DIS,0); 134 | //设置部件之间的space 135 | m_pLayout->setSpacing(0); 136 | setLayout(m_pLayout); 137 | } 138 | 139 | //设置按钮不同状态下的图标 140 | void TitleBar::SetBtnIcon(QToolButton *pBtn,eBtnMoustState state,bool bInit/*=false*/) 141 | { 142 | //获得图片路径 143 | QString strImagePath = GetBtnImagePath(pBtn,bInit); 144 | //创建QPixmap对象 145 | QPixmap objPixmap(strImagePath); 146 | //得到图像宽和高 147 | int nPixWidth = objPixmap.width(); 148 | int nPixHeight = objPixmap.height(); 149 | //如果状态不是无效值 150 | if(state!=eBtnStateNone) 151 | { 152 | if(pBtn == m_pBtnSkin) 153 | { 154 | pBtn->setIcon(objPixmap.copy((nPixWidth/3)*(state-1),0,nPixWidth/3,nPixHeight)); 155 | //设置按钮图片大小 156 | pBtn->setIconSize(QSize(nPixWidth/3,nPixHeight)); 157 | }else 158 | { 159 | /*设置按钮图片 160 | 按钮的图片是连续在一起的,如前1/4部分表示默认状态下的图片部分,接后的1/4部分表示鼠标移到按钮状态下的图片部分 161 | */ 162 | pBtn->setIcon(objPixmap.copy((nPixWidth/4)*(state-1),0,nPixWidth/4,nPixHeight)); 163 | //设置按钮图片大小 164 | pBtn->setIconSize(QSize(nPixWidth/4,nPixHeight)); 165 | } 166 | } 167 | } 168 | 169 | //获得图片路径(固定值) 170 | const QString TitleBar::GetBtnImagePath(QToolButton *pBtn,bool bInit/*=false*/) 171 | { 172 | QString strImagePath; 173 | //皮肤按钮 174 | if(m_pBtnSkin==pBtn) 175 | { 176 | strImagePath = ":/res/images/SkinButtom.png"; 177 | } 178 | //菜单按钮 179 | if(m_pBtnMenu==pBtn) 180 | { 181 | strImagePath = ":/res/images/title_bar_menu.png"; 182 | } 183 | //最小化 184 | if(m_pBtnMin==pBtn) 185 | { 186 | strImagePath = ":/res/images/sys_button_min.png"; 187 | } 188 | //最大化/还原按钮,所以包括最大化和还原两张图片 189 | if(m_pBtnMax==pBtn) 190 | { 191 | //如果是初始设置或者主界面的最大化标志不为真(其中MainWindow::Instance()使用单例设计模式) 192 | // if(bInit==true || MainFrame::Instance()->GetMaxWin()==false) 193 | if(bInit == true) 194 | { 195 | //最大化按钮图片路径 196 | strImagePath = ":/res/images/sys_button_max.png"; 197 | } 198 | else 199 | { 200 | //还原按钮图片路径 201 | strImagePath = ":/res/images/sys_button_restore.png"; 202 | } 203 | } 204 | //关闭按钮 205 | if(m_pBtnClose==pBtn) 206 | { 207 | strImagePath = ":/res/images/sys_button_close.png"; 208 | } 209 | return strImagePath; 210 | } 211 | 212 | //创建事件过滤器 213 | void TitleBar::CreateEventFiter() 214 | { 215 | m_pBtnSkin->installEventFilter(this); 216 | m_pBtnMenu->installEventFilter(this); 217 | m_pBtnMin->installEventFilter(this); 218 | m_pBtnMax->installEventFilter(this); 219 | m_pBtnClose->installEventFilter(this); 220 | } 221 | 222 | //事件过滤 223 | bool TitleBar::eventFilter(QObject *obj, QEvent *event) 224 | { 225 | //按钮状态 226 | eBtnMoustState eState = eBtnStateNone; 227 | //判断事件类型--QEvent::Enter 228 | if (event->type() == QEvent::Enter) 229 | { 230 | eState = eBtnStateHover; 231 | } 232 | //判断事件类型--QEvent::Leave 233 | if (event->type() == QEvent::Leave) 234 | { 235 | eState = eBtnStateDefault; 236 | } 237 | //判断事件类型--QEvent::MouseButtonPress 238 | if (event->type() == QEvent::MouseButtonPress && ((QMouseEvent*)(event))->button()== Qt::LeftButton) 239 | { 240 | eState = eBtnStatePress; 241 | } 242 | //判断目标 243 | if(m_pBtnSkin==obj || m_pBtnMenu==obj || m_pBtnMin==obj || m_pBtnMax==obj || m_pBtnClose==obj) 244 | { 245 | //如果状态有效 246 | if(eState != eBtnStateNone) 247 | { 248 | //根据状态设置按钮图标 249 | SetBtnIcon((QToolButton *)obj,eState, false); 250 | return false; 251 | } 252 | } 253 | return QWidget::eventFilter(obj,event); 254 | } 255 | 256 | 257 | //槽函数--slot_btnclick 258 | void TitleBar::slot_btnclick() 259 | { 260 | QToolButton *pBtn = (QToolButton*)(sender()); 261 | if(pBtn==m_pBtnMin) 262 | { 263 | emit signal_min(); 264 | } 265 | if(pBtn==m_pBtnMax) 266 | { 267 | emit signal_maxrestore(); 268 | } 269 | if(pBtn==m_pBtnClose) 270 | { 271 | emit signal_close(); 272 | } 273 | } 274 | 275 | void TitleBar::slot_btnpress() 276 | { 277 | QToolButton *pBtn = (QToolButton*)(sender()); 278 | SetBtnIcon(pBtn, eBtnStatePress, false); 279 | } 280 | -------------------------------------------------------------------------------- /titlebar.h: -------------------------------------------------------------------------------- 1 | #ifndef TITLEBAR_H 2 | #define TITLEBAR_H 3 | 4 | #include 5 | #include 6 | 7 | #define VALUE_DIS 5 8 | //Const int VALUE_DIS=5; 9 | //枚举,按钮状态 10 | enum eBtnMoustState{ 11 | eBtnStateNone,//无效 12 | eBtnStateDefault,//默认值(如按钮初始显示) 13 | eBtnStateHover,//鼠标移到按钮上状态 14 | eBtnStatePress//鼠标按下按钮时状态 15 | }; 16 | class TitleBar : public QWidget 17 | { 18 | Q_OBJECT 19 | public: 20 | explicit TitleBar(QWidget *parent = 0); 21 | void CreateWidget(); 22 | bool eventFilter(QObject *obj, QEvent *event); 23 | void CreateEventFiter(); 24 | const QString GetBtnImagePath(QToolButton *pBtn,bool bInit/*=false*/); 25 | void SetBtnIcon(QToolButton *pBtn,eBtnMoustState state,bool bInit/*=false*/); 26 | void CreateLayout(); 27 | void SetWidgetStyle(); 28 | signals: 29 | void signal_min(); 30 | void signal_maxrestore(); 31 | void signal_close(); 32 | 33 | protected: 34 | virtual void mousePressEvent(QMouseEvent *); 35 | virtual void mouseReleaseEvent(QMouseEvent *); 36 | virtual void mouseMoveEvent(QMouseEvent *); 37 | 38 | public slots: 39 | void slot_btnclick(); 40 | void slot_btnpress(); 41 | private: 42 | bool m_bLeftButtonPressed; 43 | QPoint m_ptMove; 44 | QPoint m_ptPress; 45 | QLabel *m_pLabelIcon, *m_pLabelTitle, *m_pLabelVersion; 46 | QToolButton *m_pBtnSkin, *m_pBtnMenu, *m_pBtnMin, *m_pBtnMax, *m_pBtnClose; 47 | QHBoxLayout *m_pLayout; 48 | 49 | 50 | }; 51 | 52 | #endif // TITLEBAR_H 53 | -------------------------------------------------------------------------------- /toolbar.cpp: -------------------------------------------------------------------------------- 1 | #include "toolbar.h" 2 | #include 3 | const int WIDGET_CNT=9; 4 | const int TOOLWIDGET_H=75; 5 | const int VALUE_DIS=5; 6 | ToolBar::ToolBar(QWidget *parent) : 7 | QWidget(parent) 8 | { 9 | CreateWidget(); 10 | SetStyleSheet(); 11 | } 12 | 13 | void ToolBar::CreateWidget() 14 | { 15 | //文本例子 16 | m_listMyStr<<"Examine"<<"KillTrojan"<<"CleanDust"<<"LeakRepair"<<"SysRepair" 17 | <<"CleanCom"<<"FunFull"<<"SoftMan"<<"Phnix"; 18 | //创建toolbutton 19 | for(int nIndex = 0;nIndexmove(nIndex*TOOLWIDGET_H+VALUE_DIS,0); 27 | //该信号槽设置其他按钮的按下状态bool值 28 | connect(m_listMyBtnPoint.at(nIndex), 29 | SIGNAL(signal_parent(MyBtn*)), 30 | this,SLOT(slot_set(MyBtn*))); 31 | } 32 | //创建label 33 | m_pLabel = new QLabel(this); 34 | m_pLabel->setPixmap(QPixmap(":/res/images/logo.png")); 35 | } 36 | 37 | 38 | //resizeEvent 39 | void ToolBar::resizeEvent (QResizeEvent * event) 40 | { 41 | qDebug() << "proccessing logo label..."; 42 | //按钮垂直居中 43 | // m_pLabel->move(rect().width()-m_pLabel->pixmap()->width()-VALUE_DIS, 44 | // (rect().height()-m_pLabel->pixmap()->height())/2 ); 45 | m_pLabel->move(rect().width()-m_pLabel->pixmap()->width()-VALUE_DIS, 46 | 0); 47 | } 48 | 49 | //槽函数 50 | void ToolBar::slot_set(MyBtn *pObject) 51 | { 52 | for(int nIndex = 0;nIndexSetPress(false); 57 | } 58 | } 59 | } 60 | 61 | void ToolBar::SetStyleSheet() 62 | { 63 | // setStyleSheet("QLabel{border:2px solid red;}"); 64 | setStyleSheet("QLabel{border:0px;}"); 65 | } 66 | -------------------------------------------------------------------------------- /toolbar.h: -------------------------------------------------------------------------------- 1 | #ifndef TOOLBAR_H 2 | #define TOOLBAR_H 3 | 4 | #include 5 | #include 6 | #include "mybtn.h" 7 | 8 | class ToolBar : public QWidget 9 | { 10 | Q_OBJECT 11 | public: 12 | explicit ToolBar(QWidget *parent = 0); 13 | void CreateWidget(); 14 | void SetStyleSheet(); 15 | signals: 16 | protected: 17 | virtual void resizeEvent(QResizeEvent *); 18 | 19 | public slots: 20 | void slot_set(MyBtn *pObject); 21 | private: 22 | QList m_listMyBtnPoint; 23 | QList m_listMyStr; 24 | QLabel *m_pLabel; 25 | }; 26 | 27 | #endif // TOOLBAR_H 28 | --------------------------------------------------------------------------------