{"id":73467,"date":"2026-02-07T17:06:22","date_gmt":"2026-02-07T09:06:22","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/73467.html"},"modified":"2026-02-07T17:06:22","modified_gmt":"2026-02-07T09:06:22","slug":"qt-%e5%b8%b8%e7%94%a8%e6%8e%a7%e4%bb%b6","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/73467.html","title":{"rendered":"Qt\u2014\u2014\u5e38\u7528\u63a7\u4ef6"},"content":{"rendered":"<p id=\"main-toc\">\u76ee\u5f55<\/p>\n<p id=\"%E6%8C%89%E9%92%AE%E7%B1%BB%E6%8E%A7%E4%BB%B6-toc\" style=\"margin-left:0px\">\u6309\u94ae\u7c7b\u63a7\u4ef6<\/p>\n<p id=\"QPushButton-toc\" style=\"margin-left:40px\">QPushButton<\/p>\n<p id=\"%E8%AE%BE%E7%BD%AE%E6%8C%89%E9%92%AE%E6%96%87%E6%9C%AC-toc\" style=\"margin-left:80px\">\u8bbe\u7f6e\u6309\u94ae\u6587\u672c<\/p>\n<p id=\"%E7%BB%99%E6%8C%89%E9%92%AE%E8%AE%BE%E7%BD%AE%E5%9B%BE%E6%A0%87-toc\" style=\"margin-left:80px\">\u7ed9\u6309\u94ae\u8bbe\u7f6e\u56fe\u6807<\/p>\n<p id=\"%E8%AE%BE%E7%BD%AE%E6%8C%89%E9%92%AE%E5%BF%AB%E6%8D%B7%E9%94%AE-toc\" style=\"margin-left:80px\">\u8bbe\u7f6e\u6309\u94ae\u5feb\u6377\u952e<\/p>\n<p id=\"%E8%AE%BE%E7%BD%AE%E6%8C%89%E9%92%AE%E9%87%8D%E5%A4%8D%E8%A7%A6%E5%8F%91-toc\" style=\"margin-left:80px\">\u8bbe\u7f6e\u6309\u94ae\u91cd\u590d\u89e6\u53d1<\/p>\n<p id=\"QRadioButton-toc\" style=\"margin-left:40px\">QRadioButton<\/p>\n<p id=\"%E8%AE%BE%E7%BD%AE%E9%80%89%E9%A1%B9%E6%98%AF%E5%90%A6%E8%A2%AB%E9%80%89%E4%B8%AD-toc\" style=\"margin-left:80px\">\u8bbe\u7f6e\u9009\u9879\u662f\u5426\u88ab\u9009\u4e2d<\/p>\n<p id=\"%E8%AE%BE%E7%BD%AE%E9%80%89%E9%A1%B9%E6%98%AF%E5%90%A6%E5%8F%AF%E4%BB%A5%E9%80%89%E4%B8%AD-toc\" style=\"margin-left:80px\">\u8bbe\u7f6e\u9009\u9879\u662f\u5426\u53ef\u4ee5\u9009\u4e2d<\/p>\n<p id=\"%E8%AE%BE%E7%BD%AE%E9%80%89%E9%A1%B9%E7%A6%81%E7%94%A8-toc\" style=\"margin-left:80px\">\u8bbe\u7f6e\u9009\u9879\u7981\u7528<\/p>\n<p id=\"%E8%AE%BE%E7%BD%AE%E9%80%89%E9%A1%B9%E6%98%AF%E5%90%A6%E6%8E%92%E4%BB%96-toc\" style=\"margin-left:80px\">\u8bbe\u7f6e\u9009\u9879\u662f\u5426\u6392\u4ed6<\/p>\n<p id=\"%E5%B0%86%E9%80%89%E9%A1%B9%E5%88%86%E7%BB%84-toc\" style=\"margin-left:80px\">\u5c06\u9009\u9879\u5206\u7ec4<\/p>\n<p id=\"%E9%A2%98%E5%A4%96%E8%AF%9D-%E6%8C%89%E9%92%AE(%E9%80%89%E9%A1%B9)%E7%9B%B8%E5%85%B3%E7%9A%84%E4%BF%A1%E5%8F%B7-toc\" style=\"margin-left:40px\">\u9898\u5916\u8bdd-\u6309\u94ae(\u9009\u9879)\u76f8\u5173\u7684\u4fe1\u53f7<\/p>\n<p id=\"QCheckBox-toc\" style=\"margin-left:40px\">QCheckBox<\/p>\n<p id=\"%C2%A0%E8%AE%BE%E7%BD%AE%E9%80%89%E9%A1%B9%E6%98%AF%E5%90%A6%E8%A2%AB%E9%80%89%E4%B8%AD-toc\" style=\"margin-left:80px\">\u00a0\u8bbe\u7f6e\u9009\u9879\u662f\u5426\u88ab\u9009\u4e2d<\/p>\n<p id=\"%E8%AE%BE%E7%BD%AE%E9%80%89%E9%A1%B9%E6%98%AF%E5%90%A6%E5%8F%AF%E4%BB%A5%E9%80%89%E4%B8%AD-toc\" style=\"margin-left:80px\">\u8bbe\u7f6e\u9009\u9879\u662f\u5426\u53ef\u4ee5\u9009\u4e2d<\/p>\n<p id=\"%E6%98%BE%E7%A4%BA%E7%B1%BB%E6%8E%A7%E4%BB%B6-toc\" style=\"margin-left:0px\">\u663e\u793a\u7c7b\u63a7\u4ef6<\/p>\n<p id=\"QLabel-toc\" style=\"margin-left:40px\">QLabel<\/p>\n<p id=\"%E8%AE%BE%E7%BD%AE%E6%96%87%E6%9C%AC%E5%86%85%E5%AE%B9-toc\" style=\"margin-left:80px\">\u8bbe\u7f6e\u6587\u672c\u5185\u5bb9<\/p>\n<p id=\"%E8%AE%BE%E7%BD%AElabel%E6%96%87%E6%9C%AC%E7%9A%84%E6%A0%BC%E5%BC%8F-toc\" style=\"margin-left:80px\">\u8bbe\u7f6elabel\u6587\u672c\u7684\u683c\u5f0f<\/p>\n<p id=\"%E7%BB%99label%E6%B7%BB%E5%8A%A0%E5%9B%BE%E7%89%87-toc\" style=\"margin-left:80px\">\u7ed9label\u6dfb\u52a0\u56fe\u7247<\/p>\n<p id=\"%E8%AE%BE%E7%BD%AE%E5%86%85%E5%AE%B9(%E4%B8%BB%E8%A6%81%E6%8C%87%E5%9B%BE%E7%89%87)%E8%87%AA%E5%8A%A8%E6%8B%89%E4%BC%B8%E5%A1%AB%E5%85%85%E6%95%B4%E4%B8%AAlabel-toc\" style=\"margin-left:80px\">\u8bbe\u7f6e\u5185\u5bb9(\u4e3b\u8981\u6307\u56fe\u7247)\u81ea\u52a8\u62c9\u4f38\u586b\u5145\u6574\u4e2alabel<\/p>\n<p id=\"%E8%AE%BE%E7%BD%AE%E6%96%87%E6%9C%AC%E5%AF%B9%E9%BD%90%E6%96%B9%E5%BC%8F-toc\" style=\"margin-left:80px\">\u8bbe\u7f6e\u6587\u672c\u5bf9\u9f50\u65b9\u5f0f<\/p>\n<p id=\"%E8%AE%BE%E7%BD%AE%E6%96%87%E6%9C%AC%E8%87%AA%E5%8A%A8%E6%8D%A2%E8%A1%8C-toc\" style=\"margin-left:80px\">\u8bbe\u7f6e\u6587\u672c\u81ea\u52a8\u6362\u884c<\/p>\n<p id=\"%E8%AE%BE%E7%BD%AE%E6%96%87%E6%9C%AC%E7%BC%A9%E8%BF%9B-toc\" style=\"margin-left:80px\">\u8bbe\u7f6e\u6587\u672c\u7f29\u8fdb<\/p>\n<p id=\"%E8%AE%BE%E7%BD%AE%E5%86%85%E9%83%A8%E6%96%87%E6%9C%AC%E5%92%8C%E6%96%87%E6%9C%AC%E6%A1%86%E7%9A%84%E8%BE%B9%E8%B7%9D-toc\" style=\"margin-left:80px\">\u8bbe\u7f6e\u5185\u90e8\u6587\u672c\u548c\u6587\u672c\u6846\u7684\u8fb9\u8ddd<\/p>\n<p id=\"%E8%AE%BE%E7%BD%AE%E6%A0%87%E7%AD%BE%E7%9A%84%E4%BC%99%E4%BC%B4-toc\" style=\"margin-left:80px\">\u8bbe\u7f6e\u6807\u7b7e\u7684\u4f19\u4f34<\/p>\n<p id=\"QLCDNumber-toc\" style=\"margin-left:40px\">QLCDNumber<\/p>\n<p id=\"%E9%A2%98%E5%A4%96%E8%AF%9D%E2%80%94%E2%80%94%E5%85%B3%E4%BA%8EQt%E4%B8%AD%E7%BA%BF%E7%A8%8B%E4%BF%AE%E6%94%B9%E7%95%8C%E9%9D%A2-toc\" style=\"margin-left:40px\">\u9898\u5916\u8bdd\u2014\u2014\u5173\u4e8eQt\u4e2d\u7ebf\u7a0b\u4fee\u6539\u754c\u9762<\/p>\n<p id=\"QProgressBar-toc\" style=\"margin-left:40px\">QProgressBar<\/p>\n<p id=\"QCalendarWidget-toc\" style=\"margin-left:40px\">QCalendarWidget<\/p>\n<p id=\"%E8%BE%93%E5%85%A5%E7%B1%BB%E6%8E%A7%E4%BB%B6-toc\" style=\"margin-left:0px\">\u8f93\u5165\u7c7b\u63a7\u4ef6<\/p>\n<p id=\"QLineEdit-toc\" style=\"margin-left:40px\">QLineEdit<\/p>\n<p id=\"%E9%A2%98%E5%A4%96%E8%AF%9D%E2%80%94%E2%80%94%E5%85%B3%E4%BA%8E%E6%AD%A3%E5%88%99%E8%A1%A8%E8%BE%BE%E5%BC%8F%E9%AA%8C%E8%AF%81%E8%BE%93%E5%85%A5%E6%A1%86%E6%95%B0%E6%8D%AE-toc\" style=\"margin-left:40px\">\u9898\u5916\u8bdd\u2014\u2014\u5173\u4e8e\u6b63\u5219\u8868\u8fbe\u5f0f\u9a8c\u8bc1\u8f93\u5165\u6846\u6570\u636e<\/p>\n<p id=\"QTextEdit-toc\" style=\"margin-left:40px\">QTextEdit<\/p>\n<p id=\"QComboBox-toc\" style=\"margin-left:40px\">QComboBox<\/p>\n<p id=\"QSpinBox-toc\" style=\"margin-left:40px\">QSpinBox<\/p>\n<p id=\"QDateTimeEdit-toc\" style=\"margin-left:40px\">QDateTimeEdit<\/p>\n<p id=\"QDial-toc\" style=\"margin-left:40px\">QDial<\/p>\n<p id=\"QSlider-toc\" style=\"margin-left:40px\">QSlider<\/p>\n<p id=\"%E9%A2%98%E5%A4%96%E8%AF%9D%E2%80%94%E2%80%94%E7%BB%99Qslider%E8%AE%BE%E7%BD%AE%E5%BF%AB%E6%8D%B7%E9%94%AE-toc\" style=\"margin-left:40px\">\u9898\u5916\u8bdd\u2014\u2014\u7ed9Qslider\u8bbe\u7f6e\u5feb\u6377\u952e<\/p>\n<p id=\"%E5%A4%9A%E5%85%83%E7%B4%A0%E6%8E%A7%E4%BB%B6-toc\" style=\"margin-left:0px\">\u591a\u5143\u7d20\u63a7\u4ef6<\/p>\n<p id=\"QListWidget-toc\" style=\"margin-left:40px\">QListWidget<\/p>\n<p id=\"QTableWidget-toc\" style=\"margin-left:40px\">QTableWidget<\/p>\n<p id=\"QTreeWidget-toc\" style=\"margin-left:40px\">QTreeWidget<\/p>\n<p id=\"%E5%AE%B9%E5%99%A8%E7%B1%BB%E6%8E%A7%E4%BB%B6-toc\" style=\"margin-left:0px\">\u5bb9\u5668\u7c7b\u63a7\u4ef6<\/p>\n<p id=\"QGroupBox-toc\" style=\"margin-left:40px\">QGroupBox<\/p>\n<p id=\"QTabWidget-toc\" style=\"margin-left:40px\">QTabWidget<\/p>\n<p id=\"%E5%B8%83%E5%B1%80%E7%AE%A1%E7%90%86%E5%99%A8-toc\" style=\"margin-left:0px\">\u5e03\u5c40\u7ba1\u7406\u5668<\/p>\n<p id=\"QVBoxLayout%EF%BC%88%E5%9E%82%E7%9B%B4%E5%B8%83%E5%B1%80%E7%AE%A1%E7%90%86%E5%99%A8%EF%BC%89-toc\" style=\"margin-left:40px\">QVBoxLayout&#xff08;\u5782\u76f4\u5e03\u5c40\u7ba1\u7406\u5668&#xff09;<\/p>\n<p id=\"QHBoxLayout(%E6%B0%B4%E5%B9%B3%E5%B8%83%E5%B1%80%E7%AE%A1%E7%90%86%E5%99%A8)-toc\" style=\"margin-left:40px\">QHBoxLayout(\u6c34\u5e73\u5e03\u5c40\u7ba1\u7406\u5668)<\/p>\n<p id=\"QGridLayout-toc\" style=\"margin-left:40px\">QGridLayout<\/p>\n<p id=\"%E9%A2%98%E5%A4%96%E8%AF%9D%E2%80%94%E2%80%94%E6%8E%A7%E4%BB%B6%E5%A4%A7%E5%B0%8F%E7%AD%96%E7%95%A5%E5%AF%B9%E5%B8%83%E5%B1%80%E7%9A%84%E5%BD%B1%E5%93%8D-toc\" style=\"margin-left:40px\">\u9898\u5916\u8bdd\u2014\u2014\u63a7\u4ef6\u5927\u5c0f\u7b56\u7565\u5bf9\u5e03\u5c40\u7684\u5f71\u54cd<\/p>\n<p id=\"QFormLayout%EF%BC%88%E8%A1%A8%E5%8D%95%E5%B8%83%E5%B1%80%E7%AE%A1%E7%90%86%E5%99%A8%EF%BC%89-toc\" style=\"margin-left:40px\">QFormLayout&#xff08;\u8868\u5355\u5e03\u5c40\u7ba1\u7406\u5668&#xff09;<\/p>\n<p id=\"QSpacerItem-toc\" style=\"margin-left:40px\">QSpacerItem<\/p>\n<hr id=\"hr-toc\" \/>\n<h2><span style=\"color:#0d0016\">\u6309\u94ae\u7c7b\u63a7\u4ef6<\/span><\/h2>\n<h3 id=\"QPushButton\" style=\"background-color:transparent\"><span style=\"color:#0d0016\">QPushButton<\/span><\/h3>\n<h4 id=\"%E8%AE%BE%E7%BD%AE%E6%8C%89%E9%92%AE%E6%96%87%E6%9C%AC\"><span style=\"color:#0d0016\">\u8bbe\u7f6e\u6309\u94ae\u6587\u672c<\/span><\/h4>\n<p>ui-&gt;pushButton-&gt;setText(QString(&#034;\u8fd9\u662f\u4e00\u4e2a\u6309\u94ae&#034;)); <\/p>\n<h4 id=\"%E7%BB%99%E6%8C%89%E9%92%AE%E8%AE%BE%E7%BD%AE%E5%9B%BE%E6%A0%87\"><span style=\"color:#0d0016\">\u7ed9\u6309\u94ae\u8bbe\u7f6e\u56fe\u6807<\/span><\/h4>\n<p>  QIcon icon(&#034;:\/rose.jpg&#034;);<br \/>\n  ui-&gt;pushButton-&gt;setIcon(icon);\/\/\u7ed9\u6309\u94ae\u8bbe\u7f6e\u56fe\u6807<br \/>\n  ui-&gt;pushButton-&gt;setIconSize(QSize(20,20));\/\/\u8bbe\u7f6e\u56fe\u6807\u5c3a\u5bf8 <\/p>\n<h4 id=\"%E8%AE%BE%E7%BD%AE%E6%8C%89%E9%92%AE%E5%BF%AB%E6%8D%B7%E9%94%AE\" style=\"background-color:transparent\"><span style=\"color:#0d0016\">\u8bbe\u7f6e\u6309\u94ae\u5feb\u6377\u952e<\/span><\/h4>\n<p>ui-&gt;a-&gt;setShortcut(QKeySequence(&#034;ctrl&#043;w&#034;));\/\/\u7ec4\u5408\u952ectrl&#043;w<br \/>\nui-&gt;b-&gt;setShortcut(QKeySequence(&#034;w&#034;));\/\/\u5b57\u6bcdw\u662f\u5feb\u6377\u952e<br \/>\nui-&gt;c-&gt;setShortcut(QKeySequence(Qt::Key_C));\/\/\u5b57\u6bcdC\u662f\u5feb\u6377\u952e<br \/>\nui-&gt;d-&gt;setShortcut(QKeySequence(Qt::CTRL&#043;Qt::Key_S));\/\/\u7ec4\u5408\u952ectrl&#043;s <\/p>\n<h4 id=\"%E8%AE%BE%E7%BD%AE%E6%8C%89%E9%92%AE%E9%87%8D%E5%A4%8D%E8%A7%A6%E5%8F%91\"><span style=\"color:#0d0016\">\u8bbe\u7f6e\u6309\u94ae\u91cd\u590d\u89e6\u53d1<\/span><\/h4>\n<p>ui-&gt;c-&gt;setAutoRepeat(true);\/\/\u5f00\u542f\u6309\u94ae\u70b9\u51fb\u7684\u91cd\u590d\u89e6\u53d1<br \/>\nui-&gt;c-&gt;setAutoRepeatDelay(1000);\/\/\u4ee5ms\u4e3a\u5355\u4f4d&#xff0c;\u8bbe\u7f6e\u6309\u4f4f\u591a\u4e45\u4e4b\u540e\u5f00\u59cb\u91cd\u590d\u89e6\u53d1<br \/>\nui-&gt;c-&gt;setAutoRepeatInterval(500);\/\/\u8bbe\u7f6e\u5f00\u59cb\u91cd\u590d\u51fa\u53d1\u540e\u6bcf\u6b21\u95f4\u9694\u591a\u4e45\u89e6\u53d1\u4e00\u6b21 <\/p>\n<hr \/>\n<h3 id=\"QRadioButton\"><span style=\"color:#0d0016\">QRadioButton<\/span><\/h3>\n<h4 id=\"%E8%AE%BE%E7%BD%AE%E9%80%89%E9%A1%B9%E6%98%AF%E5%90%A6%E8%A2%AB%E9%80%89%E4%B8%AD\"><span style=\"color:#0d0016\">\u8bbe\u7f6e\u9009\u9879\u662f\u5426\u88ab\u9009\u4e2d<\/span><\/h4>\n<p>ui-&gt;a-&gt;setChecked(true); <\/p>\n<h4 id=\"%E8%AE%BE%E7%BD%AE%E9%80%89%E9%A1%B9%E6%98%AF%E5%90%A6%E5%8F%AF%E4%BB%A5%E9%80%89%E4%B8%AD\"><span style=\"color:#0d0016\">\u8bbe\u7f6e\u9009\u9879\u662f\u5426\u53ef\u4ee5\u9009\u4e2d<\/span><\/h4>\n<p>ui-&gt;a-&gt;setCheckable(false);<br \/>\n\/\/\u5373\u4f7f\u8bbe\u7f6e\u4e86\u65e0\u6cd5\u9009\u4e2d&#xff0c;\u4e5f\u4f1a\u53d1\u9001\u4fe1\u53f7&#xff0c;\u6267\u884c\u69fd <\/p>\n<h4 id=\"%E8%AE%BE%E7%BD%AE%E9%80%89%E9%A1%B9%E7%A6%81%E7%94%A8\"><span style=\"color:#0d0016\">\u8bbe\u7f6e\u9009\u9879\u7981\u7528<\/span><\/h4>\n<p>ui-&gt;a-&gt;setEnabled(false);<br \/>\n\/\/\u5b8c\u5168\u7981\u7528\u9009\u9879&#xff0c;\u4e0d\u4f1a\u53d1\u9001\u4fe1\u53f7 <\/p>\n<h4 id=\"%E8%AE%BE%E7%BD%AE%E9%80%89%E9%A1%B9%E6%98%AF%E5%90%A6%E6%8E%92%E4%BB%96\"><span style=\"color:#0d0016\">\u8bbe\u7f6e\u9009\u9879\u662f\u5426\u6392\u4ed6<\/span><\/h4>\n<p>ui-&gt;a-&gt;setAutoExclusive(false);<br \/>\n\/\/\u9ed8\u8ba4\u5c31\u662f\u6392\u4ed6\u7684<br \/>\n\/\/\u6392\u4ed6\u610f\u5473\u7740&#xff0c;\u4e00\u65e6\u9009\u4e86\u8fd9\u4e2a\u9009\u9879&#xff0c;\u5176\u4ed6\u7684\u9009\u9879\u4e0d\u80fd\u88ab\u9009\u62e9&#xff0c;\u5df2\u7ecf\u88ab\u9009\u62e9\u7684\u4f1a\u53d6\u6d88\u9009\u62e9 <\/p>\n<h4 id=\"%E5%B0%86%E9%80%89%E9%A1%B9%E5%88%86%E7%BB%84\"><span style=\"color:#0d0016\">\u5c06\u9009\u9879\u5206\u7ec4<\/span><\/h4>\n<p><span style=\"color:#0d0016\">\u5206\u7ec4\u4e4b\u540e\u7ec4\u5408\u7ec4\u4e4b\u95f4\u7684\u9009\u9879\u4e92\u4e0d\u5f71\u54cd&#xff0c;\u6bd4\u5982\u6392\u4ed6\u6027<\/span><\/p>\n<p>    QButtonGroup *group1 &#061; new QButtonGroup(this);<br \/>\n    QButtonGroup *group2 &#061; new QButtonGroup(this);<\/p>\n<p>    \/\/\u628aa,b,c\u6309\u94ae\u6dfb\u52a0\u5230\u7ec41<br \/>\n    group1-&gt;addButton(ui-&gt;a);<br \/>\n    group1-&gt;addButton(ui-&gt;b);<br \/>\n    group1-&gt;addButton(ui-&gt;c);<\/p>\n<p>    \/\/\u628ad,e,f\u6309\u94ae\u6dfb\u52a0\u5230\u7ec42<br \/>\n    group2-&gt;addButton(ui-&gt;d);<br \/>\n    group2-&gt;addButton(ui-&gt;e);<br \/>\n    group2-&gt;addButton(ui-&gt;f); <\/p>\n<p><span style=\"color:#0d0016\">\u53ef\u89c1\u5206\u7ec4\u662f\u4f7f\u7528QButtonGroup\u7c7b\u8fdb\u884c\u7684<\/span><\/p>\n<hr \/>\n<h3 id=\"%E9%A2%98%E5%A4%96%E8%AF%9D-%E6%8C%89%E9%92%AE(%E9%80%89%E9%A1%B9)%E7%9B%B8%E5%85%B3%E7%9A%84%E4%BF%A1%E5%8F%B7\" style=\"background-color:transparent\"><span style=\"color:#0d0016\">\u9898\u5916\u8bdd-\u6309\u94ae(\u9009\u9879)\u76f8\u5173\u7684\u4fe1\u53f7<\/span><\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"208\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260207090615-6987008799d63.png\" width=\"597\" \/><\/p>\n<p><span style=\"color:#0d0016\">\u4e0a\u9762\u662fQt\u63d0\u4f9b\u76845\u79cd\u5173\u4e8e\u6309\u94ae\u70b9\u51fb\u540e\u53d1\u51fa\u7684\u4fe1\u53f7&#xff0c;\u4ed6\u4eec\u7684\u542b\u4e49\u5206\u522b\u662f&#xff1a;<\/span><\/p>\n<li><span style=\"color:#0d0016\">clicked():\u9f20\u6807\u70b9\u51fb\u6309\u94ae\u53c8\u677e\u5f00\u540e\u89e6\u53d1<\/span><\/li>\n<li><span style=\"color:#0d0016\">clicked(bool)&#xff1a;\u8fd9\u4e2a\u4e00\u822c\u662f\u9009\u9879\u6309\u94ae\u4f7f\u7528&#xff0c;\u9f20\u6807\u70b9\u51fb\u6309\u94ae\u53c8\u677e\u5f00\u540e\u89e6\u53d1&#xff0c;\u8fd8\u4f1a\u628a\u70b9\u51fb\u540e\u9009\u9879\u7684\u72b6\u6001&#xff08;\u662f\u5426\u9009\u4e2d&#xff09;\u4f5c\u4e3a\u53c2\u6570\u4f20\u7ed9\u69fd<\/span><\/li>\n<li><span style=\"color:#0d0016\">pressed()&#xff1a;\u9f20\u6807\u70b9\u51fb\u6309\u94ae\u5e76\u5728<\/span><span style=\"color:#fe2c24\">\u677e\u5f00\u4e4b\u524d<\/span><span style=\"color:#0d0016\">\u677e\u5f00\u5c31\u89e6\u53d1<\/span><\/li>\n<li><span style=\"color:#0d0016\">released()&#xff1a;\u9f20\u6807\u70b9\u51fb\u6309\u94ae\u5728<\/span><span style=\"color:#fe2c24\">\u677e\u5f00\u4e4b\u540e<\/span><span style=\"color:#0d0016\">\u89e6\u53d1<\/span><\/li>\n<li><span style=\"color:#0d0016\">toggled(bool)&#xff1a;\u9f20\u6807\u70b9\u51fb\u540e\u5982\u679c<\/span><span style=\"color:#fe2c24\">\u9009\u9879\u72b6\u6001\u6539\u53d8\u624d\u88ab\u89e6\u53d1<\/span><span style=\"color:#0d0016\">&#xff08;\u6bd4\u5982\u4ece\u9009\u4e2d\u53d8\u6210\u672a\u9009\u4e2d&#xff09;&#xff0c;\u5e76\u628a\u6539\u53d8\u540e\u7684\u72b6\u6001\u4f5c\u4e3a\u53c2\u6570\u4f20\u9012\u7ed9\u69fd<\/span><\/li>\n<hr \/>\n<h3 id=\"QCheckBox\"><span style=\"color:#0d0016\">QCheckBox<\/span><\/h3>\n<h4 id=\"%C2%A0%E8%AE%BE%E7%BD%AE%E9%80%89%E9%A1%B9%E6%98%AF%E5%90%A6%E8%A2%AB%E9%80%89%E4%B8%AD\"><span style=\"color:#0d0016\">\u00a0\u8bbe\u7f6e\u9009\u9879\u662f\u5426\u88ab\u9009\u4e2d<\/span><\/h4>\n<p>ui-&gt;a-&gt;setChecked(true); <\/p>\n<h4 id=\"%E8%AE%BE%E7%BD%AE%E9%80%89%E9%A1%B9%E6%98%AF%E5%90%A6%E5%8F%AF%E4%BB%A5%E9%80%89%E4%B8%AD\"><span style=\"color:#0d0016\">\u8bbe\u7f6e\u9009\u9879\u662f\u5426\u53ef\u4ee5\u9009\u4e2d<\/span><\/h4>\n<p>ui-&gt;a-&gt;setCheckable(false);<br \/>\n\/\/\u5373\u4f7f\u8bbe\u7f6e\u4e86\u65e0\u6cd5\u9009\u4e2d&#xff0c;\u4e5f\u4f1a\u53d1\u9001\u4fe1\u53f7&#xff0c;\u6267\u884c\u69fd <\/p>\n<p><span style=\"color:#0d0016\">\u5224\u65ad\u9009\u9879\u662f\u5426\u88ab\u9009\u4e2d<\/span><\/p>\n<p>ui-&gt;a-&gt;isChecked() <\/p>\n<p><span style=\"color:#0d0016\">\u6ce8&#xff1a;QCheckBox\u9ed8\u8ba4\u662f\u4e0d\u6392\u4ed6<\/span><\/p>\n<hr \/>\n<h2 id=\"%E6%98%BE%E7%A4%BA%E7%B1%BB%E6%8E%A7%E4%BB%B6\" style=\"background-color:transparent\"><span style=\"color:#0d0016\">\u663e\u793a\u7c7b\u63a7\u4ef6<\/span><\/h2>\n<h3 id=\"QLabel\"><span style=\"color:#0d0016\">QLabel<\/span><\/h3>\n<h4 id=\"%E8%AE%BE%E7%BD%AE%E6%96%87%E6%9C%AC%E5%86%85%E5%AE%B9\"><span style=\"color:#0d0016\">\u8bbe\u7f6e\u6587\u672c\u5185\u5bb9<\/span><\/h4>\n<p>ui-&gt;label-&gt;setText(&#034;haha&#034;); <\/p>\n<h4 id=\"%E8%AE%BE%E7%BD%AElabel%E6%96%87%E6%9C%AC%E7%9A%84%E6%A0%BC%E5%BC%8F\"><span style=\"color:#0d0016\">\u8bbe\u7f6elabel<\/span><span style=\"color:#0d0016\">\u6587\u672c\u7684\u683c\u5f0f<\/span><\/h4>\n<p>ui-&gt;label1-&gt;setTextFormat(Qt::PlainText);\/\/\u7eaf\u6587\u672c\u683c\u5f0f<br \/>\nui-&gt;label2-&gt;setTextFormat(Qt::RichText);\/\/\u5bcc\u6587\u672c&#xff08;html\u683c\u5f0f&#xff09;<br \/>\nui-&gt;label3-&gt;setTextFormat(Qt::MarkdownText);\/\/Markdown\u6587\u672c\u683c\u5f0f<\/p>\n<p>ui-&gt;label1-&gt;setText(&#034;\u8fd9\u662f\u7eaf\u6587\u672c&#034;);<br \/>\nui-&gt;label2-&gt;setText(&#034;&lt;b&gt;\u8fd9\u662f\u5bcc\u6587\u672c&lt;\/b&gt;&#034;);\/\/\u4f1a\u6309\u7167html\u8bed\u6cd5\u89e3\u6790\u5e76\u663e\u793a\u51fa\u76f8\u5e94\u6837\u5f0f\u7684\u6587\u672c<br \/>\nui-&gt;label3-&gt;setText(&#034;# \u8fd9\u662fMarkdown\u6587\u672c&#034;);\/\/\u4f1a\u6309\u7167Markdown\u8bed\u6cd5\u89e3\u6790\u5e76\u663e\u793a\u51fa\u76f8\u5e94\u6837\u5f0f\u7684\u6587\u672c <\/p>\n<h4 id=\"%E7%BB%99label%E6%B7%BB%E5%8A%A0%E5%9B%BE%E7%89%87\"><span style=\"color:#0d0016\">\u7ed9label\u6dfb\u52a0\u56fe\u7247<\/span><\/h4>\n<p>QPixmap pix(&#034;:\/rose.jpg&#034;);<br \/>\nlabel-&gt;setPixmap(pix); <\/p>\n<h4 id=\"%E8%AE%BE%E7%BD%AE%E5%86%85%E5%AE%B9(%E4%B8%BB%E8%A6%81%E6%8C%87%E5%9B%BE%E7%89%87)%E8%87%AA%E5%8A%A8%E6%8B%89%E4%BC%B8%E5%A1%AB%E5%85%85%E6%95%B4%E4%B8%AAlabel\"><span style=\"color:#0d0016\">\u8bbe\u7f6e\u5185\u5bb9(\u4e3b\u8981\u6307\u56fe\u7247)\u81ea\u52a8\u62c9\u4f38\u586b\u5145\u6574\u4e2alabel<\/span><\/h4>\n<p>label-&gt;setScaledContents(true); <\/p>\n<h4 id=\"%E8%AE%BE%E7%BD%AE%E6%96%87%E6%9C%AC%E5%AF%B9%E9%BD%90%E6%96%B9%E5%BC%8F\"><span style=\"color:#0d0016\">\u8bbe\u7f6e\u6587\u672c\u5bf9\u9f50\u65b9\u5f0f<\/span><\/h4>\n<p>ui-&gt;label_1-&gt;setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);\/\/\u6c34\u5e73\u5782\u76f4\u5c45\u4e2d<br \/>\nui-&gt;label_2-&gt;setAlignment(Qt::AlignRight);\/\/\u9760\u53f3\u5bf9\u9f50<br \/>\nui-&gt;label_3-&gt;setAlignment(Qt::AlignLeft | Qt::AlignTop);\/\/\u5de6\u4e0a\u5bf9\u9f50<br \/>\nui-&gt;label_4-&gt;setAlignment(Qt::AlignBottom);\/\/\u9760\u4e0b\u5bf9\u9f50 <\/p>\n<p><span style=\"color:#0d0016\">\u6548\u679c\u5982\u4e0b&#xff1a;<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"641\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260207090615-69870087acfc0.png\" width=\"840\" \/><\/p>\n<hr \/>\n<h4 id=\"%E8%AE%BE%E7%BD%AE%E6%96%87%E6%9C%AC%E8%87%AA%E5%8A%A8%E6%8D%A2%E8%A1%8C\"><span style=\"color:#0d0016\">\u8bbe\u7f6e\u6587\u672c\u81ea\u52a8\u6362\u884c<\/span><\/h4>\n<p> ui-&gt;label_1-&gt;setWordWrap(true); <\/p>\n<p><span style=\"color:#0d0016\">\u4e00\u822c\u6765\u8bf4\u6587\u672c\u957f\u5ea6\u8d85\u8fc7label\u7684width\u540e\u5c31\u4f1a\u663e\u793a\u4e0d\u51fa\u6765&#xff0c;\u81ea\u52a8\u6362\u884c\u5c31\u662f\u8ba9\u8d85\u51fa\u7684\u6587\u672c\u5728\u4e0b\u4e00\u884c\u663e\u793a\u3002<\/span><\/p>\n<hr \/>\n<h4 id=\"%E8%AE%BE%E7%BD%AE%E6%96%87%E6%9C%AC%E7%BC%A9%E8%BF%9B\"><span style=\"color:#0d0016\">\u8bbe\u7f6e\u6587\u672c\u7f29\u8fdb<\/span><\/h4>\n<p>ui-&gt;label_1-&gt;setIndent(20);\/\/ \u5355\u4f4d\u662f\u50cf\u7d20 <\/p>\n<p><span style=\"color:#0d0016\">\u5982\u679c\u8bbe\u7f6e\u4e86\u6362\u884c&#xff0c;\u6bcf\u4e00\u884c\u90fd\u4f1a\u6709\u7f29\u8fdb<\/span><\/p>\n<h4 id=\"\"><\/h4>\n<hr \/>\n<h4 id=\"%E8%AE%BE%E7%BD%AE%E5%86%85%E9%83%A8%E6%96%87%E6%9C%AC%E5%92%8C%E6%96%87%E6%9C%AC%E6%A1%86%E7%9A%84%E8%BE%B9%E8%B7%9D\"><span style=\"color:#0d0016\">\u8bbe\u7f6e\u5185\u90e8\u6587\u672c\u548c\u6587\u672c\u6846\u7684\u8fb9\u8ddd<\/span><\/h4>\n<p>ui-&gt;label_1-&gt;setMargin(10);\/\/\u5355\u4f4d\u662f\u50cf\u7d20 <\/p>\n<p><span style=\"color:#0d0016\">\u6587\u672c\u5185\u5bb9\u4e0a\u4e0b\u5de6\u53f3\u65b9\u5411\u548c\u6587\u672c\u6846\u7684\u8ddd\u79bb<\/span><\/p>\n<hr \/>\n<h4 id=\"%E8%AE%BE%E7%BD%AE%E6%A0%87%E7%AD%BE%E7%9A%84%E4%BC%99%E4%BC%B4\"><span style=\"color:#0d0016\">\u8bbe\u7f6e\u6807\u7b7e\u7684\u4f19\u4f34<\/span><\/h4>\n<p>ui-&gt;c-&gt;setText(&#034;&amp;A&#034;);\/\/\u628a\u6807\u7b7e\u6587\u672c\u8bbe\u7f6e\u6210&#034;&amp;&#034;&#043;\u5b57\u6bcd<br \/>\nui-&gt;c-&gt;setBuddy(ui-&gt;a);\/\/\u8bbe\u7f6e\u6807\u7b7e\u7684\u4f19\u4f34\u4e3a\u4e00\u4e2a\u6309\u94ae&#xff0c;\u8fd9\u6837\u53ef\u4ee5\u901a\u8fc7Alt&#043;A\u7684\u65b9\u5f0f\u6fc0\u6d3b\u6807\u7b7e\u7684\u4f19\u4f34\u5373\u8be5\u6309\u94ae <\/p>\n<p>\u6ce8&#xff1a;QLabel\u6ca1\u6709\u6eda\u52a8\u6761<\/p>\n<hr \/>\n<h3 id=\"QLCDNumber\"><span style=\"color:#0d0016\">QLCDNumber<\/span><\/h3>\n<p><span style=\"color:#0d0016\">\u8fd9\u91cc\u6211\u4eec\u53ea\u5c55\u793a\u4e00\u4e2a\u4f7f\u7528QLCDNumber\u7684\u5012\u8ba1\u65f6\u793a\u4f8b&#xff1a;<\/span><\/p>\n<p>Widget::Widget(QWidget *parent)<br \/>\n    : QWidget(parent)<br \/>\n    , ui(new Ui::Widget)<br \/>\n{<br \/>\n    ui-&gt;setupUi(this);<\/p>\n<p>    timer &#061; new QTimer(this);\/\/\u521b\u5efa\u5b9a\u65f6\u5668\u5bf9\u8c61&#xff0c;\u8be5\u5b9a\u65f6\u5668\u81ea\u5e26\u4e00\u79cd\u4fe1\u53f7timout()<br \/>\n    ui-&gt;number-&gt;display(10);\/\/\u8bbe\u7f6eQLCDNumber\u7684\u503c\u4e3a10<\/p>\n<p>    connect(timer,&amp;QTimer::timeout,this,&amp;Widget::handler);\/\/\u628a\u5b9a\u65f6\u5668\u7684\u4fe1\u53f7\u548c\u69fd\u5173\u8054\u8d77\u6765<\/p>\n<p>    timer-&gt;start(1000);\/\/\u8ba9\u5b9a\u65f6\u5668\u5f00\u59cb\u53d1\u4fe1\u53f7&#xff0c;\u5e76\u8bbe\u7f6e\u4fe1\u53f7\u53d1\u5c04\u7684\u65f6\u95f4\u95f4\u9694&#xff0c;ms\u4e3a\u5355\u4f4d<br \/>\n}<\/p>\n<p>void Widget::handler()<br \/>\n{<br \/>\n    ui-&gt;number-&gt;display(ui-&gt;number-&gt;intValue()-1);\/\/\u6bcf\u96941\u79d2\u51cf\u4e00<br \/>\n    if(ui-&gt;number-&gt;intValue() &#061;&#061; 0)<br \/>\n    {<br \/>\n        timer-&gt;stop();\/\/\u8ba9\u5b9a\u65f6\u5668\u505c\u6b62\u53d1\u9001\u4fe1\u53f7<br \/>\n    }<br \/>\n} <\/p>\n<p><span style=\"color:#0d0016\">\u4e0b\u9762\u662f\u4ed6\u7684\u5176\u4ed6\u4e3b\u8981\u5c5e\u6027&#xff0c;\u8981\u8bbe\u7f6e\u7684\u65f6\u5019\u76f4\u63a5\u4f7f\u7528set&#043;\u5c5e\u6027\u540d(\u9996\u5b57\u6bcd\u5927\u5199\u5373\u53ef)&#xff1a;<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"585\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260207090615-69870087e6bca.png\" width=\"589\" \/><\/p>\n<p>\u6ce8&#xff1a;<span style=\"color:#1f2329\">QLCDNumber\u4e2d\u6709value (double\u7c7b\u578b)\u548c intValue\u4e24\u4e2a\u5c5e\u6027\u8868\u793a\u503c&#xff0c;\u4e14\u4ed6\u4eec\u662f\u8054\u52a8\u7684&#xff0c;\u6bd4\u5982value\u4e3a1.5&#xff0c;inValue\u5c31\u4e3a2\u3002\u8bbe\u7f6eQLCDNumber\u4e2dvalue \u548c intValue\u7684\u2f45\u6cd5\u540d\u5b57\u4e3adisplay , \u800c\u4e0d\u662fsetValue<\/span><span style=\"color:#1f2329\">\u6216\u8005setIntValue\u3002<\/span><\/p>\n<hr \/>\n<h3 id=\"%E9%A2%98%E5%A4%96%E8%AF%9D%E2%80%94%E2%80%94%E5%85%B3%E4%BA%8EQt%E4%B8%AD%E7%BA%BF%E7%A8%8B%E4%BF%AE%E6%94%B9%E7%95%8C%E9%9D%A2\"><span style=\"color:#1f2329\">\u9898\u5916\u8bdd\u2014\u2014\u5173\u4e8eQt\u4e2d\u7ebf\u7a0b\u4fee\u6539\u754c\u9762<\/span><\/h3>\n<p><span style=\"color:#fe2c24\">\u5728Qt\u4e2d\u4e3a\u4e86\u9632\u6b62\u7ebf\u7a0b\u5e72\u6270&#xff0c;\u53ea\u6709\u4e3b\u7ebf\u7a0b\u624d\u80fd\u4fee\u6539\u754c\u9762&#xff08;\u4f46\u53ef\u4ee5\u521b\u5efa\u7ebf\u7a0b&#xff09;<\/span><span style=\"color:#0d0016\">&#xff0c;QApplication\u5bf9\u8c61\u5728main\u51fd\u6570\u8c03\u7528exec\u51fd\u6570\u540e&#xff0c;\u4e3b\u7ebf\u7a0b\u5f00\u59cb\u65f6\u95f4\u5faa\u73af&#xff0c;\u4f9d\u6b64\u5904\u7406\u5bf9\u754c\u9762\u7684\u4fee\u6539\u4efb\u52a1<\/span><span style=\"color:#1f2329\">&#xff08;<\/span><span style=\"color:#fe2c24\">\u8fd9\u610f\u5473\u7740\u4ed6\u662f\u5355\u7ebf\u7a0b\u5904\u7406\u6240\u6709\u4e8b\u4ef6\u7684&#xff0c;\u4e00\u4f46\u67d0\u4e8b\u4ef6\u82b1\u8d39\u8f83\u957f\u65f6\u95f4\u5c31\u4f1a\u963b\u585e<\/span><span style=\"color:#1f2329\">&#xff09;<\/span><span style=\"color:#0d0016\">&#xff0c;\u56e0\u6b64\u7ebf\u7a0b&#043;sleep\u5b9e\u73b0\u5012\u8ba1\u65f6\u7684\u65b9\u6cd5\u884c\u4e0d\u901a\u3002<\/span><\/p>\n<h3 id=\"QProgressBar\"><span style=\"color:#0d0016\">QProgressBar<\/span><\/h3>\n<p><span style=\"color:#0d0016\">\u901a\u8fc7\u4e00\u4e2a\u8fdb\u5ea6\u6761\u7a0b\u5e8f\u6765\u4e86\u89e3\u5b83\u7684\u57fa\u672c\u4f7f\u7528<\/span><span style=\"color:#0d0016\">&#xff0c;\u8981\u8bbe\u7f6e\u7684\u65f6\u5019\u76f4\u63a5\u4f7f\u7528set&#043;\u5c5e\u6027\u540d(\u9996\u5b57\u6bcd\u5927\u5199\u5373\u53ef)<\/span><span style=\"color:#0d0016\">&#xff1a;<\/span><\/p>\n<p>Widget::Widget(QWidget *parent)<br \/>\n    : QWidget(parent)<br \/>\n    , ui(new Ui::Widget)<br \/>\n{<br \/>\n    ui-&gt;setupUi(this);<\/p>\n<p>    \/\/\u8fdb\u5ea6\u6761\u5bf9\u4e8e\u6837\u5f0f\u7684\u8bbe\u7f6e\u6709\u7279\u5b9a\u7684\u683c\u5f0f\u5c31\u50cf\u4e0b\u9762<br \/>\n    ui-&gt;progressBar-&gt;setStyleSheet(&#034;QProgressBar::chunk {background-color: #05B8CC;}&#034;);<br \/>\n    timer &#061; new QTimer(this);\/\/\u521b\u5efa\u5b9a\u65f6\u5668\u5bf9\u8c61&#xff0c;\u8be5\u5b9a\u65f6\u5668\u81ea\u5e26\u4e00\u79cd\u4fe1\u53f7timout()<br \/>\n    connect(timer,&amp;QTimer::timeout,this,&amp;Widget::handler);\/\/\u628a\u5b9a\u65f6\u5668\u7684\u4fe1\u53f7\u548c\u69fd\u5173\u8054\u8d77\u6765<\/p>\n<p>    timer-&gt;start(100);\/\/\u8ba9\u5b9a\u65f6\u5668\u5f00\u59cb\u53d1\u4fe1\u53f7&#xff0c;\u5e76\u8bbe\u7f6e\u4fe1\u53f7\u53d1\u5c04\u7684\u65f6\u95f4\u95f4\u9694<br \/>\n}<\/p>\n<p>void Widget::handler()<br \/>\n{<br \/>\n    ui-&gt;progressBar-&gt;setValue(ui-&gt;progressBar-&gt;value()&#043;1);\/\/\u8ba9\u8fdb\u5ea6\u6761\u7684\u503c&#043;1<br \/>\n    if(ui-&gt;progressBar-&gt;value() &#061;&#061; 0)<br \/>\n    {<br \/>\n        timer-&gt;stop();\/\/\u8ba9\u5b9a\u65f6\u5668\u505c\u6b62\u53d1\u9001\u4fe1\u53f7<br \/>\n    }<br \/>\n} <\/p>\n<p><span style=\"color:#0d0016\">\u4e0b\u9762\u662f\u5b83\u7684\u4e3b\u8981\u5c5e\u6027&#xff1a;<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"531\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260207090616-698700880ec07.png\" width=\"584\" \/><\/p>\n<hr \/>\n<h3 id=\"QCalendarWidget\"><span style=\"color:#0d0016\">QCalendarWidget<\/span><\/h3>\n<p><span style=\"color:#0d0016\">\u901a\u8fc7\u4e00\u4e2a\u793a\u4f8b\u6211\u4eec\u4f7f\u7528\u4e00\u4e0bQCalendarWidget&#xff1a;<\/span><\/p>\n<p>\/\/\u8fd9\u662f\u65e5\u671f\u9009\u62e9\u6539\u53d8\u7684\u69fd\u51fd\u6570<br \/>\nvoid Widget::on_calendarWidget_selectionChanged()<br \/>\n{<br \/>\n    \/\/\u83b7\u53d6\u5f53\u524d\u9009\u62e9\u7684\u65e5\u671f<br \/>\n    QDate date &#061; ui-&gt;calendarWidget-&gt;selectedDate();<br \/>\n    \/\/\u5c06\u5f53\u524d\u9009\u4e2d\u7684\u65e5\u671f\u663e\u793a\u5230\u6807\u7b7e\u4e0a<br \/>\n    ui-&gt;label-&gt;setText(date.toString());<br \/>\n} <\/p>\n<p> <img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"299\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260207090616-69870088276f2.png\" width=\"530\" \/><\/p>\n<p><span style=\"color:#0d0016\">\u4e0b\u9762\u662fQCalendarWidget\u7684\u4e00\u4e9b\u4e3b\u8981\u5c5e\u6027\u548c\u5b83\u81ea\u5e26\u7684\u4fe1\u53f7&#xff0c;\u53ef\u4ee5\u67e5\u770b\u6587\u6863\u8fdb\u884c\u4f7f\u7528&#xff1a;<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"641\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260207090616-698700883adde.png\" width=\"771\" \/><\/p>\n<hr \/>\n<h2 id=\"%E8%BE%93%E5%85%A5%E7%B1%BB%E6%8E%A7%E4%BB%B6\"><span style=\"color:#0d0016\">\u8f93\u5165\u7c7b\u63a7\u4ef6<\/span><\/h2>\n<h3 id=\"QLineEdit\" style=\"background-color:transparent\"><span style=\"color:#0d0016\">QLineEdit<\/span><\/h3>\n<p><span style=\"color:#0d0016\">\u4e0b\u9762\u662f\u5176\u4e3b\u8981\u5c5e\u6027&#xff1a;<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"641\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260207090616-698700887f0ed.png\" width=\"1408\" \/><\/p>\n<p><span style=\"color:#0d0016\">\u4e0b\u9762\u662f\u4e00\u4e2a\u4f8b\u5b50&#xff1a;<\/span><\/p>\n<p>Widget::Widget(QWidget *parent)<br \/>\n    : QWidget(parent)<br \/>\n    , ui(new Ui::Widget)<br \/>\n{<br \/>\n    ui-&gt;setupUi(this);<\/p>\n<p>    ui-&gt;lineEdit_id-&gt;setPlaceholderText(&#034;\u8bf7\u8f93\u5165\u7528\u6237\u540d&#034;);\/\/\u8bbe\u7f6e\u8f93\u5165\u6846\u4e3a\u7a7a\u7684\u63d0\u793a<br \/>\n    ui-&gt;lineEdit_id-&gt;setClearButtonEnabled(true);\/\/\u542f\u7528\u6e05\u7a7a\u6309\u94ae<br \/>\n    ui-&gt;lineEdit_id-&gt;setMaxLength(5);<\/p>\n<p>    ui-&gt;lineEdit_pass-&gt;setPlaceholderText(&#034;\u8bf7\u8f93\u5165\u5bc6\u7801&#034;);\/\/\u8bbe\u7f6e\u8f93\u5165\u6846\u4e3a\u7a7a\u7684\u63d0\u793a<br \/>\n    ui-&gt;lineEdit_pass-&gt;setClearButtonEnabled(true);\/\/\u542f\u7528\u6e05\u7a7a\u6309\u94ae<br \/>\n    ui-&gt;lineEdit_pass-&gt;setEchoMode(QLineEdit::Password);\/\/\u8bbe\u7f6e\u6587\u672c\u7684\u663e\u793a\u65b9\u5f0f\u662f\u5bc6\u7801\u65b9\u5f0f&#xff0c;\u7528\u7b26\u53f7\u4ee3\u66ff\u7528\u6237\u8f93\u5165\u7684\u5185\u5bb9\u5448\u73b0<\/p>\n<p>    ui-&gt;lineEdit_phone-&gt;setPlaceholderText(&#034;\u8bf7\u8f93\u5165\u7535\u8bdd\u53f7\u7801&#034;);\/\/\u8bbe\u7f6e\u8f93\u5165\u6846\u4e3a\u7a7a\u7684\u63d0\u793a<br \/>\n    ui-&gt;lineEdit_phone-&gt;setClearButtonEnabled(true);\/\/\u542f\u7528\u6e05\u7a7a\u6309\u94ae<br \/>\n    ui-&gt;lineEdit_phone-&gt;setInputMask(&#034;000-0000-0000&#034;);\/\/\u8bbe\u7f6e\u5185\u5bb9\u683c\u5f0f\u7ea6\u675f&#xff0c;0\u8868\u793a\u8be5\u4f4d\u7f6e\u53ea\u80fd\u662f\u6570\u5b57<br \/>\n}<br \/>\n\/\/\u8bbe\u7f6e\u6309\u94ae\u7684\u70b9\u51fb\u4e8b\u4ef6<br \/>\nvoid Widget::on_pushButton_clicked()<br \/>\n{<br \/>\n    \/\/\u83b7\u53d6\u6027\u522b\u4fe1\u606f<br \/>\n    QString gender &#061; ui-&gt;radioButton_male-&gt;isChecked() ? &#034;\u7537&#034;:&#034;\u5973&#034;;<\/p>\n<p>    \/\/\u6253\u5370\u8f93\u5165\u6846\u7684\u4fe1\u606f<br \/>\n    qDebug()&lt;&lt;&#034;\u59d3\u540d&#034;&lt;&lt;ui-&gt;lineEdit_id-&gt;text();<br \/>\n    qDebug()&lt;&lt;&#034;\u5bc6\u7801&#034;&lt;&lt;ui-&gt;lineEdit_pass-&gt;text();<br \/>\n    qDebug()&lt;&lt;&#034;\u7535\u8bdd&#034;&lt;&lt;ui-&gt;lineEdit_phone-&gt;text();<br \/>\n    qDebug()&lt;&lt;&#034;\u6027\u522b&#034;&lt;&lt;gender;<br \/>\n}<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"500\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260207090616-69870088e116a.png\" width=\"1029\" \/><\/p>\n<p><span style=\"color:#0d0016\">\u4e0b\u9762\u662f\u53e6\u4e00\u4e2a\u4f8b\u5b50&#xff1a;<\/span><\/p>\n<p>Widget::Widget(QWidget *parent)<br \/>\n    : QWidget(parent)<br \/>\n    , ui(new Ui::Widget)<br \/>\n{<br \/>\n    ui-&gt;setupUi(this);<\/p>\n<p>    \/\/\u8bbe\u7f6e\u4e24\u4e2a\u8f93\u5165\u6846\u4e3a\u5bc6\u7801\u6a21\u5f0f&#xff0c;\u9632\u6b62\u5bc6\u7801\u56de\u663e<br \/>\n    ui-&gt;lineEdit-&gt;setEchoMode(QLineEdit::Password);<br \/>\n    ui-&gt;lineEdit_2-&gt;setEchoMode(QLineEdit::Password);<br \/>\n}<br \/>\n\/\/\u6bd4\u8f83\u4e24\u4e2a\u8f93\u5165\u6846\u7684\u5bc6\u7801\u662f\u5426\u76f8\u7b49<br \/>\nvoid Widget::compare()<br \/>\n{<br \/>\n    QString x1 &#061; ui-&gt;lineEdit-&gt;text();<br \/>\n    QString x2 &#061; ui-&gt;lineEdit_2-&gt;text();<\/p>\n<p>    if(x1.isEmpty() &amp;&amp; x2.isEmpty())<br \/>\n    {<br \/>\n        ui-&gt;label-&gt;setText(&#034;\u5f53\u524d\u8f93\u5165\u4e3a\u7a7a&#034;);<br \/>\n    }<br \/>\n    else if(x1 &#061;&#061; x2)<br \/>\n    {<br \/>\n        ui-&gt;label-&gt;setText(&#034;\u4e24\u6b21\u5bc6\u7801\u4e00\u81f4&#034;);<br \/>\n    }<br \/>\n    else<br \/>\n    {<br \/>\n        ui-&gt;label-&gt;setText(&#034;\u4e24\u6b21\u5bc6\u7801\u4e0d\u4e00\u81f4&#034;);<br \/>\n    }<br \/>\n}<br \/>\n\/\/\u8bbe\u7f6e\u8f93\u5165\u6846\u7684\u6587\u672c\u6539\u53d8\u4fe1\u53f7\u5bf9\u5e94\u7684\u69fd<br \/>\nvoid Widget::on_lineEdit_textEdited(const QString &amp;arg1)<br \/>\n{<br \/>\n    compare();<br \/>\n}<br \/>\n\/\/\u8bbe\u7f6e\u8f93\u5165\u6846\u7684\u6587\u672c\u6539\u53d8\u4fe1\u53f7\u5bf9\u5e94\u7684\u69fd<br \/>\nvoid Widget::on_lineEdit_2_textEdited(const QString &amp;arg1)<br \/>\n{<br \/>\n    compare();<br \/>\n}<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"470\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260207090617-69870089355c2.png\" width=\"566\" \/><\/p>\n<\/p>\n<hr \/>\n<h3 id=\"%E9%A2%98%E5%A4%96%E8%AF%9D%E2%80%94%E2%80%94%E5%85%B3%E4%BA%8E%E6%AD%A3%E5%88%99%E8%A1%A8%E8%BE%BE%E5%BC%8F%E9%AA%8C%E8%AF%81%E8%BE%93%E5%85%A5%E6%A1%86%E6%95%B0%E6%8D%AE\" style=\"background-color:transparent\"><span style=\"color:#0d0016\">\u9898\u5916\u8bdd\u2014\u2014\u5173\u4e8e\u6b63\u5219\u8868\u8fbe\u5f0f\u9a8c\u8bc1\u8f93\u5165\u6846\u6570\u636e<\/span><\/h3>\n<p><span style=\"color:#0d0016\">QlineEdit\u4e2d\u7684inputMask\u5143\u7d20\u4e0a\u9762\u6211\u4eec\u5df2\u7ecf\u4f7f\u7528\u8fc7\u4e86&#xff0c;\u4f46\u662f\u4ed6\u53ea\u80fd\u8fdb\u884c\u7b80\u5355\u7684\u9a8c\u8bc1&#xff0c;\u6b63\u5219\u8868\u8fbe\u5f0f\u9a8c\u8bc1\u624d\u662f\u7ecf\u5e38\u88ab\u4f7f\u7528\u7684\u8f93\u5165\u6846\u6570\u636e\u9a8c\u8bc1\u65b9\u6cd5\u3002<\/span><\/p>\n<p> <span style=\"color:#0d0016\">\u6b63\u5219\u8868\u8fbe\u5f0f\u662f\u2f00\u79cd\u5728\u8ba1\u7b97\u673a\u4e2d\u5e38\u7528\u7684, <\/span><br \/>\n <span style=\"color:#fe2c24\">\u4f7f\u7528\u7279\u6b8a\u5b57\u7b26\u63cf\u8ff0\u2f00\u4e2a\u5b57\u7b26\u4e32\u7684\u7279\u5f81\u7684\u673a\u5236<\/span><br \/>\n <span style=\"color:#0d0016\">\u3002\u00a0\u5728\u8fdb\u2f8f\u5b57 <\/span><\/p>\n<p> <span style=\"color:#0d0016\">\u7b26\u4e32\u5339\u914d\u65f6\u975e\u5e38\u6709\u7528\u3002<\/span><br \/>\n <span style=\"color:#0d0016\">\u6b63\u5219\u8868\u8fbe\u5f0f\u7684\u8bed\u6cd5\u8fd8\u6bd4\u8f83\u590d\u6742, \u2f00\u822c\u90fd\u662f\u968f\u7528\u968f\u67e5, \u4e0d\u9700\u8981\u80cc\u4e0b\u6765&#xff1a;<\/span><\/p>\n<p>   <span style=\"color:#0d0016\">\u6b63\u5219\u8868\u8fbe\u5f0f\u6587\u6863&#xff1a;https:\/\/learn.microsoft.com\/zh-cn\/previous-versions\/visualstudio\/visual-studio-2008\/ae5bf541(v&#061;vs.90)?redirectedfrom&#061;MSDN<\/span><br \/>\n   <span style=\"color:#0d0016\"> <\/span><\/p>\n<p>   <span style=\"color:#0d0016\">\u6b63\u5219\u8868\u8fbe\u5f0f\u5728\u7ebf\u5de5\u5177: https:\/\/regextester.buyaocha.com\/<\/span><\/p>\n<p><span style=\"color:#0d0016\">\u63a5\u4e0b\u6765\u662f\u5728Qt\u4e2d\u4f7f\u7528\u7b80\u5355\u6b63\u5219\u8868\u8fbe\u5f0f\u8fdb\u884c\u624b\u673a\u53f7\u7801\u8f93\u5165\u9a8c\u8bc1\u7684\u793a\u4f8b\u7a0b\u5e8f&#xff1a;<\/span><\/p>\n<p> Widget::Widget(QWidget *parent)<br \/>\n    : QWidget(parent)<br \/>\n    , ui(new Ui::Widget)<br \/>\n{<br \/>\n    ui-&gt;setupUi(this);<\/p>\n<p>    \/\/\u521b\u5efa\u4e00\u4e2a\u6b63\u5219\u8868\u8fbe\u5f0f<br \/>\n    QRegExp regexp(&#034;^1\\\\\\\\d{10}$&#034;);\/\/^1\u8868\u793a\u5f00\u5934\u5fc5\u987b\u662f1&#xff0c;\\\\d{10}\u8868\u793a\u63a5\u4e0b\u6765\u662f10\u4e2a\u6570\u5b57&#xff08;\u591a\u52a0\u4e00\u4e2a\\\\\u8868\u793a\u8f6c\u4e49&#xff09;&#xff0c;$\u662f\u7ed3\u675f\u7b26<\/p>\n<p>    \/\/\u521b\u5efa\u4e00\u4e2a\u9a8c\u8bc1\u5668\u5e76\u8bbe\u7f6e\u8fdb\u8f93\u5165\u6846\u63a7\u4ef6\u4e2d&#xff0c;\u9a8c\u8bc1\u5668\u7684\u751f\u547d\u5468\u671f\u4e2a\u8f93\u5165\u6846\u4e00\u6837<br \/>\n    ui-&gt;lineEdit-&gt;setValidator(new QRegExpValidator(regexp));<br \/>\n}<\/p>\n<p>\/\/\u8bbe\u7f6e\u8f93\u5165\u6846\u6587\u672c\u6570\u636e\u6539\u53d8\u7684\u4fe1\u53f7\u5bf9\u5e94\u7684\u69fd\u51fd\u6570<br \/>\nvoid Widget::on_lineEdit_textChanged(const QString &amp;arg1)<br \/>\n{<br \/>\n    QString x &#061; arg1;<br \/>\n    int pos;<\/p>\n<p>    \/\/\u83b7\u53d6lineEdit\u4e2d\u7684\u9a8c\u8bc1\u5668\u5e76\u4e14\u8c03\u7528\u9a8c\u8bc1\u51fd\u6570&#xff0c;\u6210\u529f\u5219\u8fd4\u56detrue&#xff0c;\u5931\u8d25\u5219\u8fd4\u56defalse\u5e76\u628a\u7b2c\u4e00\u4e2a\u4e0d\u5339\u914d\u7684\u4f4d\u7f6e\u8fd4\u56de\u5230pos\u4e2d\u3002<br \/>\n    if(ui-&gt;lineEdit-&gt;validator()-&gt;validate(x,pos) &#061;&#061; QValidator::Acceptable)<br \/>\n    {<br \/>\n        \/\/\u5982\u679c\u5339\u914d\u4e86\u5c31\u89e3\u5f00\u6309\u94ae\u9650\u5236<br \/>\n        ui-&gt;pushButton-&gt;setEnabled(true);<br \/>\n    }<br \/>\n    else<br \/>\n    {<br \/>\n        \/\/\u4e0d\u5339\u914d\u5c31\u7981\u7528\u6309\u94ae<br \/>\n        ui-&gt;pushButton-&gt;setEnabled(false);<br \/>\n    }<\/p>\n<p>}<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"465\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260207090617-698700894988f.png\" width=\"1120\" \/><\/p>\n<hr \/>\n<h3 id=\"QTextEdit\" style=\"background-color:transparent\"><span style=\"color:#0d0016\">QTextEdit<\/span><\/h3>\n<p><span style=\"color:#0d0016\">QTextEdit\u548cQPlainTextEdit\u5c5e\u6027\u548c\u4fe1\u53f7\u5dee\u4e0d\u591a&#xff0c;\u53ea\u4e0d\u8fc7QTextEdit\u652f\u6301\u5bcc\u6587\u672c&#xff08;\u4e5f\u5c31\u662fhtml\u548cMarkDown\u7b49\u8bed\u6cd5&#xff09;\u800cQPlainTextEdit\u53ea\u652f\u6301\u7eaf\u6587\u672c<\/span><\/p>\n<p><span style=\"color:#0d0016\">\u4e0b\u9762\u662f\u76f8\u5173\u5c5e\u6027\u548cQTextEdit\u81ea\u5e26\u4fe1\u53f7&#xff1a;<\/span><\/p>\n<p><span style=\"color:#0d0016\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"760\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260207090617-698700897c3ef.png\" width=\"1401\" \/><\/span><\/p>\n<p><span style=\"color:#0d0016\">\u4e0b\u9762\u662f\u5199\u7684\u4e00\u4e9b\u6d4b\u8bd5\u4fe1\u53f7\u7684\u4ee3\u7801&#xff1a;<\/span><\/p>\n<p>void Widget::on_textEdit_textChanged()<br \/>\n{<br \/>\n    qDebug()&lt;&lt;&#034;\u5f53\u524d\u6587\u672c\u5185\u5bb9&#034;&lt;&lt;ui-&gt;textEdit-&gt;toPlainText();<br \/>\n}<\/p>\n<p>void Widget::on_textEdit_cursorPositionChanged()<br \/>\n{<br \/>\n    QTextCursor cursor &#061; ui-&gt;textEdit-&gt;textCursor();<br \/>\n    qDebug()&lt;&lt;&#034;\u5149\u6807\u4f4d\u7f6e&#034;&lt;&lt;cursor.position();<br \/>\n}<\/p>\n<p>void Widget::on_textEdit_selectionChanged()<br \/>\n{<br \/>\n    QTextCursor cursor &#061; ui-&gt;textEdit-&gt;textCursor();<br \/>\n    qDebug()&lt;&lt;&#034;\u9009\u4e2d\u7684\u5185\u5bb9\u53d8\u6210\u4e86:&#034;&lt;&lt;cursor.selectedText();<br \/>\n}<\/p>\n<p>void Widget::on_textEdit_undoAvailable(bool b)<br \/>\n{<br \/>\n      qDebug()&lt;&lt;&#034;\u53ef\u4ee5\u8fdb\u884cundo\u64cd\u4f5c\u4e86?&#034;&lt;&lt;b;<br \/>\n}<\/p>\n<p>void Widget::on_textEdit_redoAvailable(bool b)<br \/>\n{<br \/>\n    qDebug()&lt;&lt;&#034;\u53ef\u4ee5\u8fdb\u884credo\u64cd\u4f5c\u4e86?&#034;&lt;&lt;b;<br \/>\n}<\/p>\n<p>void Widget::on_textEdit_copyAvailable(bool b)<br \/>\n{<br \/>\n    qDebug()&lt;&lt;&#034;\u9009\u4e2d\u4e86&#xff1f;&#034;&lt;&lt;b;<br \/>\n} <\/p>\n<p><span style=\"color:#0d0016\">\u6ce8\u610f&#xff1a;QTextEdit\u83b7\u53d6\u6587\u672c\u7684\u65b9\u5f0f\u662ftoPlainText(),toHtmlText()\u7b49&#xff0c;\u800c\u4e0d\u662ftext()\u3002<\/span><\/p>\n<hr \/>\n<h3 id=\"QComboBox\" style=\"background-color:transparent\"><span style=\"color:#0d0016\">QComboBox<\/span><\/h3>\n<p><span style=\"color:#0d0016\">\u4e0b\u9762\u662fQComboBox\u7684\u6838\u5fc3\u5c5e\u6027&#xff0c;\u65b9\u6cd5&#xff0c;\u4ee5\u53ca\u4fe1\u53f7<\/span><span style=\"color:#0d0016\">&#xff1a;<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"588\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260207090617-69870089e5436.png\" width=\"1381\" \/><\/p>\n<p><span style=\"color:#0d0016\">\u4e0b\u9762\u662f\u4e00\u4e2a\u4f7f\u7528\u7684\u4f8b\u5b50&#xff1a;<\/span><\/p>\n<p>Widget::Widget(QWidget *parent)<br \/>\n    : QWidget(parent)<br \/>\n    , ui(new Ui::Widget)<br \/>\n{<br \/>\n    ui-&gt;setupUi(this);<\/p>\n<p>    ui-&gt;comboBox_1-&gt;addItem(&#034;\u9ea6\u8fa3\u9e21\u817f\u5821&#034;);<br \/>\n    ui-&gt;comboBox_1-&gt;addItem(&#034;\u725b\u8089\u5821&#034;);<br \/>\n    ui-&gt;comboBox_1-&gt;addItem(&#034;\u867e\u5821&#034;);<\/p>\n<p>    ui-&gt;comboBox_2-&gt;addItem(&#034;\u85af\u6761&#034;);<br \/>\n    ui-&gt;comboBox_2-&gt;addItem(&#034;\u571f\u8c46&#034;);<br \/>\n    ui-&gt;comboBox_2-&gt;addItem(&#034;\u86cb\u631e&#034;);<\/p>\n<p>    ui-&gt;comboBox_3-&gt;addItem(&#034;\u53ef\u4e50&#034;);<br \/>\n    ui-&gt;comboBox_3-&gt;addItem(&#034;\u96ea\u78a7&#034;);<br \/>\n}<\/p>\n<p>void Widget::on_pushButton_clicked()<br \/>\n{<br \/>\n    qDebug()&lt;&lt;&#034;\u6c49\u5821&#034;&lt;&lt;ui-&gt;comboBox_1-&gt;currentText();<br \/>\n    qDebug()&lt;&lt;&#034;\u5c0f\u98df&#034;&lt;&lt;ui-&gt;comboBox_2-&gt;currentText();<br \/>\n    qDebug()&lt;&lt;&#034;\u53ef\u4e50&#034;&lt;&lt;ui-&gt;comboBox_3-&gt;currentText();<br \/>\n}<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"466\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260207090618-6987008a354ce.png\" width=\"840\" \/><\/p>\n<p><span style=\"color:#0d0016\">\u5728\u5927\u591a\u6570\u60c5\u51b5\u4e2d&#xff0c;\u6211\u4eec\u662f\u4ece\u914d\u7f6e\u6587\u4ef6\u4e2d\u8bfb\u53d6\u9009\u9879\u7684\u800c\u4e0d\u662f\u5199\u6b7b\u7684&#xff0c;\u6240\u4ee5\u518d\u5c55\u793a\u4e00\u4e2a\u6587\u4ef6\u8bfb\u53d6\u8bbe\u7f6e\u9009\u9879\u7684\u4f8b\u5b50&#xff1a;<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"479\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260207090618-6987008a5eb99.png\" width=\"1295\" \/><\/p>\n<hr \/>\n<h3 id=\"QSpinBox\" style=\"background-color:transparent\"><span style=\"color:#0d0016\">QSpinBox<\/span><\/h3>\n<p><span style=\"color:#0d0016\">QspinBox\u7528\u4e8e\u6574\u6570&#xff0c;QDoubleSpinBox\u7528\u4e8e\u5c0f\u6570&#xff0c;\u7528\u6cd5\u90fd\u662f\u7c7b\u4f3c\u7684&#xff0c;\u8fd9\u91cc\u6211\u4eec\u53ea\u8bb2QSpinBox\u3002<\/span><\/p>\n<p><span style=\"color:#0d0016\">\u4e0b\u9762\u662fQSpinBox\u7684\u6838\u5fc3\u5c5e\u6027\u548c\u4fe1\u53f7&#xff1a;<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"701\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260207090618-6987008a9f4c3.png\" width=\"1560\" \/><\/p>\n<p><span style=\"color:#0d0016\">\u4e0b\u9762\u662f\u4f7f\u7528QSpinBox\u7684\u4ee3\u7801\u793a\u4f8b&#xff1a;<\/span><\/p>\n<p>Widget::Widget(QWidget *parent)<br \/>\n    : QWidget(parent)<br \/>\n    , ui(new Ui::Widget)<br \/>\n{<br \/>\n    ui-&gt;setupUi(this);<\/p>\n<p>    ui-&gt;comboBox-&gt;addItem(&#034;\u53ef\u4e50&#034;);<br \/>\n    ui-&gt;comboBox-&gt;addItem(&#034;\u96ea\u78a7&#034;);<\/p>\n<p>    \/\/\u8bbe\u7f6e\u5fae\u8c03\u8303\u56f4<br \/>\n    ui-&gt;spinBox-&gt;setRange(1,5);<br \/>\n    \/\/\u8bbe\u7f6e\u521d\u59cb\u503c<br \/>\n    ui-&gt;spinBox-&gt;setValue(1);<br \/>\n}<\/p>\n<p>void Widget::on_pushButton_clicked()<br \/>\n{<br \/>\n    qDebug()&lt;&lt;&#034;\u60a8\u9009\u62e9\u7684\u662f&#034;&lt;&lt;ui-&gt;comboBox-&gt;currentText()&lt;&lt;ui-&gt;spinBox-&gt;value();<br \/>\n} <\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"228\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260207090619-6987008b3980b.png\" width=\"851\" \/><\/p>\n<hr \/>\n<h3 id=\"QDateTimeEdit\"><span style=\"color:#0d0016\">QDateTimeEdit<\/span><\/h3>\n<p><span style=\"color:#0d0016\">\u4e0b\u9762\u662f\u5176\u6838\u5fc3\u5c5e\u6027\u4e0e\u4fe1\u53f7&#xff1a;<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"774\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260207090619-6987008b57bd6.png\" width=\"1750\" \/><\/p>\n<p><span style=\"color:#0d0016\">\u4e0b\u9762\u662f\u7b80\u5355\u7684\u4f7f\u7528\u793a\u4f8b&#xff1a;<\/span><\/p>\n<p>void Widget::on_pushButton_clicked()<br \/>\n{<br \/>\n    QDateTime x1 &#061; ui-&gt;dateTimeEdit_1-&gt;dateTime();<br \/>\n    QDateTime x2 &#061; ui-&gt;dateTimeEdit_2-&gt;dateTime();<\/p>\n<p>    int days &#061; x1.daysTo(x2);<br \/>\n    int sec &#061; x1.secsTo(x2);<\/p>\n<p>    int hours &#061;(sec\/3600)%24;<\/p>\n<p>    ui-&gt;label-&gt;setText(QString(&#034;\u7231\u4f60\u5df2\u7ecf\u6301\u7eed\u4e86&#034;)&#043;QString::number(days)&#043;QString(&#034;\u5929\u96f6&#034;)&#043;QString::number(hours)&#043;QString(&#034;\u5c0f\u65f6&#034;));<br \/>\n}<\/p>\n<p><span style=\"color:#0d0016\">\u8ba1\u7b97\u65f6\u95f4\u5dee\u7684\u6ce8\u610f\u4e8b\u9879&#xff1a;<\/span><\/p>\n<p><span style=\"color:#0d0016\">\u4e0a\u9762\u6211\u4eec\u4f7f\u7528\u7684\u662fQDateTime\u4e2d\u7684daysTo\u51fd\u6570\u8ba1\u7b97\u4e24\u4e2a\u65e5\u671f\u4e4b\u95f4\u9694\u4e86\u591a\u5c11\u5929&#xff0c;\u4f46\u662f\u6211\u4eec\u4f1a\u53d1\u73b0&#xff0c;\u50cf&#xff08;2000 1\/1 23:55 \u2014\u2014 2000 1\/2 00:01&#xff09;\u4e5f\u4f1a\u88ab\u5f53\u4f5c\u9694\u4e86\u4e00\u5929&#xff08;\u5b9e\u9645\u4e0a\u4e0d\u5230\u4e00\u4e2a\u5c0f\u65f6&#xff09;&#xff0c;\u8fd9\u4e2a\u95ee\u9898\u5b98\u65b9\u6587\u6863\u4e2d\u4e5f\u6709\u63d0\u53ca\u3002\u89e3\u51b3\u65b9\u6cd5\u5c31\u662f<\/span><span style=\"color:#fe2c24\">\u4e0d\u4f7f\u7528daysTo\u51fd\u6570\u8ba1\u7b97\u95f4\u9694\u5929\u6570\u800c\u662f\u5148\u4f7f\u7528secsTo\u8ba1\u7b97\u51fa\u79d2\u6570&#xff0c;\u518d\u6839\u636e\u79d2\u6570\u8ba1\u7b97\u5929\u6570<\/span><span style=\"color:#0d0016\">\u3002<\/span><\/p>\n<hr \/>\n<h3 id=\"QDial\"><span style=\"color:#0d0016\">QDial<\/span><\/h3>\n<p><span style=\"color:#0d0016\">\u4e0b\u9762\u662fQDial\u7684\u4e3b\u8981\u5c5e\u6027\u548c\u4fe1\u53f7&#xff1a;<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"773\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260207090619-6987008be3223.png\" width=\"1694\" \/><\/p>\n<p><span style=\"color:#0d0016\">\u4e0b\u9762\u662f\u5bf9QDial\u7684\u7b80\u5355\u4f7f\u7528&#xff1a;<\/span><\/p>\n<p>Widget::Widget(QWidget *parent)<br \/>\n    : QWidget(parent)<br \/>\n    , ui(new Ui::Widget)<br \/>\n{<br \/>\n    ui-&gt;setupUi(this);<br \/>\n    ui-&gt;dial-&gt;setWrapping(true);\/\/\u8bbe\u7f6e\u53ef\u5faa\u73af\u8c03\u6574<br \/>\n    ui-&gt;dial-&gt;setRange(0,100);\/\/\u8bbe\u7f6e\u6570\u503c\u8303\u56f4<br \/>\n    ui-&gt;dial-&gt;setValue(100);\/\/\u8bbe\u7f6e\u521d\u59cb\u6570\u503c<br \/>\n    ui-&gt;dial-&gt;setNotchesVisible(true);\/\/\u8bbe\u7f6e\u663e\u793a\u523b\u5ea6\u7ebf<br \/>\n}<\/p>\n<p>\/\/\u65cb\u94ae\u6570\u503c\u6539\u53d8\u4fe1\u53f7\u5bf9\u5e94\u7684\u69fd\u51fd\u6570<br \/>\nvoid Widget::on_dial_valueChanged(int value)<br \/>\n{<br \/>\n    \/\/\u8bbe\u7f6e\u7a97\u53e3\u7684\u4e0d\u900f\u660e\u5ea6<br \/>\n    this-&gt;setWindowOpacity((double)value \/100);<br \/>\n} <\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"472\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260207090620-6987008c7a50d.png\" width=\"566\" \/><\/p>\n<hr \/>\n<h3 id=\"QSlider\" style=\"background-color:transparent\"><span style=\"color:#0d0016\">QSlider<\/span><\/h3>\n<p><span style=\"color:#0d0016\">\u4e0b\u9762\u662fQSlider\u7684\u4e3b\u8981\u5c5e\u6027&#xff1a;<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"715\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260207090620-6987008c8f051.png\" width=\"1697\" \/><\/p>\n<p><span style=\"color:#0d0016\">\u4e0b\u9762\u534f\u8bae\u4e00\u4e2a\u901a\u8fc7\u6eda\u52a8\u6761\u63a7\u5236\u7a97\u53e3\u5927\u5c0f\u7684\u793a\u4f8b&#xff1a;<\/span><\/p>\n<p>Widget::Widget(QWidget *parent)<br \/>\n    : QWidget(parent)<br \/>\n    , ui(new Ui::Widget)<br \/>\n{<br \/>\n    ui-&gt;setupUi(this);<br \/>\n    ui-&gt;horizontalSlider-&gt;setMinimum(100);\/\/\u8bbe\u7f6e\u6700\u5c0f\u503c<br \/>\n    ui-&gt;horizontalSlider-&gt;setMaximum(2000);\/\/\u8bbe\u7f6e\u6700\u5927\u503c<br \/>\n    ui-&gt;horizontalSlider-&gt;setValue(774);\/\/\u8bbe\u7f6e\u521d\u59cb\u503c<br \/>\n    ui-&gt;horizontalSlider-&gt;setSingleStep(20);\/\/\u8bbe\u7f6e\u6bcf\u79fb\u52a8\u4e00\u6b65\u589e\u52a0\/\u51cf\u5c11\u591a\u5c11\u6570\u503c<\/p>\n<p>    ui-&gt;verticalSlider-&gt;setMinimum(100);<br \/>\n    ui-&gt;verticalSlider-&gt;setMaximum(2000);<br \/>\n    ui-&gt;verticalSlider-&gt;setValue(530);<br \/>\n    ui-&gt;verticalSlider-&gt;setSingleStep(20);<br \/>\n}<\/p>\n<p>\/\/\u8bbe\u7f6e\u6c34\u5e73\u6761\u503c\u53d8\u5316\u5bf9\u5e94\u7684\u69fd\u4fe1\u53f7<br \/>\nvoid Widget::on_horizontalSlider_valueChanged(int value)<br \/>\n{<br \/>\n    QRect rect &#061; this-&gt;geometry();<br \/>\n    this-&gt;setGeometry(rect.x(),rect.y(),ui-&gt;horizontalSlider-&gt;value(),rect.height());<br \/>\n}<br \/>\n\/\/\u8bbe\u7f6e\u5782\u76f4\u6761\u503c\u53d8\u5316\u5bf9\u5e94\u7684\u69fd\u4fe1\u53f7<br \/>\nvoid Widget::on_verticalSlider_valueChanged(int value)<br \/>\n{<br \/>\n    QRect rect &#061; this-&gt;geometry();<br \/>\n    this-&gt;setGeometry(rect.x(),rect.y(),rect.width(),ui-&gt;verticalSlider-&gt;value());<br \/>\n} <\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"592\" src=\"2026-02-07di4julkxeog.png\" width=\"695\" \/><\/p>\n<h3 id=\"\"><\/h3>\n<hr \/>\n<h3 id=\"%E9%A2%98%E5%A4%96%E8%AF%9D%E2%80%94%E2%80%94%E7%BB%99Qslider%E8%AE%BE%E7%BD%AE%E5%BF%AB%E6%8D%B7%E9%94%AE\"><span style=\"color:#0d0016\">\u9898\u5916\u8bdd\u2014\u2014\u7ed9Qslider\u8bbe\u7f6e\u5feb\u6377\u952e<\/span><\/h3>\n<p>Widget::Widget(QWidget *parent)<br \/>\n    : QWidget(parent)<br \/>\n    , ui(new Ui::Widget)<br \/>\n{<br \/>\n    ui-&gt;setupUi(this);<br \/>\n    QShortcut* add &#061; new QShortcut(this);\/\/\u521b\u5efa\u5feb\u6377\u952e\u5bf9\u8c61<br \/>\n    add-&gt;setKey(QKeySequence(&#034;&#043;&#034;));\/\/\u8bbe\u7f6e\u5feb\u6377\u952e<br \/>\n    QShortcut* sub &#061; new QShortcut(this);<br \/>\n    sub-&gt;setKey(QKeySequence(&#034;-&#034;));<\/p>\n<p>    \/\/\u521d\u59cb\u5316\u6eda\u52a8\u6761<br \/>\n    ui-&gt;horizontalSlider-&gt;setValue(50);<br \/>\n    ui-&gt;horizontalSlider-&gt;setRange(0,100);<\/p>\n<p>    \/\/\u5173\u8054\u5feb\u6377\u952e\u6fc0\u6d3b\u4fe1\u53f7\u548c\u69fd\u51fd\u6570<br \/>\n    connect(add,&amp;QShortcut::activated,this,&amp;Widget::Add);<br \/>\n    connect(sub,&amp;QShortcut::activated,this,&amp;Widget::Sub);<br \/>\n}<\/p>\n<p>void Widget::Add()<br \/>\n{<br \/>\n    ui-&gt;horizontalSlider-&gt;setValue((ui-&gt;horizontalSlider-&gt;value())&#043;5);<br \/>\n    ui-&gt;label-&gt;setText(QString(&#034;\u5f53\u524d\u6570\u503c\u4e3a:&#034;)&#043;QString::number(ui-&gt;horizontalSlider-&gt;value()));<br \/>\n}<\/p>\n<p>void Widget::Sub()<br \/>\n{<br \/>\n    ui-&gt;horizontalSlider-&gt;setValue((ui-&gt;horizontalSlider-&gt;value())-5);<br \/>\n    ui-&gt;label-&gt;setText(QString(&#034;\u5f53\u524d\u6570\u503c\u4e3a:&#034;)&#043;QString::number(ui-&gt;horizontalSlider-&gt;value()));<br \/>\n} <\/p>\n<p><span style=\"color:#0d0016\">\u8fd9\u6837\u4e00\u6765\u6309\u4e0b&#043;&#xff0c;-\u5c31\u53ef\u4ee5\u8ba9\u6eda\u52a8\u6761\u79fb\u52a8\u4e86<\/span><\/p>\n<hr \/>\n<h2 id=\"%E5%A4%9A%E5%85%83%E7%B4%A0%E6%8E%A7%E4%BB%B6\" style=\"background-color:transparent\"><span style=\"color:#0d0016\">\u591a\u5143\u7d20\u63a7\u4ef6<\/span><\/h2>\n<p><span style=\"color:#fe2c24\">\u591a\u5143\u7d20\u63a7\u4ef6\u91cc\u9762\u5305\u542b\u7684\u5185\u5bb9\u662f\u90fd\u662f\u4e00\u4e2a\u4e2a\u201citem\u201d\u5bf9\u8c61<\/span><span style=\"color:#0d0016\">\u3002<\/span><\/p>\n<h3 id=\"QListWidget\" style=\"background-color:transparent\"><span style=\"color:#0d0016\">QListWidget<\/span><\/h3>\n<p><span style=\"color:#0d0016\">\u4e0b\u9762\u662fQListWidget\u7684\u4e3b\u8981\u5c5e\u6027&#xff0c;\u65b9\u6cd5&#xff0c;\u4fe1\u53f7&#xff1a;<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"651\" src=\"2026-02-07clejmoa2ern.png\" width=\"1813\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"431\" src=\"2026-02-07o1zgnt3dbxa.png\" width=\"1636\" \/><\/p>\n<p><span style=\"color:#0d0016\">\u4e0b\u9762\u662f\u4f7f\u7528QListWidget\u7684\u793a\u4f8b&#xff08;\u5217\u8868\u4e2d\u7684\u5143\u7d20\u662fQListWidget\u7c7b\u578b&#xff09;&#xff1a;<\/span><\/p>\n<p>Widget::Widget(QWidget *parent)<br \/>\n    : QWidget(parent)<br \/>\n    , ui(new Ui::Widget)<br \/>\n{<br \/>\n    ui-&gt;setupUi(this);<\/p>\n<p>    \/\/\u5f00\u542f\u9f20\u6807\u8ffd\u8e2a&#xff0c;\u8ba9QListWidget\u8ddf\u8e2a\u9f20\u6807\u79fb\u52a8\u4e8b\u4ef6<br \/>\n    ui-&gt;listWidget-&gt;setMouseTracking(true);<\/p>\n<p>    \/\/\u6dfb\u52a0\u56fa\u5b9a\u7684\u5217\u8868\u9879,\u8fd9\u91cc\u4f7f\u7528\u4e86\u4e24\u79cd\u6dfb\u52a0\u65b9\u5f0f<br \/>\n    ui-&gt;listWidget-&gt;addItem(&#034;\u539f\u795e&#034;);<br \/>\n    ui-&gt;listWidget-&gt;addItem(new QListWidgetItem(&#034;c&#043;&#043;&#034;));<br \/>\n}<\/p>\n<p>\/\/\u7ed9\u6dfb\u52a0\u6309\u94ae\u8bbe\u7f6e\u69fd\u51fd\u6570<br \/>\nvoid Widget::on_pushButton_add_clicked()<br \/>\n{<br \/>\n    QString temp &#061; ui-&gt;lineEdit-&gt;text();<br \/>\n    if(!temp.isEmpty())<br \/>\n    {<br \/>\n        \/\/\u6dfb\u52a0\u5143\u7d20<br \/>\n        ui-&gt;listWidget-&gt;addItem(temp);<br \/>\n    }<br \/>\n}<br \/>\n\/\/\u7ed9\u5220\u9664\u6309\u94ae\u8bbe\u7f6e\u69fd\u51fd\u6570<br \/>\nvoid Widget::on_pushButton_delete_clicked()<br \/>\n{<br \/>\n    int row &#061; ui-&gt;listWidget-&gt;currentRow();<br \/>\n    if(row&gt;&#061;0)<br \/>\n    \/\/\u6309\u7167\u884c\u53f7\u5220\u9664\u5143\u7d20<br \/>\n    ui-&gt;listWidget-&gt;takeItem(row);<br \/>\n}<\/p>\n<p>void Widget::on_listWidget_itemEntered(QListWidgetItem *item)<br \/>\n{<br \/>\n     qDebug()&lt;&lt;&#034;\u9f20\u6807\u60ac\u505c\u5728&#xff1a;&#034;&lt;&lt;item-&gt;text();<br \/>\n}<\/p>\n<p>void Widget::on_listWidget_itemDoubleClicked(QListWidgetItem *item)<br \/>\n{<br \/>\n    qDebug()&lt;&lt;&#034;\u70b9\u4e24\u6b21&#xff1a;&#034;&lt;&lt;item-&gt;text();<br \/>\n}<\/p>\n<p>void Widget::on_listWidget_currentItemChanged(QListWidgetItem *current, QListWidgetItem *previous)<br \/>\n{<br \/>\n    qDebug()&lt;&lt;&#034;\u9009\u4e86\u4e0d\u540c\u7684\u5143\u7d20&#034;;<br \/>\n}<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"464\" src=\"2026-02-07f4xg4l503g2.png\" width=\"1130\" \/><\/p>\n<hr \/>\n<h3 id=\"QTableWidget\" style=\"background-color:transparent\"><span style=\"color:#0d0016\">QTableWidget<\/span><\/h3>\n<p><span style=\"color:#0d0016\">\u4e0b\u9762\u662fQTableWidget\u7684\u4e3b\u8981\u65b9\u6cd5\u548c\u4fe1\u53f7&#xff1a;<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"776\" src=\"2026-02-07kvtcnzkds4n.png\" width=\"1803\" \/><\/p>\n<p><span style=\"color:#0d0016\">\u4e0b\u9762\u662fQTableWidgetItem\u7684\u4e3b\u8981\u65b9\u6cd5&#xff1a;<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"489\" src=\"2026-02-07zdkp5t002jn.png\" width=\"894\" \/><\/p>\n<p><span style=\"color:#0d0016\">\u4e0b\u9762\u662fQTableWidget\u7684\u793a\u4f8b&#xff08;\u5217\u8868\u4e2d\u7684\u5143\u7d20\u662fQTableWidget\u7c7b\u578b&#xff09;&#xff1a;<\/span><\/p>\n<p>Widget::Widget(QWidget *parent)<br \/>\n    : QWidget(parent)<br \/>\n    , ui(new Ui::Widget)<br \/>\n{<br \/>\n    ui-&gt;setupUi(this);<\/p>\n<p>    \/\/\u6dfb\u52a0\u4e24\u884c<br \/>\n    ui-&gt;tableWidget-&gt;insertRow(0);<br \/>\n    ui-&gt;tableWidget-&gt;insertRow(1);<\/p>\n<p>    \/\/\u6dfb\u52a0\u4e09\u5217<br \/>\n    ui-&gt;tableWidget-&gt;insertColumn(0);<br \/>\n    ui-&gt;tableWidget-&gt;insertColumn(1);<br \/>\n    ui-&gt;tableWidget-&gt;insertColumn(2);<\/p>\n<p>    \/\/\u7ed9\u6bcf\u4e2a\u5217\u8bbe\u7f6e\u8868\u5934<br \/>\n    ui-&gt;tableWidget-&gt;setHorizontalHeaderItem(0,new QTableWidgetItem(&#034;\u5b66\u53f7&#034;));<br \/>\n    ui-&gt;tableWidget-&gt;setHorizontalHeaderItem(1,new QTableWidgetItem(&#034;\u59d3\u540d&#034;));<br \/>\n    ui-&gt;tableWidget-&gt;setHorizontalHeaderItem(2,new QTableWidgetItem(&#034;\u5206\u6570&#034;));<\/p>\n<p>    \/\/\u7ed9\u8868\u683c\u7b2c\u4e00\u884c\u6dfb\u52a0\u5143\u7d20<br \/>\n    ui-&gt;tableWidget-&gt;setItem(0,0,new QTableWidgetItem(&#034;001&#034;));<br \/>\n    ui-&gt;tableWidget-&gt;setItem(0,1,new QTableWidgetItem(&#034;\u5f20\u4e09&#034;));<br \/>\n    ui-&gt;tableWidget-&gt;setItem(0,2,new QTableWidgetItem(&#034;55&#034;));<br \/>\n    \/\/\u7ed9\u8868\u683c\u7b2c\u4e8c\u884c\u6dfb\u52a0\u5143\u7d20<br \/>\n    ui-&gt;tableWidget-&gt;setItem(1,0,new QTableWidgetItem(&#034;002&#034;));<br \/>\n    ui-&gt;tableWidget-&gt;setItem(1,1,new QTableWidgetItem(&#034;\u674e\u56db&#034;));<br \/>\n    ui-&gt;tableWidget-&gt;setItem(1,2,new QTableWidgetItem(&#034;99&#034;));<\/p>\n<p>}<\/p>\n<p>void Widget::on_pushButton_addrow_clicked()<br \/>\n{<br \/>\n    int rowcount &#061; ui-&gt;tableWidget-&gt;rowCount();<br \/>\n    ui-&gt;tableWidget-&gt;insertRow(rowcount);<br \/>\n}<\/p>\n<p>void Widget::on_pushButton_delrow_clicked()<br \/>\n{<br \/>\n    int rowcount &#061; ui-&gt;tableWidget-&gt;currentRow();<br \/>\n    ui-&gt;tableWidget-&gt;removeRow(rowcount);<br \/>\n}<\/p>\n<p>void Widget::on_pushButton_addcol_clicked()<br \/>\n{<br \/>\n    \/\/\u83b7\u53d6\u8f93\u5165\u6846\u7684\u6570\u636e<br \/>\n    QString temp;<br \/>\n    temp &#061; ui-&gt;lineEdit-&gt;text();<\/p>\n<p>    if(!temp.isEmpty())<br \/>\n    {<br \/>\n        \/\/\u6dfb\u52a0\u65b0\u7684\u5217<br \/>\n       int colcount &#061; ui-&gt;tableWidget-&gt;columnCount();<br \/>\n       ui-&gt;tableWidget-&gt;insertColumn(colcount);<br \/>\n       \/\/\u6dfb\u52a0\u5217\u7684\u8868\u5934<br \/>\n       ui-&gt;tableWidget-&gt;setHorizontalHeaderItem(colcount,new QTableWidgetItem(temp));<br \/>\n    }<br \/>\n}<\/p>\n<p>void Widget::on_pushButton_delcol_clicked()<br \/>\n{<br \/>\n    int colcount &#061; ui-&gt;tableWidget-&gt;currentColumn();<br \/>\n    ui-&gt;tableWidget-&gt;removeColumn(colcount-1);<br \/>\n} <\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"529\" src=\"2026-02-07epadiqelz0y.png\" width=\"685\" \/><\/p>\n<hr \/>\n<h3 id=\"QTreeWidget\" style=\"background-color:transparent\"><span style=\"color:#0d0016\">QTreeWidget<\/span><\/h3>\n<p><span style=\"color:#0d0016\">\u4e0b\u9762\u662fQTreeWidget \u548c QTreeWidgetItem (QTreeWidget\u4e2d\u7684\u5143\u7d20\u7c7b\u578b)\u7684\u6838\u5fc3\u5c5e\u6027&#xff0c;\u4fe1\u53f7&#xff0c;\u65b9\u6cd5&#xff1a;<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"689\" src=\"2026-02-07zqajbix4hvb.png\" width=\"1833\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"636\" src=\"2026-02-07g1f0l4ky2yl.png\" width=\"1820\" \/><\/p>\n<p><span style=\"color:#fe2c24\">QTtreeWidget\u7684\u6839\u8282\u70b9\u53ea\u80fd\u4fee\u6539\u540d\u5b57\u800c\u4e0d\u80fd\u5220\u9664&#xff0c;\u5e76\u4e14QTtreeWidget\u53ea\u80fd\u7528\u6765\u64cd\u4f5c\u9876\u5c42\u8282\u70b9&#xff08;\u4e5f\u5c31\u662f\u6839\u8282\u70b9\u4e0b\u9762\u7684\u7b2c\u4e00\u5c42\u8282\u70b9&#xff09;&#xff0c;\u800c\u6dfb\u52a0\u6216\u5220\u9664\u666e\u901a\u8282\u70b9\u662f\u901a\u8fc7QTreeWidgetItem\u8282\u70b9\u672c\u8eab\u8fdb\u884c\u64cd\u4f5c\u7684<\/span><span style=\"color:#0d0016\">\u3002<\/span><\/p>\n<p><span style=\"color:#0d0016\">\u4e0b\u9762\u662f\u5bf9QTreeWidget\u7684\u4f7f\u7528\u793a\u4f8b&#xff1a;<\/span><\/p>\n<p>Widget::Widget(QWidget *parent)<br \/>\n    : QWidget(parent)<br \/>\n    , ui(new Ui::Widget)<br \/>\n{<br \/>\n    ui-&gt;setupUi(this);<\/p>\n<p>    \/\/\u8bbe\u7f6e\u6839\u8282\u70b9&#xff08;\u4e5f\u5c31\u662f\u6811&#xff09;\u7684\u540d\u79f0<br \/>\n    ui-&gt;treeWidget-&gt;setHeaderLabel(&#034;\u52a8\u7269&#034;);<\/p>\n<p>    \/\/\u521b\u5efa\u4e09\u4e2a\u9876\u5c42\u8282\u70b9<br \/>\n    QTreeWidgetItem* top1 &#061; new QTreeWidgetItem();<br \/>\n    top1-&gt;setText(0,&#034;\u72d7&#034;);\/\/\u7ed9\u9876\u5c42\u8282\u70b9\u8bbe\u7f6e\u6587\u672c\/\u56fe\u7247&#xff0c;\u53ef\u4ee5\u8bbe\u7f6e\u591a\u4e2a\u6587\u672c\/\u56fe\u7247<br \/>\n    ui-&gt;treeWidget-&gt;addTopLevelItem(top1);\/\/\u6dfb\u52a0\u9876\u5c42\u8282\u70b9<\/p>\n<p>    QTreeWidgetItem* top2 &#061; new QTreeWidgetItem();<br \/>\n    top2-&gt;setText(0,&#034;\u732b&#034;);<br \/>\n    ui-&gt;treeWidget-&gt;addTopLevelItem(top2);<\/p>\n<p>    QTreeWidgetItem* top3 &#061; new QTreeWidgetItem();<br \/>\n    top3-&gt;setText(0,&#034;\u9c7c&#034;);<br \/>\n    ui-&gt;treeWidget-&gt;addTopLevelItem(top3);<\/p>\n<p>    \/\/\u7ed9\u6bcf\u4e2a\u8282\u70b9\u65b0\u589e\u4e00\u4e9b\u5b50\u8282\u70b9<br \/>\n    QTreeWidgetItem* child1 &#061; new QTreeWidgetItem();<br \/>\n    child1-&gt;setText(0,&#034;\u91d1\u6bdb&#034;);<br \/>\n    top1-&gt;addChild(child1);<\/p>\n<p>    QTreeWidgetItem* child2 &#061; new QTreeWidgetItem();<br \/>\n    child2-&gt;setText(0,&#034;\u54c8\u5df4\u72d7&#034;);<br \/>\n    top1-&gt;addChild(child2);<\/p>\n<p>    QTreeWidgetItem* child3 &#061; new QTreeWidgetItem();<br \/>\n    child3-&gt;setText(0,&#034;\u5e03\u5076\u732b&#034;);<br \/>\n    top2-&gt;addChild(child3);<\/p>\n<p>    QTreeWidgetItem* child4 &#061; new QTreeWidgetItem();<br \/>\n    child4-&gt;setText(0,&#034;\u5927\u6bdb\u6bdb&#034;);<br \/>\n    top2-&gt;addChild(child4);<br \/>\n}<\/p>\n<p>void Widget::on_pushButton_addtop_clicked()<br \/>\n{<br \/>\n    \/\/\u83b7\u53d6\u8f93\u5165\u6846\u4e2d\u7684\u5185\u5bb9<br \/>\n    QString temp &#061; ui-&gt;lineEdit-&gt;text();<br \/>\n    if(!temp.isEmpty())<br \/>\n    {<br \/>\n        QTreeWidgetItem* top1 &#061; new QTreeWidgetItem();<br \/>\n        top1-&gt;setText(0,temp);\/\/\u7ed9\u9876\u5c42\u8282\u70b9\u8bbe\u7f6e\u6587\u672c\/\u56fe\u7247&#xff0c;\u53ef\u4ee5\u8bbe\u7f6e\u591a\u4e2a\u6587\u672c\/\u56fe\u7247<br \/>\n        ui-&gt;treeWidget-&gt;addTopLevelItem(top1);\/\/\u6dfb\u52a0\u9876\u5c42\u8282\u70b9<br \/>\n    }<br \/>\n}<\/p>\n<p>void Widget::on_pushButton_addchild_clicked()<br \/>\n{<br \/>\n    \/\/\u83b7\u53d6\u5f53\u524d\u9009\u4e2d\u7684\u8282\u70b9<br \/>\n    QTreeWidgetItem* item &#061; ui-&gt;treeWidget-&gt;currentItem();<\/p>\n<p>    \/\/\u83b7\u53d6\u8f93\u5165\u6846\u4e2d\u7684\u5185\u5bb9<br \/>\n    QString temp &#061; ui-&gt;lineEdit-&gt;text();<\/p>\n<p>    \/\/\u521b\u5efa\u4e00\u4e2a\u65b0\u8282\u70b9<br \/>\n    QTreeWidgetItem* child &#061; new QTreeWidgetItem();<br \/>\n    child-&gt;setText(0,temp);<br \/>\n    item-&gt;addChild(child);<br \/>\n}<\/p>\n<p>void Widget::on_pushButton_delete_clicked()<br \/>\n{<br \/>\n    \/\/\u83b7\u53d6\u5f53\u524d\u9009\u4e2d\u7684\u8282\u70b9<br \/>\n    QTreeWidgetItem* item &#061; ui-&gt;treeWidget-&gt;currentItem();<\/p>\n<p>    \/\/\u83b7\u53d6\u5f53\u524d\u9009\u4e2d\u8282\u70b9\u7684\u7236\u8282\u70b9<br \/>\n    QTreeWidgetItem* parent &#061; item-&gt;parent();<\/p>\n<p>    \/\/\u5982\u679c\u5f53\u524d\u9009\u4e2d\u7684\u8282\u70b9\u662f\u9876\u5c42\u8282\u70b9<br \/>\n    if(parent &#061;&#061; nullptr)<br \/>\n    {<br \/>\n        \/\/\u83b7\u53d6\u5f53\u524d\u8282\u70b9\u5728\u9876\u5c42\u4e2d\u7684\u4e0b\u6807<br \/>\n        int index &#061; ui-&gt;treeWidget-&gt;indexOfTopLevelItem(item);<br \/>\n        \/\/\u5220\u9664\u8be5\u8282\u70b9<br \/>\n        ui-&gt;treeWidget-&gt;takeTopLevelItem(index);<br \/>\n    }<br \/>\n    \/\/\u5982\u679c\u5f53\u524d\u9009\u4e2d\u7684\u8282\u70b9\u662f\u666e\u901a\u8282\u70b9<br \/>\n    else<br \/>\n    {<br \/>\n        \/\/\u5220\u9664\u8be5\u5b50\u8282\u70b9<br \/>\n        parent-&gt;removeChild(item);<br \/>\n    }<\/p>\n<p>} <\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"485\" src=\"2026-02-07oej3l1lllev.png\" width=\"666\" \/><\/p>\n<hr \/>\n<h2 id=\"%E5%AE%B9%E5%99%A8%E7%B1%BB%E6%8E%A7%E4%BB%B6\" style=\"background-color:transparent\"><span style=\"color:#0d0016\">\u5bb9\u5668\u7c7b\u63a7\u4ef6<\/span><\/h2>\n<p><span style=\"color:#fe2c24\">\u5bb9\u5668\u7c7b\u63a7\u4ef6\u91cc\u9762\u5305\u542b\u7684\u662f\u5176\u5b83\u63a7\u4ef6&#xff0c;\u88ab\u5305\u542b\u7684\u63a7\u4ef6\u7684\u7236\u5143\u7d20\u4f1a\u53d8\u6210\u5bb9\u5668\u7c7b\u63a7\u4ef6\u800c\u4e0d\u662fQWidget\u4e86&#xff0c;\u5e76\u4e14\u88ab\u5bb9\u5668\u7c7b\u63a7\u4ef6\u5206\u5272\u540e&#xff0c;\u4e00\u4e9b\u672c\u6765\u5173\u8054\u7684\u63a7\u4ef6\u4f1a\u53d8\u5f97\u4e0d\u5173\u8054&#xff0c;\u6bd4\u5982\u591a\u4e2aRadio Button&#xff0c;\u672c\u6765\u662f\u53ea\u80fd\u9009\u4e00\u4e2a&#xff08;\u5373\u4ed6\u4eec\u662f\u6709\u5173\u8054\u7684&#xff09;&#xff0c;\u4e00\u4f46\u88ab\u5bb9\u5668\u7c7b\u63a7\u4ef6\u5206\u5272\u540e\u88ab\u5206\u5272\u7684\u63a7\u4ef6\u5c31\u81ea\u6210\u4e00\u7ec4<\/span><span style=\"color:#0d0016\">\u3002<\/span><\/p>\n<h3 id=\"QGroupBox\" style=\"background-color:transparent\"><span style=\"color:#0d0016\">QGroupBox<\/span><\/h3>\n<p><span style=\"color:#0d0016\">\u4e0b\u9762\u662fQGroupBox\u7684\u6838\u5fc3\u5c5e\u6027\u4ee5\u53ca\u4f7f\u7528\u793a\u4f8b&#xff1a;<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"423\" src=\"2026-02-070amoki31g3c.png\" width=\"956\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"672\" src=\"2026-02-07xkeap1zyver.png\" width=\"729\" \/><\/p>\n<hr \/>\n<h3 id=\"QTabWidget\" style=\"background-color:transparent\"><span style=\"color:#0d0016\">QTabWidget<\/span><\/h3>\n<p><span style=\"color:#fe2c24\">QTabWidget\u91cc\u5305\u542b\u7684\u662f\u82e5\u5e72\u4e2aQWidget\u63a7\u4ef6&#xff0c;\u76f8\u5f53\u4e8e\u82e5\u5e72\u4e2a\u65b0\u7684\u7a97\u53e3<\/span><\/p>\n<p><span style=\"color:#0d0016\">\u4e0b\u9762\u662fQTabWidget\u7684\u6838\u5fc3\u5c5e\u6027\u548c\u4fe1\u53f7&#xff1a;<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"681\" src=\"2026-02-07ctfbvpm0qhs.png\" width=\"1811\" \/><\/p>\n<p><span style=\"color:#0d0016\">\u4e0b\u9762\u662fQTabWidget\u7684\u4f7f\u7528\u793a\u4f8b&#xff1a;<\/span><\/p>\n<p>Widget::Widget(QWidget *parent)<br \/>\n    : QWidget(parent)<br \/>\n    , ui(new Ui::Widget)<br \/>\n{<br \/>\n    ui-&gt;setupUi(this);<\/p>\n<p>    \/\/\u8ba9\u6807\u7b7e\u9875\u663e\u793a\u5173\u95ed\u6309\u94ae&#xff0c;\u70b9\u51fb\u6309\u94ae\u53ef\u4ee5\u53d1\u51fa\u5173\u95ed\u4fe1\u53f7<br \/>\n    ui-&gt;tabWidget-&gt;setTabsClosable(true);<\/p>\n<p>    \/\/\u5728\u6807\u7b7e\u98751\u521b\u5efa\u4e00\u4e2alabel<br \/>\n    QLabel* label &#061; new QLabel(ui-&gt;tab);<br \/>\n    label-&gt;setText(&#034;\u8fd9\u662f\u7b2c\u4e00\u4e2a\u6807\u7b7e\u9875&#034;);<br \/>\n    label-&gt;resize(200,50);<br \/>\n    \/\/\u8bbe\u7f6e\u6807\u7b7e\u98751\u7684\u6807\u9898<br \/>\n    ui-&gt;tabWidget-&gt;setTabText(0,&#034;\u6807\u7b7e\u98750&#034;);<\/p>\n<p>    \/\/\u5728\u6807\u7b7e\u98751\u521b\u5efa\u4e00\u4e2alabel<br \/>\n    QLabel* label2 &#061; new QLabel(ui-&gt;tab_2);<br \/>\n    label2-&gt;setText(&#034;\u8fd9\u662f\u7b2c\u4e00\u4e2a\u6807\u7b7e\u9875&#034;);<br \/>\n    label2-&gt;resize(200,50);<br \/>\n    \/\/\u8bbe\u7f6e\u6807\u7b7e\u98751\u7684\u6807\u9898<br \/>\n    ui-&gt;tabWidget-&gt;setTabText(1,&#034;\u6807\u7b7e\u98751&#034;);<br \/>\n}<\/p>\n<p>\/\/\u6dfb\u52a0\u65b0\u7684\u6807\u7b7e\u9875<br \/>\nvoid Widget::on_pushButton_clicked()<br \/>\n{<br \/>\n    \/\/\u83b7\u53d6\u5f53\u524d\u6807\u7b7e\u9875\u7684\u6570\u91cf<br \/>\n    int n &#061; ui-&gt;tabWidget-&gt;count();<br \/>\n    \/\/\u521b\u5efa\u65b0\u7a97\u53e3<br \/>\n    QWidget* newtab &#061; new QWidget(ui-&gt;tabWidget);<br \/>\n    \/\/\u5c06\u7a97\u53e3\u6dfb\u52a0\u5230\u6807\u7b7e\u9875\u5e76\u8bbe\u7f6e\u6807\u7b7e\u9875\u7684\u6807\u9898<br \/>\n    ui-&gt;tabWidget-&gt;addTab(newtab,QString(&#034;\u6807\u7b7e\u9875&#034;)&#043;QString::number(n));<br \/>\n    \/\/\u7ed9\u65b0\u7684\u6807\u7b7e\u9875\u6dfb\u52a0label<br \/>\n    QLabel * label &#061; new QLabel(newtab);<br \/>\n    label-&gt;setText(QString(&#034;\u8fd9\u662f\u7b2c&#034;)&#043;QString::number(n)&#043;QString(&#034;\u4e2a\u6807\u7b7e\u9875&#034;));<br \/>\n    label-&gt;resize(200,50);<\/p>\n<p>    \/\/\u8bbe\u7f6e\u5f53\u524d\u9009\u4e2d\u7684\u6807\u7b7e\u9875\u4e3a\u65b0\u6807\u7b7e\u9875<br \/>\n    ui-&gt;tabWidget-&gt;setCurrentIndex(n);<br \/>\n}<br \/>\n\/\/\u5220\u9664\u9009\u4e2d\u7684\u6807\u7b7e\u9875<br \/>\nvoid Widget::on_pushButton_2_clicked()<br \/>\n{<br \/>\n    \/\/\u83b7\u53d6\u5f53\u524d\u9009\u4e2d\u7684\u6807\u7b7e\u9875\u7684\u4e0b\u6807<br \/>\n    int index &#061; ui-&gt;tabWidget-&gt;currentIndex();<br \/>\n    \/\/\u5220\u9664\u5f53\u524d\u6807\u7b7e\u9875<br \/>\n    ui-&gt;tabWidget-&gt;removeTab(index);<br \/>\n}<br \/>\n\/\/\u8bbe\u7f6e\u5173\u95ed\u4fe1\u53f7\u5173\u8054\u7684\u69fd<br \/>\nvoid Widget::on_tabWidget_tabCloseRequested(int index)<br \/>\n{<br \/>\n    \/\/\u5220\u9664\u5f53\u524d\u6807\u7b7e\u9875<br \/>\n    ui-&gt;tabWidget-&gt;removeTab(index);<br \/>\n}<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"530\" src=\"2026-02-07yovd43ip4h4.png\" width=\"679\" \/><\/p>\n<hr \/>\n<h2 id=\"%E5%B8%83%E5%B1%80%E7%AE%A1%E7%90%86%E5%99%A8\" style=\"background-color:transparent\"><span style=\"color:#0d0016\">\u5e03\u5c40\u7ba1\u7406\u5668<\/span><\/h2>\n<p> <span style=\"color:#0d0016\">\u4e4b\u524d\u4f7f\u7528Qt\u5728\u754c\u9762\u4e0a\u521b\u5efa\u7684\u63a7\u4ef6, \u90fd\u662f\u901a\u8fc7&#034;\u7edd\u5bf9\u5b9a\u4f4d&#034;\u7684\u65b9\u5f0f\u6765\u8bbe\u5b9a\u7684\u3002<\/span><br \/>\n <span style=\"color:#0d0016\">\u4e5f\u5c31\u662f\u6bcf\u4e2a\u63a7\u4ef6\u6240\u5728\u7684\u4f4d\u7f6e, \u90fd\u9700\u8981\u8ba1\u7b97\u5750\u6807, \u6700\u7ec8\u901a\u8fc7 setGeometry \u6216\u8005 move \u65b9\u5f0f\u6446\u653e\u8fc7\u53bb.\u8fd9\u79cd\u8bbe\u5b9a\u65b9\u5f0f\u5176\u5b9e\u5e76\u4e0d\u65b9\u4fbf. \u5c24\u5176\u662f\u754c\u9762\u5982\u679c\u5185\u5bb9\u6bd4\u8f83\u591a,<\/span><br \/>\n <span style=\"color:#fe2c24\"> \u4e0d\u597d\u8ba1\u7b97<\/span><br \/>\n <span style=\"color:#0d0016\">. \u800c\u4e14\u2f00\u4e2a\u7a97\u53e3\u5927\u5c0f\u5f80\u5f80\u662f\u53ef\u4ee5\u8c03\u6574<\/span><br \/>\n <span style=\"color:#0d0016\">\u7684, \u6309\u7167\u7edd\u5bf9\u5b9a\u4f4d\u7684\u65b9\u5f0f, \u4e5f<\/span><br \/>\n <span style=\"color:#fe2c24\">\u65e0\u6cd5\u81ea\u9002\u5e94\u7a97\u53e3\u5927\u5c0f<\/span><br \/>\n <span style=\"color:#0d0016\">\u3002<\/span><\/p>\n<p> <span style=\"color:#0d0016\">\u56e0\u6b64 Qt \u5f15\u5165\u00a0&#034;\u5e03\u5c40\u7ba1\u7406\u5668&#034; (Layout) \u673a\u5236, \u6765\u89e3\u51b3\u4e0a\u8ff0\u95ee\u9898<\/span>\u3002<br \/>\n <span style=\"color:#fe2c24\">\u5e03\u5c40\u7ba1\u7406\u5668\u5185\u7684\u63a7\u4ef6\u7684\u5927\u5c0f\u95f4\u8ddd\u7b49\u662f\u81ea\u52a8\u8c03\u6574\u7684&#xff0c;\u800c\u4e14\u53ef\u4ee5\u81ea\u9002\u5e94\u7a97\u53e3\u5927\u5c0f<\/span><br \/>\n <span style=\"color:#0d0016\">\u3002\u4e0d\u8fc7\u5e03\u5c40\u7ba1\u7406\u5668\u76f8\u5f53\u4e8e\u4e00\u4e2a\u5bb9\u5668\u7c7b\u63a7\u4ef6&#xff0c;\u5176\u4e2d\u7684\u63a7\u4ef6\u548c\u5916\u754c\u63a7\u4ef6\u5e76\u4e0d\u5173\u8054\u3002<\/span><\/p>\n<h3 id=\"QVBoxLayout%EF%BC%88%E5%9E%82%E7%9B%B4%E5%B8%83%E5%B1%80%E7%AE%A1%E7%90%86%E5%99%A8%EF%BC%89\" style=\"background-color:transparent\"><span style=\"color:#0d0016\">QVBoxLayout&#xff08;\u5782\u76f4\u5e03\u5c40\u7ba1\u7406\u5668&#xff09;<\/span><\/h3>\n<p><span style=\"color:#0d0016\">\u4e0b\u9762\u662f\u5173\u4e8eQVLayout\u7684\u4e3b\u8981\u5c5e\u6027&#xff1a;<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"429\" src=\"2026-02-07syq5tebahlo.png\" width=\"906\" \/><\/p>\n<p> <span style=\"color:#0d0016\">\u4e0b\u9762\u662f\u4f7f\u7528\u793a\u4f8b&#xff1a;<\/span><\/p>\n<p> Widget::Widget(QWidget *parent)<br \/>\n    : QWidget(parent)<br \/>\n    , ui(new Ui::Widget)<br \/>\n{<br \/>\n    ui-&gt;setupUi(this);<\/p>\n<p>    QPushButton *a &#061; new QPushButton(&#034;\u6309\u94ae1&#034;);<br \/>\n    QPushButton *b &#061; new QPushButton(&#034;\u6309\u94ae2&#034;);<br \/>\n    QPushButton *c &#061; new QPushButton(&#034;\u6309\u94ae3&#034;);<\/p>\n<p>    \/\/\u521b\u5efa\u5e03\u5c40\u7ba1\u7406\u5668<br \/>\n    QVBoxLayout* layout &#061; new QVBoxLayout();<br \/>\n    \/\/\u7ed9\u5e03\u5c40\u7ba1\u7406\u5668\u6dfb\u52a0\u5143\u7d20<br \/>\n    layout-&gt;addWidget(a);<br \/>\n    layout-&gt;addWidget(b);<br \/>\n    layout-&gt;addWidget(c);<\/p>\n<p>    \/\/\u7ed9\u5f53\u524d\u7a97\u53e3\u6dfb\u52a0\u5e03\u5c40\u7ba1\u7406\u5668<br \/>\n    this-&gt;setLayout(layout);<br \/>\n} <\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"218\" src=\"2026-02-07lboocmlk5ws.png\" width=\"346\" \/><\/p>\n<p><span style=\"color:#0d0016\">\u6ce8\u610f&#xff1a;<\/span><span style=\"color:#fe2c24\">\u4e00\u4e2a\u7a97\u53e3\u9ed8\u8ba4\u53ea\u6709\u4e00\u4e2a\u5e03\u5c40\u7ba1\u7406\u5668\u7684\u65f6\u5019\u624d\u80fd\u8d77\u4f5c\u7528<\/span><span style=\"color:#0d0016\">\u3002\u5e76\u4e14\u5982\u679c\u6211\u4eec\u901a\u8fc7QtDesigner\u65b9\u5f0f\u6dfb\u52a0\u5e03\u5c40\u7ba1\u7406\u5668\u7684\u8bdd\u662f\u9ed8\u8ba4\u4e5f\u4e0d\u8d77\u6548\u679c\u7684&#xff0c;\u5b9e\u9645\u4e0a&#xff0c;\u901a\u8fc7QtDesigner\u65b9\u5f0f\u521b\u5efa\u4e00\u4e2a\u5e03\u5c40\u7ba1\u7406\u5668\u76f8\u5f53\u4e8e\u5148\u521b\u5efa\u4e00\u4e2a\u65b0\u7684Widget\u7136\u540e\u5728Widget\u91cc\u9762\u521b\u5efa\u5e03\u5c40\u7ba1\u7406\u5668&#xff0c;\u8fd9\u6837\u5bf9\u4e8e\u9876\u5c42\u7a97\u53e3\u6765\u8bf4\u662f\u6ca1\u6709\u5e03\u5c40\u7ba1\u7406\u5668\u7684&#xff0c;\u56e0\u6b64\u65e0\u6548&#xff0c;\u867d\u7136Designer\u4e0d\u5728\u5bf9\u8c61\u6811\u663e\u793a\u8fd9\u4e00\u70b9&#xff0c;\u6211\u4eec\u4ecexml\u6587\u4ef6\u4e2d\u4e5f\u53ef\u4ee5\u770b\u51fa&#xff1a;<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"785\" src=\"2026-02-07oxwjl3snuku.png\" width=\"1507\" \/><\/p>\n<hr \/>\n<h3 id=\"QHBoxLayout(%E6%B0%B4%E5%B9%B3%E5%B8%83%E5%B1%80%E7%AE%A1%E7%90%86%E5%99%A8)\" style=\"background-color:transparent\"><span style=\"color:#0d0016\">QHBoxLayout(\u6c34\u5e73\u5e03\u5c40\u7ba1\u7406\u5668)<\/span><\/h3>\n<p><span style=\"color:#0d0016\">\u7279\u6027\u548c\u5782\u76f4\u5e03\u5c40\u7ba1\u7406\u5668\u76f8\u540c&#xff0c;\u6211\u4eec\u76f4\u63a5\u5199\u4e00\u4e2a\u4f8b\u5b50&#xff1a;<\/span><\/p>\n<p>Widget::Widget(QWidget *parent)<br \/>\n    : QWidget(parent)<br \/>\n    , ui(new Ui::Widget)<br \/>\n{<br \/>\n    ui-&gt;setupUi(this);<\/p>\n<p>    QPushButton *a &#061; new QPushButton(&#034;\u6309\u94ae1&#034;);<br \/>\n    QPushButton *b &#061; new QPushButton(&#034;\u6309\u94ae2&#034;);<br \/>\n    QPushButton *c &#061; new QPushButton(&#034;\u6309\u94ae2&#034;);<br \/>\n    QPushButton *d &#061; new QPushButton(&#034;\u6309\u94ae2&#034;);<\/p>\n<p>    \/\/\u521b\u5efa\u6c34\u5e73\u5e03\u5c40\u7ba1\u7406\u5668<br \/>\n    QHBoxLayout* layout1 &#061; new QHBoxLayout();<br \/>\n    layout1-&gt;addWidget(c);<br \/>\n    layout1-&gt;addWidget(d);<\/p>\n<p>    \/\/\u521b\u5efa\u5782\u76f4\u5e03\u5c40\u7ba1\u7406\u5668<br \/>\n    QVBoxLayout* layout2 &#061; new QVBoxLayout();<br \/>\n    \/\/\u7ed9\u5782\u76f4\u5e03\u5c40\u7ba1\u7406\u5668\u6dfb\u52a0\u5143\u7d20<br \/>\n    layout2-&gt;addWidget(a);<br \/>\n    layout2-&gt;addWidget(b);<br \/>\n    layout2-&gt;addLayout(layout1);<\/p>\n<p>    \/\/\u7ed9\u5f53\u524d\u7a97\u53e3\u6dfb\u52a0\u5e03\u5c40\u7ba1\u7406\u5668<br \/>\n    this-&gt;setLayout(layout2);<br \/>\n}<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"621\" src=\"2026-02-07ri41rddli4r.png\" width=\"810\" \/><\/p>\n<p><span style=\"color:#0d0016\">\u6ce8\u610f&#xff1a;\u5e03\u5c40\u7ba1\u7406\u5668\u4e4b\u95f4\u53ef\u4ee5\u5d4c\u5957&#xff0c;\u4e0a\u9762\u7684\u4f8b\u5b50\u5c31\u662f\u7528\u5782\u76f4\u5e03\u5c40\u7ba1\u7406\u5668\u5d4c\u5957\u4e86\u6c34\u5e73\u5e03\u5c40\u7ba1\u7406\u5668\u3002<\/span><\/p>\n<hr \/>\n<h3 id=\"QGridLayout\" style=\"background-color:transparent\"><span style=\"color:#0d0016\">QGridLayout<\/span><\/h3>\n<p><span style=\"color:#0d0016\">QVBoxLayout\u53ea\u662f\u5782\u76f4\u65b9\u5411\u4e0a\u7684\u5e03\u5c40\u7ba1\u7406&#xff0c;QHBoxLayout\u53ea\u662f\u6c34\u5e73\u4e0a\u7684\u5e03\u5c40\u7ba1\u7406&#xff0c;\u4e3a\u4e86\u5b9e\u73b0\u4e8c\u7ef4\u5e03\u5c40\u7ba1\u7406&#xff0c;\u6211\u5728QHBoxLayout\u4e2d\u4f7f\u7528\u4e86\u5e03\u5c40\u7ba1\u7406\u5668\u5d4c\u5957\u7684\u65b9\u5f0f&#xff0c;\u4f46\u662f\u8fd9\u6837\u505a\u672a\u514d\u8fc7\u4e8e\u7e41\u7410\u3002<\/span><span style=\"color:#fe2c24\">QGridLayout\u5c31\u662f\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u7684\u4e8c\u7ef4\u5e03\u5c40\u7ba1\u7406\u5668<\/span><span style=\"color:#0d0016\">\u3002<\/span><\/p>\n<p><span style=\"color:#0d0016\">\u4e0b\u9762\u662f\u5b83\u7684\u4e3b\u8981\u5c5e\u6027&#xff1a;<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"604\" src=\"2026-02-07nba3hhtkwhd.png\" width=\"917\" \/><\/p>\n<p><span style=\"color:#0d0016\">\u4e0b\u9762\u662f\u4f7f\u7528\u7684\u4f8b\u5b50&#xff1a;<\/span><\/p>\n<p>Widget::Widget(QWidget *parent)<br \/>\n    : QWidget(parent)<br \/>\n    , ui(new Ui::Widget)<br \/>\n{<br \/>\n    ui-&gt;setupUi(this);<\/p>\n<p>    QPushButton *a &#061; new QPushButton(&#034;\u6309\u94ae1&#034;);<br \/>\n    QPushButton *b &#061; new QPushButton(&#034;\u6309\u94ae2&#034;);<br \/>\n    QPushButton *c &#061; new QPushButton(&#034;\u6309\u94ae2&#034;);<br \/>\n    QPushButton *d &#061; new QPushButton(&#034;\u6309\u94ae2&#034;);<\/p>\n<p>    \/\/\u521b\u5efaGrid\u5e03\u5c40\u7ba1\u7406\u5668<br \/>\n    QGridLayout* layout &#061; new QGridLayout();<br \/>\n    layout-&gt;addWidget(a,0,0);\/\/\u6dfb\u52a0\u63a7\u4ef6\u7684\u65f6\u5019\u6307\u660e\u63a7\u4ef6\u5904\u5728\u7ba1\u7406\u5668\u4e2d\u7684\u4f4d\u7f6e\u5750\u6807<br \/>\n    layout-&gt;addWidget(b,1,0);<br \/>\n    layout-&gt;addWidget(c,2,0);<br \/>\n    layout-&gt;addWidget(d,2,100);<\/p>\n<p>    \/\/\u7ed9\u5f53\u524d\u7a97\u53e3\u6dfb\u52a0\u5e03\u5c40\u7ba1\u7406\u5668<br \/>\n    this-&gt;setLayout(layout);<br \/>\n}<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"403\" src=\"2026-02-07ontrpisqt53.png\" width=\"703\" \/><\/p>\n<p><span style=\"color:#fe2c24\">\u6211\u5728\u6dfb\u52a0d\u6309\u94ae\u7684\u65f6\u5019\u7279\u5730\u5199\u4e86100\u8fd9\u4e2a\u5f88\u5927\u7684\u6570\u5b57&#xff0c;\u4f46\u662fd\u6309\u94ae\u5e76\u6ca1\u6709\u8dd1\u5230\u5f88\u8fdc\u7684\u5730\u65b9&#xff0c;\u56e0\u6b64&#xff0c;\u6211\u4eec\u6307\u5b9a\u7684\u5750\u6807\u53ea\u662f\u6307\u5b9a\u76f8\u5bf9\u987a\u5e8f\u800c\u4e0d\u662f\u6574\u6574\u610f\u4e49\u4e0a\u7684\u5750\u6807<\/span><span style=\"color:#0d0016\">\u3002<\/span><\/p>\n<p><span style=\"color:#0d0016\">\u4e0b\u9762\u662f\u5173\u4e8e\u6c34\u5e73\u62c9\u4f38\u7cfb\u6570\u7684\u4f7f\u7528\u793a\u4f8b&#xff1a;<\/span><\/p>\n<p>Widget::Widget(QWidget *parent)<br \/>\n    : QWidget(parent)<br \/>\n    , ui(new Ui::Widget)<br \/>\n{<br \/>\n    ui-&gt;setupUi(this);<\/p>\n<p>    QPushButton *a &#061; new QPushButton(&#034;\u6309\u94ae1&#034;);<br \/>\n    QPushButton *b &#061; new QPushButton(&#034;\u6309\u94ae2&#034;);<br \/>\n    QPushButton *c &#061; new QPushButton(&#034;\u6309\u94ae3&#034;);<br \/>\n    QPushButton *d &#061; new QPushButton(&#034;\u6309\u94ae4&#034;);<br \/>\n    QPushButton *e &#061; new QPushButton(&#034;\u6309\u94ae5&#034;);<br \/>\n    QPushButton *f &#061; new QPushButton(&#034;\u6309\u94ae6&#034;);<\/p>\n<p>    \/\/\u521b\u5efaGrid\u5e03\u5c40\u7ba1\u7406\u5668<br \/>\n    QGridLayout* layout &#061; new QGridLayout();<br \/>\n    layout-&gt;addWidget(a,0,0);\/\/\u6dfb\u52a0\u63a7\u4ef6\u7684\u65f6\u5019\u6307\u660e\u63a7\u4ef6\u5904\u5728\u7ba1\u7406\u5668\u4e2d\u7684\u4f4d\u7f6e\u5750\u6807<br \/>\n    layout-&gt;addWidget(b,0,1);<br \/>\n    layout-&gt;addWidget(c,0,2);<br \/>\n    layout-&gt;addWidget(d,1,0);<br \/>\n    layout-&gt;addWidget(e,1,1);<br \/>\n    layout-&gt;addWidget(f,1,2);<\/p>\n<p>    \/\/\u8bbe\u7f6e\u67d0\u4e00\u5217\u7684\u6c34\u5e73\u62c9\u5347\u7cfb\u6570&#xff08;\u5217\u4e0e\u5217\u4e4b\u4e2d\u63a7\u4ef6\u7684\u5bbd\u5ea6\u6bd4&#xff09;<br \/>\n    layout-&gt;setColumnStretch(0,0);<br \/>\n    layout-&gt;setColumnStretch(1,1);<br \/>\n    layout-&gt;setColumnStretch(2,2);<\/p>\n<p>    \/\/\u7ed9\u5f53\u524d\u7a97\u53e3\u6dfb\u52a0\u5e03\u5c40\u7ba1\u7406\u5668<br \/>\n    this-&gt;setLayout(layout);<br \/>\n}<\/p>\n<p> <img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"265\" src=\"2026-02-07jci5dev4ral.png\" width=\"796\" \/><\/p>\n<p><span style=\"color:#fe2c24\">layout-&gt;setColumnStretch(0,0);\u5e76\u4e0d\u4ee3\u8868\u6bd4\u4f8b\u4e3a0&#xff0c;\u800c\u662f\u4ee3\u8868\u8fd9\u4e00\u5217\u7684\u63a7\u4ef6\u4e0d\u53c2\u4e0e\u6309\u7167\u6bd4\u4f8b\u53d8\u5316\u7684\u8fc7\u7a0b<\/span><span style=\"color:#0d0016\">\u3002<\/span><\/p>\n<p><span style=\"color:#0d0016\">\u4e0b\u9762\u662f\u5173\u4e8e\u5782\u76f4\u62c9\u4f38\u7cfb\u6570\u7684\u4f7f\u7528\u793a\u4f8b&#xff1a;<\/span><\/p>\n<p>Widget::Widget(QWidget *parent)<br \/>\n    : QWidget(parent)<br \/>\n    , ui(new Ui::Widget)<br \/>\n{<br \/>\n    ui-&gt;setupUi(this);<\/p>\n<p>    QPushButton *a &#061; new QPushButton(&#034;\u6309\u94ae1&#034;);<br \/>\n    QPushButton *b &#061; new QPushButton(&#034;\u6309\u94ae2&#034;);<br \/>\n    QPushButton *c &#061; new QPushButton(&#034;\u6309\u94ae3&#034;);<br \/>\n    QPushButton *d &#061; new QPushButton(&#034;\u6309\u94ae4&#034;);<br \/>\n    QPushButton *e &#061; new QPushButton(&#034;\u6309\u94ae5&#034;);<br \/>\n    QPushButton *f &#061; new QPushButton(&#034;\u6309\u94ae6&#034;);<\/p>\n<p>    \/\/\u521b\u5efaGrid\u5e03\u5c40\u7ba1\u7406\u5668<br \/>\n    QGridLayout* layout &#061; new QGridLayout();<br \/>\n    layout-&gt;addWidget(a,0,0);\/\/\u6dfb\u52a0\u63a7\u4ef6\u7684\u65f6\u5019\u6307\u660e\u63a7\u4ef6\u5904\u5728\u7ba1\u7406\u5668\u4e2d\u7684\u4f4d\u7f6e\u5750\u6807<br \/>\n    layout-&gt;addWidget(b,0,1);<br \/>\n    layout-&gt;addWidget(c,0,2);<br \/>\n    layout-&gt;addWidget(d,1,0);<br \/>\n    layout-&gt;addWidget(e,1,1);<br \/>\n    layout-&gt;addWidget(f,1,2);<\/p>\n<p>    \/\/\u8bbe\u7f6e\u67d0\u4e00\u884c\u7684\u5782\u76f4\u62c9\u5347\u7cfb\u6570&#xff08;\u884c\u4e0e\u884c\u4e4b\u4e2d\u63a7\u4ef6\u7684\u5bbd\u5ea6\u6bd4&#xff09;<br \/>\n    layout-&gt;setRowStretch(0,0);<br \/>\n    layout-&gt;setRowStretch(1,1);<\/p>\n<p>    \/\/\u7ed9\u5f53\u524d\u7a97\u53e3\u6dfb\u52a0\u5e03\u5c40\u7ba1\u7406\u5668<br \/>\n    this-&gt;setLayout(layout);<br \/>\n} <\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"350\" src=\"2026-02-07wkf5ve5c31z.png\" width=\"636\" \/><\/p>\n<hr \/>\n<h3 id=\"%E9%A2%98%E5%A4%96%E8%AF%9D%E2%80%94%E2%80%94%E6%8E%A7%E4%BB%B6%E5%A4%A7%E5%B0%8F%E7%AD%96%E7%95%A5%E5%AF%B9%E5%B8%83%E5%B1%80%E7%9A%84%E5%BD%B1%E5%93%8D\"><span style=\"color:#0d0016\">\u9898\u5916\u8bdd\u2014\u2014\u63a7\u4ef6\u5927\u5c0f\u7b56\u7565\u5bf9\u5e03\u5c40\u7684\u5f71\u54cd<\/span><\/h3>\n<p><span style=\"color:#0d0016\">\u6211\u4eec\u53d1\u73b0&#xff0c;\u4e0a\u9762\u5782\u76f4\u62c9\u4f38\u7cfb\u6570\u7684\u8bbe\u7f6e\u5b8c\u5168\u6ca1\u6709\u6548\u679c&#xff0c;\u56e0\u4e3a<\/span><span style=\"color:#fe2c24\">\u6309\u94ae&#xff08;\u5176\u5b83\u63a7\u4ef6\u4e00\u822c\u4e5f\u6709\u8fd9\u79cd\u60c5\u51b5&#xff09;\u7684\u5927\u5c0f\u7b56\u7565\u4f1a\u5f71\u54cd\u5e03\u5c40<\/span><span style=\"color:#0d0016\">&#xff1a;<\/span><\/p>\n<p><span style=\"color:#fe2c24\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"302\" src=\"2026-02-071udrs0slhuh.png\" width=\"1095\" \/><\/span><\/p>\n<p><span style=\"color:#0d0016\">\u6211\u4eec\u4fee\u6539\u4ee3\u7801&#xff1a;<\/span><\/p>\n<p>Widget::Widget(QWidget *parent)<br \/>\n    : QWidget(parent)<br \/>\n    , ui(new Ui::Widget)<br \/>\n{<br \/>\n    ui-&gt;setupUi(this);<\/p>\n<p>    QPushButton *a &#061; new QPushButton(&#034;\u6309\u94ae1&#034;);<br \/>\n    QPushButton *b &#061; new QPushButton(&#034;\u6309\u94ae2&#034;);<br \/>\n    QPushButton *c &#061; new QPushButton(&#034;\u6309\u94ae3&#034;);<br \/>\n    QPushButton *d &#061; new QPushButton(&#034;\u6309\u94ae4&#034;);<br \/>\n    QPushButton *e &#061; new QPushButton(&#034;\u6309\u94ae5&#034;);<br \/>\n    QPushButton *f &#061; new QPushButton(&#034;\u6309\u94ae6&#034;);<\/p>\n<p>    \/\/\u521b\u5efaGrid\u5e03\u5c40\u7ba1\u7406\u5668<br \/>\n    QGridLayout* layout &#061; new QGridLayout();<br \/>\n    layout-&gt;addWidget(a,0,0);\/\/\u6dfb\u52a0\u63a7\u4ef6\u7684\u65f6\u5019\u6307\u660e\u63a7\u4ef6\u5904\u5728\u7ba1\u7406\u5668\u4e2d\u7684\u4f4d\u7f6e\u5750\u6807<br \/>\n    layout-&gt;addWidget(b,0,1);<br \/>\n    layout-&gt;addWidget(c,0,2);<br \/>\n    layout-&gt;addWidget(d,1,0);<br \/>\n    layout-&gt;addWidget(e,1,1);<br \/>\n    layout-&gt;addWidget(f,1,2);<\/p>\n<p>    \/\/\u8bbe\u7f6e\u6309\u94ae\u7684\u5c3a\u5bf8\u63aa\u65bd<br \/>\n    a-&gt;setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);<br \/>\n    b-&gt;setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);<br \/>\n    c-&gt;setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);<br \/>\n    d-&gt;setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);<br \/>\n    e-&gt;setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);<br \/>\n    f-&gt;setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);<\/p>\n<p>    \/\/\u8bbe\u7f6e\u67d0\u4e00\u884c\u7684\u5782\u76f4\u62c9\u5347\u7cfb\u6570&#xff08;\u884c\u4e0e\u884c\u4e4b\u4e2d\u63a7\u4ef6\u7684\u5bbd\u5ea6\u6bd4&#xff09;<br \/>\n    layout-&gt;setRowStretch(0,0);<br \/>\n    layout-&gt;setRowStretch(1,1);<\/p>\n<p>    \/\/\u7ed9\u5f53\u524d\u7a97\u53e3\u6dfb\u52a0\u5e03\u5c40\u7ba1\u7406\u5668<br \/>\n    this-&gt;setLayout(layout);<br \/>\n} <\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"273\" src=\"2026-02-07xneagds1k14.png\" width=\"660\" \/><\/p>\n<p><span style=\"color:#0d0016\">\u6709\u6548\u679c\u4e86\u3002<\/span><\/p>\n<hr \/>\n<h3 id=\"QFormLayout%EF%BC%88%E8%A1%A8%E5%8D%95%E5%B8%83%E5%B1%80%E7%AE%A1%E7%90%86%E5%99%A8%EF%BC%89\"><span style=\"color:#0d0016\">QFormLayout&#xff08;\u8868\u5355\u5e03\u5c40\u7ba1\u7406\u5668&#xff09;<\/span><\/h3>\n<p><span style=\"color:#0d0016\">\u672c\u8d28\u4e0a\u662fQGridLayout\u7684\u7279\u6b8a\u60c5\u51b5&#xff0c;\u7528\u4e8e\u521b\u5efa\u8868\u5355\u7c7b\u578b\u7684\u5e03\u5c40\u3002<\/span><\/p>\n<p><span style=\"color:#0d0016\">\u76f4\u63a5\u5199\u4e00\u4e2a\u4f7f\u7528\u793a\u4f8b&#xff1a;<\/span><\/p>\n<p>Widget::Widget(QWidget *parent)<br \/>\n    : QWidget(parent)<br \/>\n    , ui(new Ui::Widget)<br \/>\n{<br \/>\n    ui-&gt;setupUi(this);<\/p>\n<p>    QLabel* label1 &#061; new QLabel(&#034;\u59d3\u540d&#034;);<br \/>\n    QLabel* label2 &#061; new QLabel(&#034;\u7535\u8bdd&#034;);<br \/>\n    QLineEdit* line1 &#061; new QLineEdit();<br \/>\n    QLineEdit* line2 &#061; new QLineEdit();<br \/>\n    \/\/\u521b\u5efa\u8868\u5355\u5e03\u5c40\u7ba1\u7406\u5668<br \/>\n    QFormLayout* layout &#061; new QFormLayout();<br \/>\n    layout-&gt;addRow(label1,line1);\/\/\u6bcf\u6b21\u6dfb\u52a0\u4e00\u884c&#xff0c;\u6bcf\u884c\u7531\u4e24\u4e2a\u90e8\u5206\u7ec4\u6210<br \/>\n    layout-&gt;addRow(label2,line2);<\/p>\n<p>    \/\/\u7ed9\u5f53\u524d\u7a97\u53e3\u6dfb\u52a0\u5e03\u5c40\u7ba1\u7406\u5668<br \/>\n    this-&gt;setLayout(layout);<br \/>\n}<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"349\" src=\"2026-02-07x5pr2om4ter.png\" width=\"750\" \/><\/p>\n<hr \/>\n<h3 id=\"QSpacerItem\" style=\"background-color:transparent\"><span style=\"color:#0d0016\">QSpacerItem<\/span><\/h3>\n<p> <span style=\"color:#0d0016\">\u4f7f\u7528\u5e03\u5c40\u7ba1\u7406\u5668\u7684\u65f6\u5019, \u53ef\u80fd\u9700\u8981\u5728\u63a7\u4ef6\u4e4b\u95f4, \u6dfb\u52a0\u2f00\u6bb5\u7a7a\u767d\u3002\u00a0\u5c31\u53ef\u4ee5\u4f7f\u7528QSpacerItem\u6765\u8868\u793a\u3002<\/span><\/p>\n<p> <span style=\"color:#0d0016\">\u4e0b\u9762\u662f\u4f7f\u7528\u793a\u4f8b&#xff1a;<\/span><\/p>\n<p>Widget::Widget(QWidget *parent)<br \/>\n    : QWidget(parent)<br \/>\n    , ui(new Ui::Widget)<br \/>\n{<br \/>\n    ui-&gt;setupUi(this);<\/p>\n<p>    QPushButton* a &#061; new QPushButton();<br \/>\n    QPushButton* b &#061; new QPushButton();<br \/>\n    QPushButton* c &#061; new QPushButton();<br \/>\n    QPushButton* d &#061; new QPushButton();<br \/>\n    \/\/\u521b\u5efa\u8868\u5355\u5e03\u5c40\u7ba1\u7406\u5668<br \/>\n    QHBoxLayout* layout &#061; new QHBoxLayout();<br \/>\n    \/\/\u7ed9\u5f53\u524d\u7a97\u53e3\u6dfb\u52a0\u5e03\u5c40\u7ba1\u7406\u5668<br \/>\n    this-&gt;setLayout(layout);<\/p>\n<p>    \/\/\u521b\u5efaSpacer\u5bf9\u8c61<br \/>\n    QSpacerItem* sp &#061; new QSpacerItem(200,200);<\/p>\n<p>    layout-&gt;addWidget(a);<br \/>\n    layout-&gt;addWidget(b);<br \/>\n    layout-&gt;addWidget(c);<br \/>\n    layout-&gt;addSpacerItem(sp);\/\/\u6dfb\u52a0\u7a7a\u767d<br \/>\n    layout-&gt;addWidget(d);<br \/>\n}<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"340\" src=\"2026-02-07rmtkspz22z0.png\" width=\"722\" \/><\/p>\n<hr \/>\n<p><span style=\"color:#0d0016\">\u6bcf\u4e2a\u63a7\u4ef6\u90fd\u662fQt\u4e2d\u5185\u7f6e\u7684\u7c7b&#xff0c;\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u7ee7\u627f\u8005\u8fd9\u4e9b\u7c7b&#xff0c;\u589e\u52a0\u65b0\u7684\u5c5e\u6027\u548c\u65b9\u6cd5&#xff0c;\u7ec4\u5408\u51fa\u65b0\u7684\u63a7\u4ef6&#xff0c;\u8fd9\u4e9b\u90fd\u662f\u53ef\u4ee5\u7684\u3002<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u76ee\u5f55<br \/>\n\u6309\u94ae\u7c7b\u63a7\u4ef6<br \/>\nQPushButton<br \/>\n\u8bbe\u7f6e\u6309\u94ae\u6587\u672c<br \/>\n\u7ed9\u6309\u94ae\u8bbe\u7f6e\u56fe\u6807<br \/>\n\u8bbe\u7f6e\u6309\u94ae\u5feb\u6377\u952e<br \/>\n\u8bbe\u7f6e\u6309\u94ae\u91cd\u590d\u89e6\u53d1<br \/>\nQRadioButton<br \/>\n\u8bbe\u7f6e\u9009\u9879\u662f\u5426\u88ab\u9009\u4e2d<br \/>\n\u8bbe\u7f6e\u9009\u9879\u662f\u5426\u53ef\u4ee5\u9009\u4e2d<br \/>\n\u8bbe\u7f6e\u9009\u9879\u7981\u7528<br \/>\n\u8bbe\u7f6e\u9009\u9879\u662f\u5426\u6392\u4ed6<br \/>\n\u5c06\u9009\u9879\u5206\u7ec4<br \/>\n\u9898\u5916\u8bdd-\u6309\u94ae(\u9009\u9879)\u76f8\u5173\u7684\u4fe1\u53f7<br \/>\nQCheckBox \u8bbe\u7f6e\u9009\u9879\u662f\u5426\u88ab\u9009\u4e2d<br \/>\n\u8bbe\u7f6e\u9009\u9879\u662f\u5426\u53ef\u4ee5\u9009\u4e2d<br \/>\n\u663e\u793a\u7c7b\u63a7\u4ef6<br \/>\nQLabel<br \/>\n\u8bbe\u7f6e\u6587\u672c\u5185\u5bb9<br \/>\n\u8bbe\u7f6elabel\u6587\u672c\u7684\u683c\u5f0f<br \/>\n\u7ed9label\u6dfb\u52a0\u56fe\u7247<br \/>\n\u8bbe\u7f6e\u5185\u5bb9(\u4e3b\u8981\u6307\u56fe\u7247)\u81ea\u52a8\u62c9\u4f38\u586b\u5145\u6574\u4e2a<\/p>\n","protected":false},"author":2,"featured_media":73447,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[218,190],"topic":[],"class_list":["post-73467","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-qt","tag-190"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Qt\u2014\u2014\u5e38\u7528\u63a7\u4ef6 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/73467.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Qt\u2014\u2014\u5e38\u7528\u63a7\u4ef6 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u76ee\u5f55 \u6309\u94ae\u7c7b\u63a7\u4ef6 QPushButton \u8bbe\u7f6e\u6309\u94ae\u6587\u672c \u7ed9\u6309\u94ae\u8bbe\u7f6e\u56fe\u6807 \u8bbe\u7f6e\u6309\u94ae\u5feb\u6377\u952e \u8bbe\u7f6e\u6309\u94ae\u91cd\u590d\u89e6\u53d1 QRadioButton \u8bbe\u7f6e\u9009\u9879\u662f\u5426\u88ab\u9009\u4e2d \u8bbe\u7f6e\u9009\u9879\u662f\u5426\u53ef\u4ee5\u9009\u4e2d \u8bbe\u7f6e\u9009\u9879\u7981\u7528 \u8bbe\u7f6e\u9009\u9879\u662f\u5426\u6392\u4ed6 \u5c06\u9009\u9879\u5206\u7ec4 \u9898\u5916\u8bdd-\u6309\u94ae(\u9009\u9879)\u76f8\u5173\u7684\u4fe1\u53f7 QCheckBox \u8bbe\u7f6e\u9009\u9879\u662f\u5426\u88ab\u9009\u4e2d \u8bbe\u7f6e\u9009\u9879\u662f\u5426\u53ef\u4ee5\u9009\u4e2d \u663e\u793a\u7c7b\u63a7\u4ef6 QLabel \u8bbe\u7f6e\u6587\u672c\u5185\u5bb9 \u8bbe\u7f6elabel\u6587\u672c\u7684\u683c\u5f0f \u7ed9label\u6dfb\u52a0\u56fe\u7247 \u8bbe\u7f6e\u5185\u5bb9(\u4e3b\u8981\u6307\u56fe\u7247)\u81ea\u52a8\u62c9\u4f38\u586b\u5145\u6574\u4e2a\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/73467.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-02-07T09:06:22+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260207090615-6987008799d63.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"16 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/73467.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/73467.html\",\"name\":\"Qt\u2014\u2014\u5e38\u7528\u63a7\u4ef6 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-02-07T09:06:22+00:00\",\"dateModified\":\"2026-02-07T09:06:22+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/73467.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/73467.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/73467.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Qt\u2014\u2014\u5e38\u7528\u63a7\u4ef6\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Qt\u2014\u2014\u5e38\u7528\u63a7\u4ef6 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/73467.html","og_locale":"zh_CN","og_type":"article","og_title":"Qt\u2014\u2014\u5e38\u7528\u63a7\u4ef6 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u76ee\u5f55 \u6309\u94ae\u7c7b\u63a7\u4ef6 QPushButton \u8bbe\u7f6e\u6309\u94ae\u6587\u672c \u7ed9\u6309\u94ae\u8bbe\u7f6e\u56fe\u6807 \u8bbe\u7f6e\u6309\u94ae\u5feb\u6377\u952e \u8bbe\u7f6e\u6309\u94ae\u91cd\u590d\u89e6\u53d1 QRadioButton \u8bbe\u7f6e\u9009\u9879\u662f\u5426\u88ab\u9009\u4e2d \u8bbe\u7f6e\u9009\u9879\u662f\u5426\u53ef\u4ee5\u9009\u4e2d \u8bbe\u7f6e\u9009\u9879\u7981\u7528 \u8bbe\u7f6e\u9009\u9879\u662f\u5426\u6392\u4ed6 \u5c06\u9009\u9879\u5206\u7ec4 \u9898\u5916\u8bdd-\u6309\u94ae(\u9009\u9879)\u76f8\u5173\u7684\u4fe1\u53f7 QCheckBox \u8bbe\u7f6e\u9009\u9879\u662f\u5426\u88ab\u9009\u4e2d \u8bbe\u7f6e\u9009\u9879\u662f\u5426\u53ef\u4ee5\u9009\u4e2d \u663e\u793a\u7c7b\u63a7\u4ef6 QLabel \u8bbe\u7f6e\u6587\u672c\u5185\u5bb9 \u8bbe\u7f6elabel\u6587\u672c\u7684\u683c\u5f0f \u7ed9label\u6dfb\u52a0\u56fe\u7247 \u8bbe\u7f6e\u5185\u5bb9(\u4e3b\u8981\u6307\u56fe\u7247)\u81ea\u52a8\u62c9\u4f38\u586b\u5145\u6574\u4e2a","og_url":"https:\/\/www.wsisp.com\/helps\/73467.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-02-07T09:06:22+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260207090615-6987008799d63.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"16 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/73467.html","url":"https:\/\/www.wsisp.com\/helps\/73467.html","name":"Qt\u2014\u2014\u5e38\u7528\u63a7\u4ef6 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-02-07T09:06:22+00:00","dateModified":"2026-02-07T09:06:22+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/73467.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/73467.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/73467.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"Qt\u2014\u2014\u5e38\u7528\u63a7\u4ef6"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/73467","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=73467"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/73467\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/73447"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=73467"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=73467"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=73467"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=73467"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}