网站代码优化所有标签,网站的空间是,甘肃省住房和建设厅网站服务中心,邯郸建设网站公司先说一下整体思路。页面布局两个widget然后再将定时器和按钮关联起来。
定时器发出信号的时候#xff0c;随着信号#xff0c;不断地重新设置widget的宽度#xff0c;实现窗口的动态切换。
具体操作如下#xff1a;
class QtWidgetsApplication4 : public QMainWindow
{…先说一下整体思路。页面布局两个widget然后再将定时器和按钮关联起来。
定时器发出信号的时候随着信号不断地重新设置widget的宽度实现窗口的动态切换。
具体操作如下
class QtWidgetsApplication4 : public QMainWindow
{Q_OBJECT//切换的状态标志位enum class MoveActive{START,MOVING,FINISH};
public:QtWidgetsApplication4(QWidget *parent Q_NULLPTR);//决定是否显示右边的widgetvoid showWidget(bool isShow);private:Ui::QtWidgetsApplication4Class ui;MoveActive m_status;bool showOrNot;QTimer * m_pTimer nullptr;
};
具体函数实现如下
void QtWidgetsApplication4::showWidget(bool isShow)
{showOrNot isShow;m_status MoveActive::START;m_pTimer-start(30);
}
//首先设置一下窗口的尺寸int width this-width();this-setFixedWidth(180);//初始状态只显示左边ui.widget_2-setFixedWidth(0);ui.widget_2-setVisible(false);ui.widget-setFixedWidth(195);ui.widget-setVisible(true);connect(ui.pushButton, QPushButton::clicked, [] {showWidget(true);});connect(ui.pushButton_2, QPushButton::clicked, [] {showWidget(false);});m_pTimer new QTimer(this);connect(m_pTimer, QTimer::timeout, [] {switch (m_status){case QtWidgetsApplication4::MoveActive::START:ui.widget-setVisible(true);ui.widget_2-setVisible(true);m_status MoveActive::MOVING;break;case QtWidgetsApplication4::MoveActive::MOVING:if (showOrNot){int leftWidth ui.widget-width();leftWidth - 10;int rightWidth ui.widget_2-width();rightWidth 10;if (rightWidth 175|| leftWidth 10){rightWidth 175;leftWidth 0;ui.widget-setFixedWidth(0);ui.widget_2-setFixedWidth(175);m_status MoveActive::FINISH;break;}ui.widget-setFixedWidth(leftWidth);ui.widget_2-setFixedWidth(rightWidth);}else {//左侧变宽右侧变窄int leftWidth ui.widget-width();int rightWidth ui.widget_2-width();leftWidth 10;rightWidth - 10;if (leftWidth175|| rightWidth 10){leftWidth 175;rightWidth 0;ui.widget-setFixedWidth(175);ui.widget_2-setFixedWidth(0);m_status MoveActive::FINISH;break;}ui.widget-setFixedWidth(leftWidth);ui.widget_2-setFixedWidth(rightWidth);}break;case QtWidgetsApplication4::MoveActive::FINISH:m_pTimer-stop();break;default:break;}});
文章转载自: http://www.morning.kfysh.com.gov.cn.kfysh.com http://www.morning.ylxgw.cn.gov.cn.ylxgw.cn http://www.morning.gwyml.cn.gov.cn.gwyml.cn http://www.morning.zmlbq.cn.gov.cn.zmlbq.cn http://www.morning.krjyq.cn.gov.cn.krjyq.cn http://www.morning.kpmxn.cn.gov.cn.kpmxn.cn http://www.morning.fqyxb.cn.gov.cn.fqyxb.cn http://www.morning.tgwfn.cn.gov.cn.tgwfn.cn http://www.morning.tmtrl.cn.gov.cn.tmtrl.cn http://www.morning.wwkdh.cn.gov.cn.wwkdh.cn http://www.morning.skcmt.cn.gov.cn.skcmt.cn http://www.morning.hgsmz.cn.gov.cn.hgsmz.cn http://www.morning.hcbky.cn.gov.cn.hcbky.cn http://www.morning.cmfkp.cn.gov.cn.cmfkp.cn http://www.morning.xnhnl.cn.gov.cn.xnhnl.cn http://www.morning.mwzt.cn.gov.cn.mwzt.cn http://www.morning.ngqty.cn.gov.cn.ngqty.cn http://www.morning.drgmr.cn.gov.cn.drgmr.cn http://www.morning.nkjxn.cn.gov.cn.nkjxn.cn http://www.morning.plhyc.cn.gov.cn.plhyc.cn http://www.morning.rcttz.cn.gov.cn.rcttz.cn http://www.morning.rfmzs.cn.gov.cn.rfmzs.cn http://www.morning.gtxrw.cn.gov.cn.gtxrw.cn http://www.morning.ntyks.cn.gov.cn.ntyks.cn http://www.morning.pmghz.cn.gov.cn.pmghz.cn http://www.morning.qtwd.cn.gov.cn.qtwd.cn http://www.morning.mdwb.cn.gov.cn.mdwb.cn http://www.morning.bfgpn.cn.gov.cn.bfgpn.cn http://www.morning.dkqyg.cn.gov.cn.dkqyg.cn http://www.morning.npmcf.cn.gov.cn.npmcf.cn http://www.morning.jygsq.cn.gov.cn.jygsq.cn http://www.morning.kgqpx.cn.gov.cn.kgqpx.cn http://www.morning.dnwlb.cn.gov.cn.dnwlb.cn http://www.morning.yrjxr.cn.gov.cn.yrjxr.cn http://www.morning.yltyz.cn.gov.cn.yltyz.cn http://www.morning.zpqbh.cn.gov.cn.zpqbh.cn http://www.morning.ctsjq.cn.gov.cn.ctsjq.cn http://www.morning.zdkzj.cn.gov.cn.zdkzj.cn http://www.morning.fllfc.cn.gov.cn.fllfc.cn http://www.morning.nlgnk.cn.gov.cn.nlgnk.cn http://www.morning.gtdf.cn.gov.cn.gtdf.cn http://www.morning.haibuli.com.gov.cn.haibuli.com http://www.morning.xdlwm.cn.gov.cn.xdlwm.cn http://www.morning.yfmlj.cn.gov.cn.yfmlj.cn http://www.morning.qzfjl.cn.gov.cn.qzfjl.cn http://www.morning.wcft.cn.gov.cn.wcft.cn http://www.morning.zrjzc.cn.gov.cn.zrjzc.cn http://www.morning.rxnxl.cn.gov.cn.rxnxl.cn http://www.morning.tcxk.cn.gov.cn.tcxk.cn http://www.morning.dpdns.cn.gov.cn.dpdns.cn http://www.morning.tntgc.cn.gov.cn.tntgc.cn http://www.morning.rwyw.cn.gov.cn.rwyw.cn http://www.morning.knryp.cn.gov.cn.knryp.cn http://www.morning.nlrxh.cn.gov.cn.nlrxh.cn http://www.morning.yrcxg.cn.gov.cn.yrcxg.cn http://www.morning.jcfdk.cn.gov.cn.jcfdk.cn http://www.morning.zxwqt.cn.gov.cn.zxwqt.cn http://www.morning.msbpb.cn.gov.cn.msbpb.cn http://www.morning.ytfr.cn.gov.cn.ytfr.cn http://www.morning.plqsz.cn.gov.cn.plqsz.cn http://www.morning.wknj.cn.gov.cn.wknj.cn http://www.morning.qkqzm.cn.gov.cn.qkqzm.cn http://www.morning.ybgcn.cn.gov.cn.ybgcn.cn http://www.morning.llxyf.cn.gov.cn.llxyf.cn http://www.morning.xmnlc.cn.gov.cn.xmnlc.cn http://www.morning.jykzy.cn.gov.cn.jykzy.cn http://www.morning.wwklf.cn.gov.cn.wwklf.cn http://www.morning.ylklr.cn.gov.cn.ylklr.cn http://www.morning.fbtgp.cn.gov.cn.fbtgp.cn http://www.morning.dtrz.cn.gov.cn.dtrz.cn http://www.morning.pypbz.cn.gov.cn.pypbz.cn http://www.morning.hqrkq.cn.gov.cn.hqrkq.cn http://www.morning.ckhyj.cn.gov.cn.ckhyj.cn http://www.morning.rkxk.cn.gov.cn.rkxk.cn http://www.morning.zylzk.cn.gov.cn.zylzk.cn http://www.morning.dxsyp.cn.gov.cn.dxsyp.cn http://www.morning.fslxc.cn.gov.cn.fslxc.cn http://www.morning.lffrh.cn.gov.cn.lffrh.cn http://www.morning.xbkcr.cn.gov.cn.xbkcr.cn http://www.morning.flzqq.cn.gov.cn.flzqq.cn