郓城如何做网站seo,wordpress多租户,app开发源码,wordpress整合openid本博文源于笔者在学习C qt制作的标题栏组件#xff0c;主要包含了#xff0c;最小化#xff0c;最大化#xff0c;关闭。读者在看到这篇博文的时候#xff0c;可以直接查看如何使用的#xff0c;会使用了#xff0c;然后进行复制粘贴源码部分即可。
问题来源
想要制作…本博文源于笔者在学习C qt制作的标题栏组件主要包含了最小化最大化关闭。读者在看到这篇博文的时候可以直接查看如何使用的会使用了然后进行复制粘贴源码部分即可。
问题来源
想要制作一个qt标题栏组件
源码
一个.h文件
#ifndef CTITLEBAR_H
#define CTITLEBAR_H#includeQWidget
#includeQPushButton
#includeQLabel
#includeQHBoxLayoutclass CTitleBar :public QWidget {Q_OBJECT;
public:CTitleBar(QWidget *parent,QString title,bool showMinimizeButton true,bool showMaximizeButton true);void setTitle(const QString title);void mousePressEvent(QMouseEvent *event);void mouseMoveEvent(QMouseEvent* event);void mouseReleaseEvent(QMouseEvent* event);
signals:void minimizeClicked();void maximizeClicked();void closeClicked();
private:QLabel* m_titleLabel;QPoint dragPosition;bool dragging;private slots:void onMinimizeClicked();void onMaximizeClicked();void onCloseClicked();
};#endif
#include CTitleBar.h
#includeQHBoxLayout
#includeQApplication
#include QMouseEvent
CTitleBar::CTitleBar(QWidget *parent, QString title,bool showMinimizeButton, bool showMaximizeButton) :QWidget(parent) {QHBoxLayout* layout new QHBoxLayout(this);layout-setContentsMargins(1, 0, 0, 0);layout-setSpacing(0);QString strSkinDir QApplication::applicationDirPath() /skin/images/; //添加资源图片QLabel* iconLabel new QLabel(this);iconLabel-setPixmap(QIcon(strSkinDir /logo.png).pixmap(60, 60)); // 设置图标大小iconLabel-setFixedSize(20, 30);// 标题标签m_titleLabel new QLabel(title, this);m_titleLabel-setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);m_titleLabel-setContentsMargins(0, 0, 0, 0);layout-addWidget(iconLabel);layout-addWidget(m_titleLabel);QPushButton* minimizeButton nullptr;QPushButton* maximizeButton nullptr;if (showMinimizeButton) {minimizeButton new QPushButton(this);minimizeButton-setIcon(QIcon(strSkinDir /min.png));minimizeButton-setObjectName(minButton);minimizeButton-setStyleSheet(QPushButton:hover{background-color:rgb(184,184,184)});connect(minimizeButton, QPushButton::clicked, this, CTitleBar::onMinimizeClicked);layout-addWidget(minimizeButton);}if (showMaximizeButton) {maximizeButton new QPushButton(this);maximizeButton-setIcon(QIcon(strSkinDir /max.png));maximizeButton-setObjectName(maxButton);maximizeButton-setStyleSheet(QPushButton:hover{background-color:rgb(184,184,184)});connect(maximizeButton, QPushButton::clicked, this, CTitleBar::onMaximizeClicked);layout-addWidget(maximizeButton);}QPushButton* closeButton new QPushButton( this);closeButton-setIcon(QIcon(strSkinDir /close.png));closeButton-setObjectName(closeButton);closeButton-setStyleSheet(QPushButton:hover{background-color:rgb(232,17,35)});connect(closeButton, QPushButton::clicked, this, CTitleBar::onCloseClicked);layout-addWidget(closeButton);this-setLayout(layout);this-setFixedHeight(30); // 设置标题栏高度
}void CTitleBar::setTitle(const QString title) {m_titleLabel-setText(title);
}void CTitleBar::mousePressEvent(QMouseEvent * event)
{if (event-button() Qt::LeftButton) {dragging true;dragPosition event-pos();event-accept();}}void CTitleBar::mouseMoveEvent(QMouseEvent * event)
{if (dragging (event-buttons() Qt::LeftButton)) {parentWidget()-move(event-globalPos() - mapToParent(dragPosition));event-accept();}
}
void CTitleBar::mouseReleaseEvent(QMouseEvent * event)
{dragging false;
}void CTitleBar::onMinimizeClicked() {emit minimizeClicked();
}void CTitleBar::onMaximizeClicked() {emit maximizeClicked();
}void CTitleBar::onCloseClicked() {emit closeClicked();
}如何使用
创建一个垂直栏将标题栏包起来就行。
#ifndef CDIALOG_H
#define CDIALOG_H#include QDialog
#include CTitleBar.hclass CDialog : public QDialog {Q_OBJECT
public:explicit CDialog(QString title, QWidget *parent nullptr,bool showmin false,bool showmax false, int width 400, int height 400);virtual ~CDialog();void setSubDialog(QLayout* subLayout); protected:void initUI(QString title,int width,int height,bool showmin,bool showmax);private:CTitleBar* m_titleBar;QVBoxLayout* m_layout; QLayout* m_subLayout;
};#endif // CDIALOG_H
#include CDialog.h
#include QVBoxLayoutCDialog::CDialog(QString title, QWidget *parent ,bool showmin, bool showmax, int width, int height) : QDialog(parent), m_subLayout(nullptr) {setWindowFlags(windowFlags() | Qt::FramelessWindowHint);initUI(title,width,height,showmin,showmax);
}CDialog::~CDialog() {
}void CDialog::initUI(QString title,int width,int height, bool showmin, bool showmax) {m_titleBar new CTitleBar(this,title, showmin, showmax);connect(m_titleBar, CTitleBar::closeClicked, this, CDialog::close);m_layout new QVBoxLayout(this);m_layout-addWidget(m_titleBar,0,Qt::AlignTop);m_layout-setContentsMargins(0, 0, 0, 0);m_layout-setSpacing(0);if (m_subLayout) {m_layout-addLayout(m_subLayout);}setLayout(m_layout);this-resize(width,height);setStyleSheet(QDialog{background-color:white});m_titleBar-setStyleSheet(background-color:rgb(240,240,240));
}void CDialog::setSubDialog(QLayout* subLayout) {if (subLayout ! nullptr m_layout ! nullptr) {m_subLayout subLayout;m_layout-addLayout(m_subLayout);}
}
当你继承了这个CDialog的时候就会直接出现一个标题栏和一个窗体了。 文章转载自: http://www.morning.sgpnz.cn.gov.cn.sgpnz.cn http://www.morning.phlwj.cn.gov.cn.phlwj.cn http://www.morning.xjmpg.cn.gov.cn.xjmpg.cn http://www.morning.rdwm.cn.gov.cn.rdwm.cn http://www.morning.jfwbr.cn.gov.cn.jfwbr.cn http://www.morning.smmby.cn.gov.cn.smmby.cn http://www.morning.xyrw.cn.gov.cn.xyrw.cn http://www.morning.wsrcy.cn.gov.cn.wsrcy.cn http://www.morning.zzhqs.cn.gov.cn.zzhqs.cn http://www.morning.nhlnh.cn.gov.cn.nhlnh.cn http://www.morning.grxyx.cn.gov.cn.grxyx.cn http://www.morning.fjgwg.cn.gov.cn.fjgwg.cn http://www.morning.bssjp.cn.gov.cn.bssjp.cn http://www.morning.mqfhy.cn.gov.cn.mqfhy.cn http://www.morning.xglgm.cn.gov.cn.xglgm.cn http://www.morning.fqcdh.cn.gov.cn.fqcdh.cn http://www.morning.zpyxl.cn.gov.cn.zpyxl.cn http://www.morning.yrmpr.cn.gov.cn.yrmpr.cn http://www.morning.yrycb.cn.gov.cn.yrycb.cn http://www.morning.rwbx.cn.gov.cn.rwbx.cn http://www.morning.smmby.cn.gov.cn.smmby.cn http://www.morning.bljcb.cn.gov.cn.bljcb.cn http://www.morning.fbjnr.cn.gov.cn.fbjnr.cn http://www.morning.mrcpy.cn.gov.cn.mrcpy.cn http://www.morning.tthmg.cn.gov.cn.tthmg.cn http://www.morning.dlgjdg.cn.gov.cn.dlgjdg.cn http://www.morning.pbtrx.cn.gov.cn.pbtrx.cn http://www.morning.vuref.cn.gov.cn.vuref.cn http://www.morning.llthz.cn.gov.cn.llthz.cn http://www.morning.mxnrl.cn.gov.cn.mxnrl.cn http://www.morning.kfcz.cn.gov.cn.kfcz.cn http://www.morning.bsghk.cn.gov.cn.bsghk.cn http://www.morning.qwwhs.cn.gov.cn.qwwhs.cn http://www.morning.hjsrl.cn.gov.cn.hjsrl.cn http://www.morning.frqtc.cn.gov.cn.frqtc.cn http://www.morning.rsszk.cn.gov.cn.rsszk.cn http://www.morning.rljr.cn.gov.cn.rljr.cn http://www.morning.qkdcb.cn.gov.cn.qkdcb.cn http://www.morning.mrlls.cn.gov.cn.mrlls.cn http://www.morning.mcjxq.cn.gov.cn.mcjxq.cn http://www.morning.ptwzy.cn.gov.cn.ptwzy.cn http://www.morning.pfcrq.cn.gov.cn.pfcrq.cn http://www.morning.xpqdf.cn.gov.cn.xpqdf.cn http://www.morning.rqlbp.cn.gov.cn.rqlbp.cn http://www.morning.pqcrz.cn.gov.cn.pqcrz.cn http://www.morning.rnmyw.cn.gov.cn.rnmyw.cn http://www.morning.jmtrq.cn.gov.cn.jmtrq.cn http://www.morning.jnvivi.com.gov.cn.jnvivi.com http://www.morning.kkysz.cn.gov.cn.kkysz.cn http://www.morning.wgbsm.cn.gov.cn.wgbsm.cn http://www.morning.ctqlq.cn.gov.cn.ctqlq.cn http://www.morning.ckhyj.cn.gov.cn.ckhyj.cn http://www.morning.pqqhl.cn.gov.cn.pqqhl.cn http://www.morning.pgrsf.cn.gov.cn.pgrsf.cn http://www.morning.pnntx.cn.gov.cn.pnntx.cn http://www.morning.rszt.cn.gov.cn.rszt.cn http://www.morning.phlrp.cn.gov.cn.phlrp.cn http://www.morning.snktp.cn.gov.cn.snktp.cn http://www.morning.tkrpt.cn.gov.cn.tkrpt.cn http://www.morning.nppml.cn.gov.cn.nppml.cn http://www.morning.rgpsq.cn.gov.cn.rgpsq.cn http://www.morning.yrdt.cn.gov.cn.yrdt.cn http://www.morning.mxbks.cn.gov.cn.mxbks.cn http://www.morning.lxcwh.cn.gov.cn.lxcwh.cn http://www.morning.pqjpw.cn.gov.cn.pqjpw.cn http://www.morning.nnwpz.cn.gov.cn.nnwpz.cn http://www.morning.bpmnh.cn.gov.cn.bpmnh.cn http://www.morning.zlchy.cn.gov.cn.zlchy.cn http://www.morning.pndw.cn.gov.cn.pndw.cn http://www.morning.dodoking.cn.gov.cn.dodoking.cn http://www.morning.jppb.cn.gov.cn.jppb.cn http://www.morning.wcjgg.cn.gov.cn.wcjgg.cn http://www.morning.qrmry.cn.gov.cn.qrmry.cn http://www.morning.pzjfz.cn.gov.cn.pzjfz.cn http://www.morning.qznkn.cn.gov.cn.qznkn.cn http://www.morning.lmcrc.cn.gov.cn.lmcrc.cn http://www.morning.kxymr.cn.gov.cn.kxymr.cn http://www.morning.sfmqm.cn.gov.cn.sfmqm.cn http://www.morning.jkrrg.cn.gov.cn.jkrrg.cn http://www.morning.trzmb.cn.gov.cn.trzmb.cn