忻州市城乡建设局网站,互联网营销师在哪里报名,企业建站1年,二手手机网站网页设计该示例演示了一个扩张的窗口#xff0c;主窗口的布局为水平布局#xff0c;内置两个子窗口#xff0c;采用定时器设置左边窗口的宽度#xff0c;达到控制扩张的目的。 #include QApplication
#include QWidget
#include QHBox… 该示例演示了一个扩张的窗口主窗口的布局为水平布局内置两个子窗口采用定时器设置左边窗口的宽度达到控制扩张的目的。 #include QApplication
#include QWidget
#include QHBoxLayout
#include QTimerclass MyWidget : public QWidget
{//Q_OBJECT
public:MyWidget(QWidget* parent nullptr) : QWidget(parent){setFixedSize(600, 400);hLayout new QHBoxLayout(this);widget1 new QWidget(this);widget1-setFixedWidth(20);widget1-setStyleSheet(background-color:red;);widget2 new QWidget(this);hLayout-addWidget(widget1);hLayout-addWidget(widget2, 1);widget2-setStyleSheet(background-color:green;);m_timer new QTimer(this);m_timer-start();m_timer-setInterval(100);QObject::connect(m_timer, QTimer::timeout, []() {int nW widget1-width() 1;if (nW 100)return;widget1-setFixedWidth(nW);});}private:QWidget* widget1;QWidget* widget2;QHBoxLayout *hLayout;QTimer* m_timer;
};int main(int argc, char** argv)
{QApplication app(argc, argv);MyWidget w;w.show();return app.exec();
}