{"id":106320,"date":"2026-09-17T06:56:30","date_gmt":"2026-09-16T22:56:30","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/106320.html"},"modified":"2026-09-17T06:56:30","modified_gmt":"2026-09-16T22:56:30","slug":"%e3%80%90qt%e3%80%91%e3%80%8aqt-5-9-c%e5%bc%80%e5%8f%91%e6%8c%87%e5%8d%97%e3%80%8b%e7%ac%94%e8%ae%b0-chapter4-%e5%b8%b8%e7%94%a8%e7%95%8c%e9%9d%a2%e8%ae%be%e8%ae%a1%e7%bb%84%e4%bb%b6","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/106320.html","title":{"rendered":"\u3010Qt\u3011\u300aQt 5.9 C++\u5f00\u53d1\u6307\u5357\u300b\u7b14\u8bb0-Chapter4-\u5e38\u7528\u754c\u9762\u8bbe\u8ba1\u7ec4\u4ef6"},"content":{"rendered":"<h2>\u7b2c4\u7ae0\u3000\u5e38\u7528\u754c\u9762\u8bbe\u8ba1\u7ec4\u4ef6<\/h2>\n<p>\u7b2c2\u7ae0\u5df2\u7ecf\u4ecb\u7ecd\u4e86\u8bbe\u8ba1GUI\u5e94\u7528\u7a0b\u5e8f\u7684\u57fa\u672c\u539f\u7406\u548c\u65b9\u6cd5&#xff0c;\u5728\u638c\u63e1\u4e86\u7528Qt Creator\u8bbe\u8ba1\u5e94\u7528\u7a0b\u5e8f\u7684\u57fa\u672c\u65b9\u6cd5\u4e4b\u540e&#xff0c;\u8981\u5e94\u7528Qt\u7f16\u5199\u5404\u79cd\u5e94\u7528\u7a0b\u5e8f&#xff0c;\u91cd\u8981\u7684\u5c31\u662f\u719f\u7ec3\u638c\u63e1Qt\u7c7b\u5e93\u91cc\u5404\u79cd\u7528\u4e8e\u754c\u9762\u8bbe\u8ba1\u6216\u5176\u4ed6\u529f\u80fd\u7684\u7c7b\u7684\u4f7f\u7528\u3002<\/p>\n<p>Qt\u7c7b\u5e93\u4e3a\u5e94\u7528\u7a0b\u5e8f\u8bbe\u8ba1\u63d0\u4f9b\u4e86\u5927\u91cf\u7684\u7c7b&#xff0c;\u672c\u7ae0\u4e3b\u8981\u4ecb\u7ecd\u8bbe\u8ba1GUI\u5e94\u7528\u7a0b\u5e8f\u5e38\u7528\u7684\u5404\u79cd\u754c\u9762\u7ec4\u4ef6\u7684\u4f7f\u7528&#xff0c;\u8fd9\u4e9b\u662f\u8bbe\u8ba1GUI\u5e94\u7528\u7a0b\u5e8f\u7684\u57fa\u7840\u3002<\/p>\n<h3>4.1\u3000\u5b57\u7b26\u4e32\u4e0e\u8f93\u5165\u8f93\u51fa<\/h3>\n<h4>4.1.1\u5b57\u7b26\u4e32\u4e0e\u6570\u503c\u4e4b\u95f4\u7684\u8f6c\u6362<\/h4>\n<p>\u754c\u9762\u8bbe\u8ba1\u65f6\u4f7f\u7528\u6700\u591a\u7684\u7ec4\u4ef6\u6050\u6015\u5c31\u662fQLabel\u548cQLineEdit\u4e86&#xff0c;QLabel\u7528\u4e8e\u663e\u793a\u5b57\u7b26\u4e32&#xff0c;QLineEdit\u7528\u4e8e\u663e\u793a\u548c\u8f93\u5165\u5b57\u7b26\u4e32\u3002\u8fd9\u4e24\u4e2a\u7c7b\u90fd\u6709\u5982\u4e0b\u7684\u4e24\u4e2a\u51fd\u6570\u7528\u4e8e\u8bfb\u53d6\u548c\u8bbe\u7f6e\u663e\u793a\u6587\u5b57\u3002<\/p>\n<p>QString  text() const<br \/>\nvoid  setText(const QString &amp;)<\/p>\n<p>\u8fd9\u4e24\u4e2a\u51fd\u6570\u90fd\u6d89\u53ca\u5230QString\u7c7b\u3002QString\u7c7b\u662fQt\u7a0b\u5e8f\u91cc\u7ecf\u5e38\u4f7f\u7528\u7684\u7c7b&#xff0c;\u7528\u4e8e\u5904\u7406\u5b57\u7b26\u4e32\u3002QString\u7c7b\u53ef\u4ee5\u8fdb\u884c\u5b57\u7b26\u4e32\u4e0e\u6570\u5b57\u4e4b\u95f4\u7684\u8f6c\u6362&#xff0c;\u4f7f\u7528QLineEdit\u5c31\u53ef\u4ee5\u5b9e\u73b0\u6570\u5b57\u91cf\u7684\u8f93\u5165\u4e0e\u8f93\u51fa\u3002<\/p>\n<p>\u539f\u4e66\u7684\u56fe4-1\u662f\u5b9e\u4f8bsamp4_1\u8bbe\u8ba1\u65f6\u7684\u7a97\u4f53&#xff0c;\u662f\u57fa\u4e8eQWidget\u521b\u5efa\u7684\u53ef\u89c6\u5316\u7a97\u4f53\u3002\u754c\u9762\u8bbe\u8ba1\u4f7f\u7528\u4e86\u5e03\u5c40\u7ba1\u7406&#xff0c;\u7a97\u4f53\u4e0a\u7ec4\u4ef6\u7684\u5e03\u5c40\u662f&#xff1a;\u4e0a\u65b9\u7684\u51e0\u4e2a\u7ec4\u4ef6\u662f\u4e00\u4e2aGridLayout&#xff0c;\u4e0b\u65b9\u76849\u4e2a\u7ec4\u4ef6\u4e5f\u662f\u4e00\u4e2aGridLayout&#xff0c;\u4e24\u4e2aGridLayout\u548c\u4e2d\u95f4\u4e00\u4e2aVerticalSpacer\u53c8\u7ec4\u6210\u4e00\u4e2aVerticalLayout\u3002<\/p>\n<p>\u5728\u5e03\u5c40\u8bbe\u8ba1\u65f6&#xff0c;\u8981\u5de7\u5999\u8fd0\u7528VerticalSpacer\u548cHorizontalSpacer&#xff0c;\u8fd8\u8981\u4f1a\u8bbe\u7f6e\u7ec4\u4ef6\u7684MaximumSize\u548cMinimumSize\u5c5e\u6027&#xff0c;\u4ee5\u53d6\u5f97\u671f\u671b\u7684\u5e03\u5c40\u6548\u679c\u3002\u4f8b\u5982&#xff0c;\u5728\u56fe4-1\u4e2d&#xff0c;\u4e24\u4e2aGridLayout\u4e4b\u95f4\u653e\u4e86\u4e00\u4e2a\u5782\u76f4\u65b9\u5411\u7684\u5206\u9694&#xff0c;\u5f53\u7a97\u4f53\u53d8\u5927\u65f6&#xff0c;\u4e24\u4e2aGridLayout\u7684\u9ad8\u5ea6\u5e76\u4e0d\u4f1a\u53d1\u751f\u53d8\u5316&#xff1b;\u800c\u5982\u679c\u4e0d\u653e\u7f6e\u8fd9\u4e2a\u5782\u76f4\u5206\u9694&#xff0c;\u4e24\u4e2aGridLayout\u7684\u9ad8\u5ea6\u90fd\u4f1a\u53d1\u751f\u53d8\u5316&#xff0c;GridLayout\u5185\u90e8\u7ec4\u4ef6\u7684\u5782\u76f4\u8ddd\u79bb\u4f1a\u53d1\u751f\u53d8\u5316\u3002<\/p>\n<h5>1&#xff0e;\u666e\u901a\u6570\u503c\u4e0e\u5b57\u7b26\u4e32\u4e4b\u95f4\u7684\u8f6c\u6362<\/h5>\n<p>\u5728UI\u8bbe\u8ba1\u5668\u91cc&#xff0c;\u9009\u4e2d\u56fe4-1\u4e2d\u7684\u201c\u8ba1\u7b97\u201d\u6309\u94ae&#xff0c;\u5728\u53f3\u952e\u5feb\u6377\u83dc\u5355\u91cc\u5355\u51fb\u201cGo to slot\u2026\u201d&#xff0c;\u5e76\u5728\u51fa\u73b0\u7684\u5bf9\u8bdd\u6846\u91cc\u9009\u62e9clicked()\u4fe1\u53f7\u521b\u5efa\u69fd\u51fd\u6570&#xff0c;\u5728\u81ea\u52a8\u751f\u6210\u7684\u51fd\u6570\u4f53\u91cc\u7f16\u5199\u5982\u4e0b\u7684\u4ee3\u7801&#xff0c;\u5b9e\u73b0\u4ece\u754c\u9762\u4e0a\u5206\u522b\u8bfb\u53d6\u6570\u91cf\u548c\u5355\u4ef7&#xff0c;\u76f8\u4e58\u8ba1\u7b97\u540e\u5c06\u7ed3\u679c\u518d\u663e\u793a\u5230\u6587\u672c\u6846\u91cc\u3002<\/p>\n<p>void Widget::on_btnCal_clicked()<br \/>\n{<br \/>\n   QString str&#061;ui-&gt;editNum-&gt;text();\/\/\u8bfb\u53d6&#034;\u6570\u91cf&#034;<br \/>\n   int num&#061;str.toInt();<br \/>\n   str&#061;ui-&gt;editPrice-&gt;text();\/\/\u8bfb\u53d6&#034;\u5355\u4ef7&#034;<br \/>\n   float   price&#061;str.toFloat();<br \/>\n   float   total&#061;num*price;<br \/>\n   str&#061;str.sprintf(&#034;%.2f&#034;,total);<br \/>\n   ui-&gt;editTotal-&gt;setText(str);<br \/>\n}<\/p>\n<p>QString\u7c7b\u4ece\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u6574\u6570\u7684\u51fd\u6570\u6709&#xff1a;<\/p>\n<p>int     toInt(bool *ok &#061; Q_NULLPTR, int base &#061; 10)      const<br \/>\nlong    toLong (bool *ok &#061; Q_NULLPTR, int base &#061; 10)    const<br \/>\nshort   toShort (bool *ok &#061; Q_NULLPTR, int base &#061; 10)   const<br \/>\nuint    toUInt (bool *ok &#061; Q_NULLPTR, int base &#061; 10)    const<br \/>\nulong   toULong (bool *ok &#061; Q_NULLPTR, int base &#061; 10)   const<\/p>\n<p>\u8fd9\u4e9b\u51fd\u6570\u5982\u679c\u4e0d\u8bbe\u7f6e\u53c2\u6570&#xff0c;\u7f3a\u7701\u8868\u793a\u4ece\u5341\u8fdb\u5236\u8868\u793a\u7684\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u6574\u6570&#xff1b;\u82e5\u6307\u5b9a\u6574\u6570\u57fa\u53c2\u6570&#xff0c;\u8fd8\u53ef\u4ee5\u76f4\u63a5\u5c06\u4e8c\u8fdb\u5236\u3001\u5341\u516d\u8fdb\u5236\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u6574\u6570\u3002<\/p>\n<p>QString\u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u6d6e\u70b9\u6570\u7684\u51fd\u6570\u6709&#xff1a;<\/p>\n<p>double   toDouble(bool *ok &#061; Q_NULLPTR)    const<br \/>\nfloat    toFloat (bool *ok &#061; Q_NULLPTR)    const<\/p>\n<p>\u5728\u5f97\u5230\u5355\u4ef7\u548c\u6570\u91cf\u540e\u505a\u76f8\u4e58\u8fd0\u7b97&#xff0c;\u5f97\u5230\u8ba1\u7b97\u7ed3\u679c\u53d8\u91cftotal&#xff0c;\u518d\u5c06\u6b64\u6570\u503c\u663e\u793a\u5728\u7f16\u8f91\u6846editTotal\u4e2d\u3002\u7531\u4e8e\u8ba1\u7b97\u7ed3\u679c\u662f\u6d6e\u70b9\u6570&#xff0c;\u5e0c\u671b\u663e\u793a\u4e24\u4f4d\u5c0f\u6570&#xff0c;\u4e0b\u97624\u884c\u8bed\u53e5\u90fd\u53ef\u4ee5\u5b9e\u73b0\u8fd9\u4e2a\u529f\u80fd\u3002<\/p>\n<p>str&#061;QString::number(total,&#039;f&#039;,2);<br \/>\nstr&#061;QString::asprintf(&#034;%.2f&#034;,total);<br \/>\nstr&#061;str.setNum(total,&#039;f&#039;,2);<br \/>\nstr&#061;str.sprintf(&#034;%.2f&#034;,total);<\/p>\n<p>\u53ef\u4ee5\u4f7f\u7528QString\u7684\u9759\u6001\u51fd\u6570number()\u548casprintf()&#xff0c;\u4e5f\u53ef\u4ee5\u4f7f\u7528\u5176\u516c\u5171\u51fd\u6570setNum()\u548csprintf()\u3002QString\u7684sprintf()\u51fd\u6570\u4e0eC\u8bed\u8a00\u91cc\u7684sprintf()\u51fd\u6570\u7684\u683c\u5f0f\u662f\u4e00\u6837\u7684&#xff0c;\u800csetNum()\u548cnumber()\u51fd\u6570\u4f7f\u7528\u53e6\u5916\u4e00\u79cd\u683c\u5f0f\u5b9a\u4e49&#xff0c;\u800c\u4e14setNum\u548cnumber\u6709\u591a\u4e2a\u91cd\u8f7d\u51fd\u6570\u5b9a\u4e49&#xff0c;\u53ef\u4ee5\u5904\u7406\u5404\u79cd\u7c7b\u578b\u7684\u6574\u6570\u548c\u6d6e\u70b9\u6570&#xff0c;\u5728\u5904\u7406\u6574\u6570\u65f6\u8fd8\u53ef\u4ee5\u6307\u5b9a\u8fdb\u5236&#xff0c;\u4f8b\u5982\u5c06\u4e00\u4e2a\u6574\u6570\u76f4\u63a5\u8f6c\u6362\u4e3a\u5341\u516d\u8fdb\u5236\u6216\u4e8c\u8fdb\u5236\u5b57\u7b26\u4e32\u3002<\/p>\n<h5>2&#xff0e;\u8fdb\u5236\u8f6c\u6362<\/h5>\n<p>\u4ee5\u4e0b\u662f\u8bfb\u53d6\u5341\u8fdb\u5236\u6570\u8f6c\u6362\u4e3a\u4e8c\u8fdb\u5236\u548c\u5341\u516d\u8fdb\u5236\u5b57\u7b26\u4e32\u7684\u6309\u94ae\u7684\u69fd\u51fd\u6570\u4ee3\u7801&#xff1a;<\/p>\n<p>void Widget::on_btnDec_clicked()<br \/>\n{ \/\/\u8bfb\u53d6\u5341\u8fdb\u5236\u6570&#xff0c;\u8f6c\u6362\u4e3a\u5176\u4ed6\u8fdb\u5236<br \/>\n   QString  str&#061;ui-&gt;editDec-&gt;text();<br \/>\n   int  val&#061;str.toInt();\/\/\u7f3a\u7701\u4e3a\u5341\u8fdb\u5236<br \/>\n\/\/   str&#061;QString::number(val,16);\/\/ \u8f6c\u6362\u4e3a\u5341\u516d\u8fdb\u5236\u7684\u5b57\u7b26\u4e32<br \/>\n   str&#061;str.setNum(val,16);\/\/\u5341\u516d\u8fdb\u5236<br \/>\n   str&#061;str.toUpper();<br \/>\n   ui-&gt;editHex-&gt;setText(str);<\/p>\n<p>   str&#061;str.setNum(val,2);  \/\/\u4e8c\u8fdb\u5236<br \/>\n\/\/   str&#061;QString::number(val,2);<br \/>\n   ui-&gt;editBin-&gt;setText(str);<br \/>\n}<\/p>\n<p>\u5c06\u4e00\u4e2a\u6574\u6570\u8f6c\u6362\u4e3a\u4e0d\u540c\u8fdb\u5236\u7684\u5b57\u7b26\u4e32&#xff0c;\u53ef\u4ee5\u4f7f\u7528QString\u7684\u51fd\u6570setNum()\u6216\u9759\u6001\u51fd\u6570number()&#xff0c;\u5b83\u4eec\u7684\u51fd\u6570\u539f\u578b\u662f&#xff1a;<\/p>\n<p>Qstring &amp;setNum (int n, int base &#061; 10)<br \/>\nQString number (int n, int base &#061; 10)<\/p>\n<p>\u5176\u4e2dn\u662f\u5f85\u8f6c\u6362\u7684\u6574\u6570&#xff0c;base\u662f\u4f7f\u7528\u7684\u8fdb\u5236&#xff0c;\u7f3a\u7701\u4e3a\u5341\u8fdb\u5236&#xff0c;\u4e5f\u53ef\u4ee5\u6307\u5b9a\u4e3a\u5341\u516d\u8fdb\u5236\u548c\u4e8c\u8fdb\u5236\u3002<\/p>\n<p>\u4e0b\u9762\u662f\u8bfb\u53d6\u4e8c\u8fdb\u5236\u5b57\u7b26\u4e32&#xff0c;\u7136\u540e\u8f6c\u6362\u4e3a\u5341\u8fdb\u5236\u548c\u5341\u516d\u8fdb\u5236\u663e\u793a\u7684\u6309\u94ae\u7684\u69fd\u51fd\u6570\u4ee3\u7801\u3002<\/p>\n<p>void Widget::on_btnBin_clicked()<br \/>\n{ \/\/\u8bfb\u53d6\u4e8c\u8fdb\u5236\u6570&#xff0c;\u8f6c\u6362\u4e3a\u5176\u4ed6\u8fdb\u5236\u7684\u6570<br \/>\n   QString  str&#061;ui-&gt;editBin-&gt;text(); \/\/\u8bfb\u53d6\u4e8c\u8fdb\u5236\u5b57\u7b26\u4e32<br \/>\n   bool ok;<br \/>\n   int val&#061;str.toInt(&amp;ok,2);\/\/\u4ee5\u4e8c\u8fdb\u5236\u6570\u8bfb\u5165<br \/>\n   str&#061;QString::number(val,10);\/\/\u6570\u5b57\u663e\u793a\u4e3a\u5341\u8fdb\u5236\u5b57\u7b26\u4e32<br \/>\n   ui-&gt;editDec-&gt;setText(str);<\/p>\n<p>   str&#061;str.setNum(val,16);\/\/\u663e\u793a\u4e3a\u5341\u516d\u8fdb\u5236<br \/>\n   str&#061;str.toUpper();<br \/>\n   ui-&gt;editHex-&gt;setText(str);<br \/>\n}<\/p>\n<h4>4.1.2\u3000QString\u7684\u5e38\u7528\u529f\u80fd<\/h4>\n<p>QString\u662fQt\u7f16\u7a0b\u4e2d\u5e38\u7528\u7684\u7c7b&#xff0c;\u9664\u4e86\u7528\u4f5c\u6570\u5b57\u91cf\u7684\u8f93\u5165\u8f93\u51fa\u4e4b\u5916&#xff0c;QString\u8fd8\u6709\u5f88\u591a\u5176\u4ed6\u529f\u80fd&#xff0c;\u719f\u6089\u8fd9\u4e9b\u5e38\u89c1\u7684\u529f\u80fd&#xff0c;\u6709\u52a9\u4e8e\u7075\u6d3b\u5730\u5b9e\u73b0\u5b57\u7b26\u4e32\u5904\u7406\u529f\u80fd\u3002<\/p>\n<p>QString\u5b58\u50a8\u5b57\u7b26\u4e32\u91c7\u7528\u7684\u662fUnicode\u7801&#xff0c;\u6bcf\u4e00\u4e2a\u5b57\u7b26\u662f\u4e00\u4e2a16\u4f4d\u7684QChar&#xff0c;\u800c\u4e0d\u662f8\u4f4d\u7684char&#xff0c;\u6240\u4ee5QString\u5904\u7406\u4e2d\u6587\u5b57\u7b26\u6ca1\u6709\u95ee\u9898&#xff0c;\u800c\u4e14\u4e00\u4e2a\u6c49\u5b57\u7b97\u4f5c\u662f\u4e00\u4e2a\u5b57\u7b26\u3002<\/p>\n<p>\u539f\u4e66\u7684\u56fe4-2\u662f\u5bf9QString\u5e38\u7528\u51fd\u6570\u7684\u6d4b\u8bd5\u5b9e\u4f8bsamp4_2\u7684\u8fd0\u884c\u754c\u9762\u3002\u4e0b\u9762\u5728\u8bf4\u660e\u51fd\u6570\u529f\u80fd\u65f6&#xff0c;\u5bf9\u4e8e\u540c\u540d\u4e0d\u540c\u53c2\u6570\u7684\u51fd\u6570&#xff0c;\u53ea\u8bf4\u660e\u67d0\u79cd\u53c2\u6570\u4e0b\u7684\u4f7f\u7528\u5b9e\u4f8b\u3002QString\u8fd8\u6709\u5f88\u591a\u529f\u80fd\u51fd\u6570\u6ca1\u6709\u5728\u6b64\u4ecb\u7ecd&#xff0c;\u5728\u4f7f\u7528\u4e2d\u5982\u679c\u9047\u5230&#xff0c;\u53ef\u67e5\u8be2Qt\u7684\u5e2e\u52a9\u6587\u4ef6\u3002<\/p>\n<ul>\n<li>append()\u548cprepend()<\/li>\n<\/ul>\n<p>append()\u5728\u5b57\u7b26\u4e32\u7684\u540e\u9762\u6dfb\u52a0\u5b57\u7b26\u4e32&#xff0c;prepend()\u5728\u5b57\u7b26\u4e32\u7684\u524d\u9762\u6dfb\u52a0\u5b57\u7b26\u4e32&#xff0c;\u5982&#xff1a;<\/p>\n<p>QString str1&#061;&#034;\u5356&#034;, str2&#061;&#034;\u62d0&#034;;<br \/>\nQString str3&#061;str1;<br \/>\nstr1.append(str2);    \/\/str1&#061;&#034;\u5356\u62d0&#034;<br \/>\nstr3.prepend(str2);   \/\/str3&#061;&#034;\u62d0\u5356&#034;<\/p>\n<ul>\n<li>toUpper()\u548ctoLower()<\/li>\n<\/ul>\n<p>toUpper()\u5c06\u5b57\u7b26\u4e32\u5185\u7684\u5b57\u6bcd\u5168\u90e8\u8f6c\u6362\u4e3a\u5927\u5199\u5f62\u5f0f&#xff0c;toLower()\u5c06\u5b57\u6bcd\u5168\u90e8\u8f6c\u6362\u4e3a\u5c0f\u5199\u5f62\u5f0f&#xff0c;\u5982&#xff1a;<\/p>\n<p>QString str1&#061;&#034;Hello, World&#034;, str2;<br \/>\nstr2&#061;str1.toUpper();   \/\/str2&#061;&#034;HELLO,WORLD&#034;<br \/>\nstr2&#061;str1.toLower();   \/\/str2&#061;&#034;hello, world&#034;<\/p>\n<ul>\n<li>count()\u3001size()\u548clength()<\/li>\n<\/ul>\n<p>count()\u3001size()\u548clength()\u90fd\u8fd4\u56de\u5b57\u7b26\u4e32\u7684\u5b57\u7b26\u4e2a\u6570&#xff0c;\u8fd93\u4e2a\u51fd\u6570\u662f\u76f8\u540c\u7684&#xff0c;\u4f46\u662f\u8981\u6ce8\u610f&#xff0c;\u5b57\u7b26\u4e32\u4e2d\u5982\u679c\u6709\u6c49\u5b57&#xff0c;\u4e00\u4e2a\u6c49\u5b57\u7b97\u4e00\u4e2a\u5b57\u7b26\u3002<\/p>\n<p>QString str1&#061;&#034;NI\u597d&#034;<br \/>\nN&#061;str1.count()       \/\/N&#061;3<br \/>\nN&#061;str1.size()        \/\/N&#061;3<br \/>\nN&#061;str1.length()      \/\/N&#061;3<\/p>\n<ul>\n<li>trimmed()\u548csimplified()<\/li>\n<\/ul>\n<p>trimmed()\u53bb\u6389\u5b57\u7b26\u4e32\u9996\u5c3e\u7684\u7a7a\u683c&#xff0c;simplified()\u4e0d\u4ec5\u53bb\u6389\u9996\u5c3e\u7684\u7a7a\u683c&#xff0c;\u4e2d\u95f4\u8fde\u7eed\u7684\u7a7a\u683c\u4e5f\u7528\u4e00\u4e2a\u7a7a\u683c\u66ff\u6362\u3002<\/p>\n<p>QString    str1&#061;&#034;   Are    you   OK?   &#034;, str2;<br \/>\nstr2&#061;str1.trimmed();       \/\/str1&#061;&#034;Are    you   OK? &#034;<br \/>\nstr2&#061;str1.simplified();    \/\/str1&#061;&#034;Are you OK? &#034;<\/p>\n<ul>\n<li>indexOf ()\u548clastIndexOf ()<\/li>\n<\/ul>\n<p>indexOf()\u51fd\u6570\u7684\u539f\u578b\u4e3a&#xff1a;<\/p>\n<p>int indexOf (const QString &amp;str, int from &#061; 0, Qt::CaseSensitivity cs &#061; Qt::CaseSensitive) const<\/p>\n<p>\u5176\u529f\u80fd\u662f\u5728\u81ea\u8eab\u5b57\u7b26\u4e32\u5185\u67e5\u627e\u53c2\u6570\u5b57\u7b26\u4e32str\u51fa\u73b0\u7684\u4f4d\u7f6e&#xff0c;\u53c2\u6570from\u662f\u5f00\u59cb\u67e5\u627e\u7684\u4f4d\u7f6e&#xff0c;Qt::CaseSensitivity cs\u53c2\u6570\u6307\u5b9a\u662f\u5426\u533a\u5206\u5927\u5c0f\u5199\u3002<\/p>\n<p>lastIndexOf()\u51fd\u6570\u5219\u662f\u67e5\u627e\u67d0\u4e2a\u5b57\u7b26\u4e32\u6700\u540e\u51fa\u73b0\u7684\u4f4d\u7f6e\u3002<\/p>\n<p>QString str1&#061;&#034;G:\\\\Qt5Book\\\\QT5.9Study\\\\qw.cpp&#034;;<br \/>\nN&#061;str1.indexOf(&#034;5.9&#034;);          \/\/ N&#061;13<br \/>\nN&#061;str1.lastIndexOf(&#034;\\\\\\\\&#034;);       \/\/N&#061;21<\/p>\n<p>\u201c\\\\\u201d\u662f\u8f6c\u4e49\u5b57\u7b26&#xff0c;\u5982\u679c\u8981\u67e5\u627e\u201c\\\\\u201d&#xff0c;\u9700\u8981\u8f93\u5165\u201c\\\\\u201d\u3002<\/p>\n<ul>\n<li>isNull()\u548cisEmpty()<\/li>\n<\/ul>\n<p>\u4e24\u4e2a\u51fd\u6570\u90fd\u5224\u8bfb\u5b57\u7b26\u4e32\u662f\u5426\u4e3a\u7a7a&#xff0c;\u4f46\u662f\u7a0d\u6709\u5dee\u522b\u3002\u5982\u679c\u4e00\u4e2a\u7a7a\u5b57\u7b26\u4e32&#xff0c;\u53ea\u6709\u201c\\\\0\u201d&#xff0c;isNull()\u8fd4\u56defalse&#xff0c;\u800cisEmpty()\u8fd4\u56detrue&#xff1b;\u53ea\u6709\u672a\u8d4b\u503c\u7684\u5b57\u7b26\u4e32&#xff0c;isNull()\u624d\u8fd4\u56detrue\u3002<\/p>\n<p>QString str1, str2&#061;&#034;&#034;;<br \/>\nN&#061;str1.isNull();   \/\/ N&#061;true    \u672a\u8d4b\u503c\u5b57\u7b26\u4e32\u53d8\u91cf<br \/>\nN&#061;str2.isNull();   \/\/ N&#061;false   \u53ea\u6709&#034;\\\\0&#034;\u7684\u5b57\u7b26\u4e32&#xff0c;\u4e5f\u4e0d\u662fNull<br \/>\nN&#061;str1.isEmpty();  \/\/ N&#061;true<br \/>\nN&#061;str2.isEmpty();  \/\/ N&#061;true<\/p>\n<p>QString\u53ea\u8981\u8d4b\u503c&#xff0c;\u5c31\u5728\u5b57\u7b26\u4e32\u7684\u672b\u5c3e\u81ea\u52a8\u52a0\u4e0a\u201c\\\\0\u201d&#xff0c;\u6240\u4ee5&#xff0c;\u5982\u679c\u53ea\u662f\u8981\u5224\u65ad\u5b57\u7b26\u4e32\u5185\u5bb9\u662f\u5426\u4e3a\u7a7a&#xff0c;\u5e38\u7528isEmpty()\u3002<\/p>\n<ul>\n<li>contains()<\/li>\n<\/ul>\n<p>\u5224\u65ad\u5b57\u7b26\u4e32\u5185\u662f\u5426\u5305\u542b\u67d0\u4e2a\u5b57\u7b26\u4e32&#xff0c;\u53ef\u6307\u5b9a\u662f\u5426\u533a\u5206\u5927\u5c0f\u5199\u3002<\/p>\n<p>QString str1&#061;&#034;G:\\\\Qt5Book\\\\QT5.9Study\\\\qw.cpp&#034;;<br \/>\nN&#061;str1.contains(&#034;.cpp&#034;, Qt::CaseInsensitive);    \/\/ N&#061;true&#xff0c;\u4e0d\u533a\u5206\u5927\u5c0f\u5199<br \/>\nN&#061;str1.contains(&#034;.CPP&#034;, Qt::CaseSensitive);      \/\/ N&#061;false&#xff0c;\u533a\u5206\u5927\u5c0f\u5199<\/p>\n<ul>\n<li>endsWith()\u548cstartsWith()<\/li>\n<\/ul>\n<p>startsWith ()\u5224\u65ad\u662f\u5426\u4ee5\u67d0\u4e2a\u5b57\u7b26\u4e32\u5f00\u5934&#xff0c;endsWith()\u5224\u65ad\u662f\u5426\u4ee5\u67d0\u4e2a\u5b57\u7b26\u4e32\u7ed3\u675f\u3002<\/p>\n<p>QString str1&#061;&#034;G:\\\\Qt5Book\\\\QT5.9Study\\\\qw.cpp&#034;;<br \/>\nN&#061;str1.endsWith(&#034;.cpp&#034;, Qt::CaseInsensitive);     \/\/ N&#061;true&#xff0c;\u4e0d\u533a\u5206\u5927\u5c0f\u5199<br \/>\nN&#061;str1.endsWith(&#034;.CPP&#034;, Qt::CaseSensitive);       \/\/ N&#061;false&#xff0c;\u533a\u5206\u5927\u5c0f\u5199<br \/>\nN&#061;str1.startsWith(&#034;g: &#034;);                         \/\/ N&#061;true&#xff0c;\u7f3a\u7701\u4e3a\u4e0d\u533a\u5206\u5927\u5c0f\u5199<\/p>\n<ul>\n<li>left()\u548cright()<\/li>\n<\/ul>\n<p>left\u8868\u793a\u4ece\u5b57\u7b26\u4e32\u4e2d\u53d6\u5de6\u8fb9\u591a\u5c11\u4e2a\u5b57\u7b26&#xff0c;right\u8868\u793a\u4ece\u5b57\u7b26\u4e32\u4e2d\u53d6\u53f3\u8fb9\u591a\u5c11\u4e2a\u5b57\u7b26\u3002\u6ce8\u610f&#xff0c;\u4e00\u4e2a\u6c49\u5b57\u88ab\u5f53\u4f5c\u4e00\u4e2a\u5b57\u7b26\u3002<\/p>\n<p>QString str2, str1&#061;&#034;\u5b66\u751f\u59d3\u540d&#xff0c;\u7537&#xff0c;1984-3-4&#xff0c;\u6c49\u65cf&#xff0c;\u5c71\u4e1c&#034;;<br \/>\nN&#061;str1.indexOf (&#034;&#xff0c;&#034;);                             \/\/ N&#061;4&#xff0c;\u7b2c\u4e00\u4e2a&#034;&#xff0c;&#034;\u51fa\u73b0\u7684\u4f4d\u7f6e<br \/>\nstr2&#061;str1.left(N);                                 \/\/str2&#061;&#034;\u5b66\u751f\u59d3\u540d&#034;<br \/>\nN&#061;str1.lastIndexOf (&#034;&#xff0c;&#034;);                         \/\/ N&#061;18&#xff0c;\u6700\u540e\u4e00\u4e2a\u9017\u53f7\u7684\u4f4d\u7f6e<br \/>\nstr2&#061;str1.right(str1.size()-N-1); \/\/str2&#061;&#034;\u5c71\u4e1c&#034;&#xff0c;\u63d0\u53d6\u6700\u540e\u4e00\u4e2a\u9017\u53f7\u4e4b\u540e\u7684\u5b57\u7b26\u4e32<\/p>\n<ul>\n<li>section()<\/li>\n<\/ul>\n<p>section()\u51fd\u6570\u7684\u539f\u578b\u4e3a&#xff1a;<\/p>\n<p>QString section (const QString &amp;sep, int start, int end &#061; -1, SectionFlags flags &#061; SectionDefault) const<\/p>\n<p>\u5176\u529f\u80fd\u662f\u4ece\u5b57\u7b26\u4e32\u4e2d\u63d0\u53d6\u4ee5sep\u4f5c\u4e3a\u5206\u9694\u7b26&#xff0c;\u4ecestart\u7aef\u5230end\u7aef\u7684\u5b57\u7b26\u4e32\u3002<\/p>\n<p>QString str2, str1&#061;&#034;\u5b66\u751f\u59d3\u540d&#xff0c;\u7537&#xff0c;1984-3-4&#xff0c;\u6c49\u65cf&#xff0c;\u5c71\u4e1c&#034;;<br \/>\nstr2&#061;str1.section (&#034;&#xff0c;&#034;,0,0);                    \/\/ str2&#061;&#034;\u5b66\u751f\u59d3\u540d&#034;&#xff0c;   \u7b2c1\u6bb5\u7684\u7f16\u53f7\u4e3a0<br \/>\nstr2&#061;str1.section (&#034;&#xff0c;&#034;,1,1);                    \/\/ str2&#061;&#034;\u7537&#034;<br \/>\nstr2&#061;str1.section (&#034;&#xff0c;&#034;,0,1);                    \/\/ str2&#061;&#034;\u5b66\u751f\u59d3\u540d&#xff0c;\u7537&#034;<br \/>\nstr2&#061;str1.section (&#034;&#xff0c;&#034;,4,4);                    \/\/ str2&#061;&#034;\u5c71\u4e1c&#034;<\/p>\n<h3>4.2\u3000SpinBox\u7684\u4f7f\u7528<\/h3>\n<p>QSpinBox\u7528\u4e8e\u6574\u6570\u7684\u663e\u793a\u548c\u8f93\u5165&#xff0c;\u4e00\u822c\u663e\u793a\u5341\u8fdb\u5236\u6570&#xff0c;\u4e5f\u53ef\u4ee5\u663e\u793a\u4e8c\u8fdb\u5236\u3001\u5341\u516d\u8fdb\u5236\u7684\u6570&#xff0c;\u800c\u4e14\u53ef\u4ee5\u5728\u663e\u793a\u6846\u4e2d\u589e\u52a0\u524d\u7f00\u6216\u540e\u7f00\u3002<\/p>\n<p>QDoubleSpinBox\u7528\u4e8e\u6d6e\u70b9\u6570\u7684\u663e\u793a\u548c\u8f93\u5165&#xff0c;\u53ef\u4ee5\u8bbe\u7f6e\u663e\u793a\u5c0f\u6570\u4f4d\u6570&#xff0c;\u4e5f\u53ef\u4ee5\u8bbe\u7f6e\u663e\u793a\u7684\u524d\u7f00\u548c\u540e\u7f00\u3002<\/p>\n<p>\u5b9e\u4f8bsamp4_3\u6f14\u793aQSpinBox\u548cQDoubleSpinBox\u8fd9\u4e24\u4e2a\u7ec4\u4ef6\u7684\u4f7f\u7528&#xff0c;\u539f\u4e66\u7684\u56fe4-3\u662f\u7a0b\u5e8f\u8fd0\u884c\u754c\u9762\u3002\u7a0b\u5e8f\u529f\u80fd\u4e0e\u5b9e\u4f8bsamp4_1\u7c7b\u4f3c&#xff0c;\u4f46\u662f\u4f7f\u7528QSpinBox\u548cQDoubleSpinBox\u4f5c\u4e3a\u6570\u5b57\u8f93\u5165\u8f93\u51fa\u7ec4\u4ef6\u3002<\/p>\n<p>QSpinBox\u548cQDoubleSpinBox\u90fd\u662fQAbstractSpinBox\u7684\u5b50\u7c7b&#xff0c;\u5177\u6709\u5927\u591a\u6570\u76f8\u540c\u7684\u5c5e\u6027&#xff0c;\u53ea\u662f\u53c2\u6570\u7c7b\u578b\u4e0d\u540c\u3002\u5728UI\u8bbe\u8ba1\u5668\u91cc\u8fdb\u884c\u754c\u9762\u8bbe\u8ba1\u65f6&#xff0c;\u5c31\u53ef\u4ee5\u8bbe\u7f6e\u8fd9\u4e9b\u5c5e\u6027\u3002QSpinBox\u548cQDoubleSpinBox\u7684\u4e3b\u8981\u5c5e\u6027\u89c1\u88684-1\u3002<\/p>\n<p>\u88684-1\u3000QSpinBox\u548cQDoubleSpinBox\u7684\u4e3b\u8981\u5c5e\u6027<\/p>\n<table>\n<tr>\u5c5e\u6027\u540d\u79f0\u63cf\u8ff0<\/tr>\n<tbody>\n<tr>\n<td>prefix<\/td>\n<td>\u6570\u5b57\u663e\u793a\u7684\u524d\u7f00&#xff0c;\u4f8b\u5982\u201c$\u201d<\/td>\n<\/tr>\n<tr>\n<td>suffix<\/td>\n<td>\u6570\u5b57\u663e\u793a\u7684\u540e\u7f00&#xff0c;\u4f8b\u5982\u201ckg\u201d<\/td>\n<\/tr>\n<tr>\n<td>minimum<\/td>\n<td>\u6570\u503c\u8303\u56f4\u7684\u6700\u5c0f\u503c&#xff0c;\u59820<\/td>\n<\/tr>\n<tr>\n<td>maximum<\/td>\n<td>\u6570\u503c\u8303\u56f4\u7684\u6700\u5927\u503c&#xff0c;\u5982255<\/td>\n<\/tr>\n<tr>\n<td>singlestep<\/td>\n<td>\u5355\u51fb\u53f3\u4fa7\u4e0a\u4e0b\u8c03\u6574\u6309\u94ae\u65f6\u7684\u5355\u6b65\u6539\u53d8\u503c&#xff0c;\u5982\u8bbe\u7f6e\u4e3a1&#xff0c;\u62160.1<\/td>\n<\/tr>\n<tr>\n<td>value<\/td>\n<td>\u5f53\u524d\u663e\u793a\u7684\u503c<\/td>\n<\/tr>\n<tr>\n<td>displayIntegerBase<\/td>\n<td>QSpinBox\u7279\u6709\u5c5e\u6027&#xff0c;\u663e\u793a\u6574\u6570\u4f7f\u7528\u7684\u8fdb\u5236&#xff0c;\u4f8b\u59822\u5c31\u8868\u793a\u4e8c\u8fdb\u5236<\/td>\n<\/tr>\n<tr>\n<td>decimals<\/td>\n<td>QDoubleSpinBox\u7279\u6709\u5c5e\u6027&#xff0c;\u663e\u793a\u6570\u503c\u7684\u5c0f\u6570\u4f4d\u6570&#xff0c;\u4f8b\u59822\u5c31\u663e\u793a\u4e24\u4f4d\u5c0f\u6570<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u63d0\u793a&#xff1a;\u4e00\u4e2a\u5c5e\u6027\u5728\u7c7b\u7684\u63a5\u53e3\u4e2d\u4e00\u822c\u6709\u4e00\u4e2a\u8bfb\u53d6\u51fd\u6570\u548c\u4e00\u4e2a\u8bbe\u7f6e\u51fd\u6570&#xff0c;\u5982QDoubleSpinBox\u7684decimals\u5c5e\u6027&#xff0c;\u8bfb\u53d6\u5c5e\u6027\u503c\u7684\u51fd\u6570\u4e3aint decimals()&#xff0c;\u8bbe\u7f6e\u5c5e\u6027\u503c\u7684\u51fd\u6570\u4e3avoid setDecimals(int prec)\u3002<\/p>\n<p>\u539f\u4e66\u7684\u56fe4-3\u4e2d\u5404\u4e2aSpinBox\u7684\u7c7b\u578b\u53ca\u5c5e\u6027\u8bbe\u7f6e\u4e00\u76ee\u4e86\u7136&#xff0c;\u4e0d\u518d\u8d58\u8ff0\u3002\u4f7f\u7528QSpinBox\u548cQdouble SpinBox\u8fdb\u884c\u6570\u503c\u91cf\u7684\u8f93\u5165\u8f93\u51fa\u5f88\u65b9\u4fbf&#xff0c;\u4e0b\u9762\u662f\u56fe4-3\u4e2d\u201c\u8ba1\u7b97\u201d\u6309\u94ae\u548c\u201c\u5341\u8fdb\u5236\u201d\u540e\u9762\u7684\u6309\u94ae\u7684\u69fd\u51fd\u6570\u4ee3\u7801\u3002<\/p>\n<p>void Widget::on_btnCal_clicked()<br \/>\n{ \/\/\u8ba1\u7b97<br \/>\n   int num&#061;ui-&gt;spinNum-&gt;value();<br \/>\n   float price&#061;ui-&gt;spinPrice-&gt;value();<br \/>\n   float total&#061;num*price;<br \/>\n   ui-&gt;spinTotal-&gt;setValue(total);<br \/>\n}<br \/>\nvoid Widget::on_btnBin_clicked()<br \/>\n{ \/\/\u8bfb\u53d6\u4e8c\u8fdb\u5236\u6570&#xff0c;\u4ee5\u5176\u4ed6\u8fdb\u5236\u663e\u793a<br \/>\n   int val&#061;ui-&gt;spinBin-&gt;value();<br \/>\n   ui-&gt;spinDec-&gt;setValue(val);<br \/>\n   ui-&gt;spinHex-&gt;setValue(val);<br \/>\n}<\/p>\n<p>\u5728\u4f7f\u7528QSpinBox\u548cQDoubleSpinBox\u8bfb\u53d6\u548c\u8bbe\u7f6e\u6570\u503c\u65f6&#xff0c;\u65e0\u9700\u505a\u5b57\u7b26\u4e32\u4e0e\u6570\u503c\u4e4b\u95f4\u7684\u8f6c\u6362&#xff0c;\u4e5f\u65e0\u9700\u505a\u8fdb\u5236\u7684\u8f6c\u6362&#xff0c;\u5176\u663e\u793a\u6548\u679c&#xff08;\u524d\u7f00\u3001\u540e\u7f00\u3001\u8fdb\u5236\u548c\u5c0f\u6570\u4f4d\u6570&#xff09;\u5728\u8bbe\u7f6e\u597d\u4e4b\u540e\u5c31\u81ea\u52a8\u6309\u7167\u6548\u679c\u8fdb\u884c\u663e\u793a&#xff0c;\u8fd9\u5bf9\u4e8e\u6570\u503c\u7684\u8f93\u5165\u8f93\u51fa\u662f\u975e\u5e38\u65b9\u4fbf\u7684\u3002<\/p>\n<h3>4.3\u3000\u5176\u4ed6\u6570\u503c\u8f93\u5165\u548c\u663e\u793a\u7ec4\u4ef6<\/h3>\n<h4>4.3.1\u3000\u5b9e\u4f8b\u529f\u80fd<\/h4>\n<p>\u9664\u4e86LineEdit\u548cSpinBox\u4e4b\u5916&#xff0c;\u8fd8\u6709\u5176\u4ed6\u4e00\u4e9b\u7528\u4e8e\u6570\u503c\u8f93\u5165\u548c\u663e\u793a\u7684\u7ec4\u4ef6\u3002\u5b9e\u4f8bsamp4_4\u6f14\u793a\u5982\u4f55\u4f7f\u7528\u8fd9\u4e9b\u7ec4\u4ef6&#xff0c;\u539f\u4e66\u7684\u56fe4-4\u662f\u5b9e\u4f8bsamp4_4\u7684\u8bbe\u8ba1\u754c\u9762\u3002<\/p>\n<p>\u5728\u8fd9\u4e2a\u5b9e\u4f8b\u4e2d&#xff0c;\u7528\u5230\u5982\u4e0b\u4e00\u4e9b\u7ec4\u4ef6\u3002<\/p>\n<ul>\n<li>\n<p>QSlider&#xff1a;\u6ed1\u52a8\u6761&#xff0c;\u901a\u8fc7\u6ed1\u52a8\u6765\u8bbe\u7f6e\u6570\u503c&#xff0c;\u53ef\u7528\u4e8e\u6570\u503c\u8f93\u5165\u3002\u5b9e\u4f8b\u4e2d\u4f7f\u75284\u4e2a\u6ed1\u52a8\u6761\u8f93\u5165\u7ea2\u3001\u7eff\u3001\u84dd\u4e09\u8272\u548cAlpha\u503c&#xff0c;\u7136\u540e\u5408\u6210\u989c\u8272&#xff0c;\u4f5c\u4e3a\u4e00\u4e2aQTextEdit\u7ec4\u4ef6\u7684\u5e95\u8272\u3002<\/p>\n<\/li>\n<li>\n<p>QScrollBar&#xff1a;\u5377\u6eda\u6761&#xff0c;\u4e0eQSlider\u529f\u80fd\u7c7b\u4f3c&#xff0c;\u8fd8\u53ef\u4ee5\u7528\u4e8e\u5377\u6eda\u533a\u57df\u3002<\/p>\n<\/li>\n<li>\n<p>QProgressBar&#xff1a;\u8fdb\u5ea6\u6761&#xff0c;\u4e00\u822c\u7528\u4e8e\u663e\u793a\u4efb\u52a1\u8fdb\u5ea6&#xff0c;\u53ef\u7528\u4e8e\u6570\u503c\u7684\u767e\u5206\u6bd4\u663e\u793a\u3002\u5b9e\u4f8b\u7a0b\u5e8f\u4e2d\u6ed1\u52a8\u4e00\u4e2aSlider&#xff0c;\u83b7\u53d6\u5176\u503c\u5e76\u66f4\u65b0ScrollBar\u548cProgressBar\u3002<\/p>\n<\/li>\n<li>\n<p>QDial&#xff1a;\u8868\u76d8\u5f0f\u6570\u503c\u8f93\u5165\u7ec4\u4ef6&#xff0c;\u901a\u8fc7\u8f6c\u52a8\u8868\u9488\u83b7\u5f97\u8f93\u5165\u503c\u3002<\/p>\n<\/li>\n<li>\n<p>QLCDNumber&#xff1a;\u6a21\u4effLCD\u6570\u5b57\u7684\u663e\u793a\u7ec4\u4ef6&#xff0c;\u53ef\u4ee5\u663e\u793a\u6574\u6570\u6216\u6d6e\u70b9\u6570&#xff0c;\u663e\u793a\u6574\u6570\u65f6\u53ef\u4ee5\u4e0d\u540c\u8fdb\u5236\u663e\u793a\u3002\u5b9e\u4f8b\u7a0b\u5e8f\u4e2d\u8f6c\u52a8\u8868\u76d8&#xff0c;\u83b7\u5f97\u7684\u503c\u663e\u793a\u5728LCD\u7ec4\u4ef6\u4e2d\u3002\u5355\u51fb\u201cLCD\u663e\u793a\u8fdb\u5236\u201d\u7684RadioButton\u65f6&#xff0c;\u8bbe\u7f6eLCD\u7684\u663e\u793a\u8fdb\u5236\u3002<\/p>\n<\/li>\n<\/ul>\n<h4>4.3.2\u3000\u5404\u7ec4\u4ef6\u7684\u4e3b\u8981\u529f\u80fd\u548c\u5c5e\u6027<\/h4>\n<h5>1&#xff0e;QSlider<\/h5>\n<p>QSlider\u3001QScrollBar\u548cQdial 3\u4e2a\u7ec4\u4ef6\u90fd\u4eceQAbstractSlider\u7ee7\u627f\u800c\u6765&#xff0c;\u6709\u4e00\u4e9b\u5171\u6709\u7684\u5c5e\u6027\u3002QSlider\u662f\u6ed1\u52a8\u7684\u6807\u5c3a\u578b\u7ec4\u4ef6&#xff0c;\u6ed1\u52a8\u6807\u5c3a\u4e0a\u7684\u4e00\u4e2a\u6ed1\u5757\u53ef\u4ee5\u6539\u53d8\u503c\u3002<\/p>\n<p>\u57fa\u7c7bQAbstractSlider\u7684\u4e3b\u8981\u5c5e\u6027\u5305\u62ec\u4ee5\u4e0b\u51e0\u79cd\u3002<\/p>\n<ul>\n<li>\n<p>minimum\u3001maximum&#xff1a;\u8bbe\u7f6e\u8f93\u5165\u8303\u56f4\u7684\u6700\u5c0f\u503c\u548c\u6700\u5927\u503c&#xff0c;\u4f8b\u5982&#xff0c;\u7528\u7ea2\u3001\u7eff\u3001\u84dd\u914d\u8272\u65f6&#xff0c;\u6bcf\u79cd\u57fa\u8272\u7684\u5927\u5c0f\u8303\u56f4\u662f0~255&#xff0c;\u6240\u4ee5\u8bbe\u7f6eminimum\u4e3a0&#xff0c;maximum\u4e3a255\u3002<\/p>\n<\/li>\n<li>\n<p>singleStep&#xff1a;\u5355\u6b65\u957f&#xff0c;\u62d6\u52a8\u6807\u5c3a\u4e0a\u7684\u6ed1\u5757&#xff0c;\u6216\u6309\u4e0b\u5de6\/\u53f3\u5149\u6807\u952e\u65f6\u7684\u6700\u5c0f\u53d8\u5316\u6570\u503c\u3002<\/p>\n<\/li>\n<li>\n<p>pageStep&#xff1a;\u5728Slider\u4e0a\u8f93\u5165\u7126\u70b9&#xff0c;\u6309PgUp\u6216PgDn\u952e\u65f6\u53d8\u5316\u7684\u6570\u503c\u3002<\/p>\n<\/li>\n<li>\n<p>value&#xff1a;\u7ec4\u4ef6\u7684\u5f53\u524d\u503c&#xff0c;\u62d6\u52a8\u6ed1\u5757\u65f6\u81ea\u52a8\u6539\u53d8\u6b64\u503c&#xff0c;\u5e76\u9650\u5b9a\u5728minimum\u548cmaximum\u5b9a\u4e49\u7684\u8303\u56f4\u4e4b\u5185\u3002<\/p>\n<\/li>\n<li>\n<p>sliderPosition&#xff1a;\u6ed1\u5757\u7684\u4f4d\u7f6e&#xff0c;\u82e5tracking\u5c5e\u6027\u8bbe\u7f6e\u4e3atrue&#xff0c;sliderPosition\u5c31\u7b49\u4e8evalue\u3002<\/p>\n<\/li>\n<li>\n<p>tracking&#xff1a;sliderPosition\u662f\u5426\u7b49\u540c\u4e8evalue&#xff0c;\u5982\u679ctracking&#061;true&#xff0c;\u6539\u53d8value\u65f6\u4e5f\u540c\u65f6\u6539\u53d8sliderPosition\u3002<\/p>\n<\/li>\n<li>\n<p>orientation&#xff1a;Slider\u7684\u65b9\u5411&#xff0c;\u53ef\u4ee5\u8bbe\u7f6e\u4e3a\u6c34\u5e73\u6216\u5782\u76f4\u3002\u65b9\u5411\u53c2\u6570\u662fQt\u7684\u679a\u4e3e\u7c7b\u578benum Qt::Orientation&#xff0c;\u53d6\u503c\u5305\u62ec\u4ee5\u4e0b\u4e24\u79cd\u3002<\/p>\n<ul>\n<li>\n<p>Qt::Horizontal \u6c34\u5e73\u65b9\u5411<\/p>\n<\/li>\n<li>\n<p>Qt::Vertical \u5782\u76f4\u65b9\u5411<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>invertedAppearance&#xff1a;\u663e\u793a\u65b9\u5f0f\u662f\u5426\u53cd\u5411&#xff0c;invertedAppearance&#061;false\u65f6&#xff0c;\u6c34\u5e73\u7684Slider\u7531\u5de6\u5411\u53f3\u6570\u503c\u589e\u5927&#xff0c;\u5426\u5219\u53cd\u8fc7\u6765\u3002<\/p>\n<\/li>\n<li>\n<p>invertedControls&#xff1a;\u53cd\u5411\u6309\u952e\u63a7\u5236&#xff0c;\u82e5invertedControls&#061;true&#xff0c;\u5219\u6309\u4e0bPgUp\u6216PgDn\u6309\u952e\u65f6\u8c03\u6574\u6570\u503c\u7684\u65b9\u5411\u76f8\u53cd\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u5c5e\u4e8eQSlider\u7684\u4e13\u6709\u5c5e\u6027\u6709\u4e24\u4e2a&#xff0c;\u5982\u4e0b\u3002<\/p>\n<ul>\n<li>\n<p>tickPosition&#xff1a;\u6807\u5c3a\u523b\u5ea6\u7684\u663e\u793a\u4f4d\u7f6e&#xff0c;\u4f7f\u7528\u679a\u4e3e\u7c7b\u578bQSlider::TickPosition&#xff0c;\u53d6\u503c\u5305\u62ec\u4ee5\u4e0b6\u79cd\u3002<\/p>\n<p>QSlider::NoTicks\u3000\u3000\u3000 \u4e0d\u663e\u793a\u523b\u5ea6<br \/>\nQSlider::TicksBothSides \u6807\u5c3a\u4e24\u4fa7\u90fd\u663e\u793a\u523b\u5ea6<br \/>\nQSlider::TicksAbove\u3000\u3000\u6807\u5c3a\u4e0a\u65b9\u663e\u793a\u523b\u5ea6<br \/>\nQSlider::TicksBelow \u6807\u5c3a\u4e0b\u65b9\u663e\u793a\u523b\u5ea6<br \/>\nQSlider::TicksLeft \u6807\u5c3a\u5de6\u4fa7\u663e\u793a\u523b\u5ea6<br \/>\nQSlider::TicksRight \u6807\u5c3a\u53f3\u4fa7\u663e\u793a\u523b\u5ea6<\/p>\n<\/li>\n<li>\n<p>QSlider::NoTicks\u3000\u3000\u3000 \u4e0d\u663e\u793a\u523b\u5ea6<\/p>\n<\/li>\n<li>\n<p>QSlider::TicksBothSides \u6807\u5c3a\u4e24\u4fa7\u90fd\u663e\u793a\u523b\u5ea6<\/p>\n<\/li>\n<li>\n<p>QSlider::TicksAbove\u3000\u3000\u6807\u5c3a\u4e0a\u65b9\u663e\u793a\u523b\u5ea6<\/p>\n<\/li>\n<li>\n<p>QSlider::TicksBelow \u6807\u5c3a\u4e0b\u65b9\u663e\u793a\u523b\u5ea6<\/p>\n<\/li>\n<li>\n<p>QSlider::TicksLeft \u6807\u5c3a\u5de6\u4fa7\u663e\u793a\u523b\u5ea6<\/p>\n<\/li>\n<li>\n<p>QSlider::TicksRight \u6807\u5c3a\u53f3\u4fa7\u663e\u793a\u523b\u5ea6<\/p>\n<\/li>\n<li>\n<p>tickInterval&#xff1a;\u6807\u5c3a\u523b\u5ea6\u7684\u95f4\u9694\u503c&#xff0c;\u82e5\u8bbe\u7f6e\u4e3a0&#xff0c;\u4f1a\u5728singleStep\u548cpageStep\u4e4b\u95f4\u81ea\u52a8\u9009\u62e9\u3002<\/p>\n<\/li>\n<\/ul>\n<h5>2&#xff0e;QScrollBar<\/h5>\n<p>QScrollBar\u4eceQAbstractSlider\u7ee7\u627f\u800c\u6765\u7684&#xff0c;\u5177\u6709QAbstractSlider\u7684\u57fa\u672c\u5c5e\u6027&#xff0c;\u6ca1\u6709\u4e13\u6709\u5c5e\u6027\u3002<\/p>\n<h5>3&#xff0e;QDial<\/h5>\n<p>QDial\u662f\u4eea\u8868\u76d8\u5f0f\u7684\u7ec4\u4ef6&#xff0c;\u901a\u8fc7\u65cb\u8f6c\u8868\u76d8\u83b7\u5f97\u8f93\u5165\u503c\u3002QDial\u7684\u7279\u6709\u7684\u5c5e\u6027\u5305\u62ec\u4ee5\u4e0b\u4e24\u79cd\u3002<\/p>\n<ul>\n<li>\n<p>notchesVisible&#xff1a;\u8868\u76d8\u7684\u5c0f\u523b\u5ea6\u662f\u5426\u53ef\u89c1\u3002<\/p>\n<\/li>\n<li>\n<p>notchTarget&#xff1a;\u8868\u76d8\u523b\u5ea6\u95f4\u7684\u95f4\u9694\u50cf\u7d20\u503c\u3002<\/p>\n<\/li>\n<\/ul>\n<h5>4&#xff0e;QProgressBar<\/h5>\n<p>QProgressBar\u7684\u7236\u7c7b\u662fQWidget&#xff0c;\u4e00\u822c\u7528\u4e8e\u8fdb\u5ea6\u663e\u793a&#xff0c;\u5e38\u7528\u5c5e\u6027\u5982\u4e0b\u3002<\/p>\n<ul>\n<li>\n<p>minimum\u3001maximum&#xff1a;\u6700\u5c0f\u503c\u548c\u6700\u5927\u503c\u3002<\/p>\n<\/li>\n<li>\n<p>value&#xff1a;\u5f53\u524d\u503c&#xff0c;\u53ef\u4ee5\u8bbe\u5b9a\u6216\u8bfb\u53d6\u5f53\u524d\u503c\u3002<\/p>\n<\/li>\n<li>\n<p>textVisible&#xff1a;\u662f\u5426\u663e\u793a\u6587\u5b57&#xff0c;\u6587\u5b57\u4e00\u822c\u662f\u767e\u5206\u6bd4\u8868\u793a\u7684\u8fdb\u5ea6\u3002<\/p>\n<\/li>\n<li>\n<p>orientation&#xff1a;\u53ef\u4ee5\u8bbe\u7f6e\u4e3a\u6c34\u5e73\u6216\u5782\u76f4\u65b9\u5411\u3002<\/p>\n<\/li>\n<li>\n<p>format&#xff1a;\u663e\u793a\u6587\u5b57\u7684\u683c\u5f0f&#xff0c;\u201c%p%\u201d\u663e\u793a\u767e\u5206\u6bd4&#xff0c;\u201c%v\u201d\u663e\u793a\u5f53\u524d\u503c&#xff0c;\u201c%m\u201d\u663e\u793a\u603b\u6b65\u6570\u3002\u7f3a\u7701\u4e3a\u201c%p%\u201d\u3002<\/p>\n<\/li>\n<\/ul>\n<h5>5&#xff0e;QLCDNumber<\/h5>\n<p>QLCDNumber\u662f\u6a21\u62dfLCD\u663e\u793a\u6570\u5b57\u7684\u7ec4\u4ef6&#xff0c;\u53ef\u4ee5\u663e\u793a\u6574\u6570\u6216\u5c0f\u6570&#xff0c;\u4f46\u5c31\u5982\u5b9e\u9645\u7684LCD\u4e00\u6837&#xff0c;\u8981\u8bbe\u5b9a\u663e\u793a\u6570\u5b57\u7684\u4e2a\u6570\u3002\u663e\u793a\u6574\u6570\u65f6&#xff0c;\u8fd8\u53ef\u4ee5\u9009\u62e9\u4ee5\u4e0d\u540c\u8fdb\u5236\u6765\u663e\u793a&#xff0c;\u5982\u5341\u8fdb\u5236\u3001\u4e8c\u8fdb\u5236\u3001\u5341\u516d\u8fdb\u5236\u3002\u5176\u4e3b\u8981\u5c5e\u6027\u5982\u4e0b\u3002<\/p>\n<ul>\n<li>\n<p>digitCount&#xff1a;\u663e\u793a\u7684\u6570\u7684\u4f4d\u6570&#xff0c;\u5982\u679c\u662f\u5c0f\u6570&#xff0c;\u5c0f\u6570\u70b9\u4e5f\u7b97\u4e00\u4e2a\u6570\u4f4d\u3002<\/p>\n<\/li>\n<li>\n<p>smallDecimalPoint&#xff1a;\u662f\u5426\u6709\u5c0f\u6570\u70b9&#xff0c;\u5982\u679c\u6709\u5c0f\u6570\u70b9&#xff0c;\u5c31\u53ef\u4ee5\u663e\u793a\u5c0f\u6570\u3002<\/p>\n<\/li>\n<li>\n<p>mode&#xff1a;\u6570\u7684\u663e\u793a\u8fdb\u5236&#xff0c;\u901a\u8fc7\u8c03\u7528\u51fd\u6570setDecMode()\u3001setBinMode()\u3001setOctMode()\u3001setHexMode()\u53ef\u4ee5\u8bbe\u7f6e\u4e3a\u5e38\u7528\u7684\u5341\u8fdb\u5236\u3001\u4e8c\u8fdb\u5236\u3001\u516b\u8fdb\u5236\u3001\u5341\u516d\u8fdb\u5236\u683c\u5f0f\u3002<\/p>\n<\/li>\n<li>\n<p>value&#xff1a;\u8fd4\u56de\u663e\u793a\u503c&#xff0c;\u6d6e\u70b9\u6570\u3002\u82e5\u8bbe\u7f6e\u4e3a\u663e\u793a\u6574\u6570&#xff0c;\u4f1a\u81ea\u52a8\u56db\u820d\u4e94\u5165\u540e\u5f97\u5230\u6574\u6570&#xff0c;\u8bbe\u7f6e\u4e3aintValue\u7684\u503c\u3002\u5982\u679csmallDecimalPoint&#061;true&#xff0c;\u8bbe\u7f6evalue\u65f6\u53ef\u4ee5\u663e\u793a\u5c0f\u6570&#xff0c;\u4f46\u662f\u6570\u7684\u4f4d\u6570\u4e0d\u80fd\u8d85\u8fc7digitCount\u3002<\/p>\n<\/li>\n<li>\n<p>intValue&#xff1a;\u8fd4\u56de\u663e\u793a\u7684\u6574\u6570\u503c\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u4f8b\u5982&#xff0c;\u82e5smallDecimalPoint&#061;true&#xff0c;digitCount&#061;3&#xff0c;\u8bbe\u7f6evalue&#061;2.36&#xff0c;\u5219\u754c\u9762\u4e0aLCDNumber\u7ec4\u4ef6\u4f1a\u663e\u793a\u4e3a2.4&#xff1b;\u82e5\u8bbe\u7f6evalue&#061;1456.25&#xff0c;\u5219\u754c\u9762\u4e0aLCDNumber\u7ec4\u4ef6\u53ea\u4f1a\u663e\u793a145\u3002\u6240\u4ee5&#xff0c;\u7528QLCDNumber\u4f5c\u4e3a\u663e\u793a\u7ec4\u4ef6\u65f6&#xff0c;\u5e94\u6ce8\u610f\u8fd9\u4e9b\u5c5e\u6027\u7684\u914d\u5408\u3002<\/p>\n<h4>4.3.3\u3000\u5b9e\u4f8b\u529f\u80fd\u7684\u4ee3\u7801\u5b9e\u73b0<\/h4>\n<h5>1&#xff0e;\u7ea2\u7eff\u84dd\u914d\u8272<\/h5>\n<p>\u4f7f\u7528Red\u3001Green\u3001Blue\u548cAlpha 4\u4e2a\u6ed1\u52a8\u6761\u914d\u8272&#xff0c;\u7136\u540e\u8bbe\u7f6e\u4e3a\u65c1\u8fb9\u7684TextEdit\u7684\u5e95\u8272\u3002\u754c\u9762\u64cd\u4f5c\u662f\u5728\u62d6\u52a8\u6ed1\u5757\u65f6\u5c31\u8fdb\u5165\u54cd\u5e94\u7a0b\u5e8f&#xff0c;\u4e3aQSlider\u7684valueChanged()\u4fe1\u53f7\u8bbe\u8ba1\u69fd\u51fd\u6570\u3002\u5728UI\u8bbe\u8ba1\u5668\u91cc&#xff0c;\u9009\u4e2d\u6ed1\u52a8\u6761SliderRed&#xff0c;\u7136\u540e\u5728\u201cGo to slot\u201d\u5bf9\u8bdd\u6846\u91cc\u9009\u62e9valueChanged(int)\u4fe1\u53f7&#xff0c;\u751f\u6210\u69fd\u51fd\u6570\u539f\u578b\u58f0\u660e\u548c\u51fd\u6570\u4f53&#xff0c;\u7f16\u5199\u4ee3\u7801\u5982\u4e0b&#xff1a;<\/p>\n<p>void Widget::on_SliderRed_valueChanged(int value)<br \/>\n{ \/\/\u62d6\u52a8Red\u3001Green\u3001Blue \u989c\u8272\u6ed1\u52a8\u6761\u65f6\u8bbe\u7f6etextEdit\u7684\u5e95\u8272<br \/>\n   Q_UNUSED(value);<br \/>\n   QColor  color;<br \/>\n   int R&#061;ui-&gt;SliderRed-&gt;value();<br \/>\n   int G&#061;ui-&gt;SliderGreen-&gt;value();<br \/>\n   int B&#061;ui-&gt;SliderBlue-&gt;value();<br \/>\n   int alpha&#061;ui-&gt;SliderAlpha-&gt;value();<br \/>\n   color.setRgb(R,G,B,alpha); \/\/\u4f7f\u7528QColor\u7684setRgb()\u51fd\u6570\u83b7\u5f97\u989c\u8272<br \/>\n   QPalette pal&#061;ui-&gt;textEdit-&gt;palette();<br \/>\n   pal.setColor(QPalette::Base,color); \/\/\u8bbe\u7f6e\u5e95\u8272<br \/>\n   ui-&gt;textEdit-&gt;setPalette(pal);<br \/>\n}<\/p>\n<p>\u5728\u8fd9\u6bb5\u4ee3\u7801\u91cc&#xff0c;\u4f7f\u7528QSlider::value()\u51fd\u6570\u83b7\u5f97\u6ed1\u52a8\u6761\u7684\u5f53\u524d\u503c&#xff0c;\u7136\u540e\u8c03\u7528QColor::setRgb()\u51fd\u6570\u751f\u6210\u989c\u8272\u3002QColor\u7684\u9759\u6001\u51fd\u6570setRgb()\u5b9a\u4e49\u4e3a&#xff1a;<\/p>\n<p>void QColor::setRgb(int r, int g, int b, int a &#061; 255)<\/p>\n<p>\u5176\u4e2dr\u3001g\u3001b\u662f\u7ea2\u3001\u7eff\u3001\u84dd\u989c\u8272\u503c&#xff0c;\u5747\u57280\u5728255\u4e4b\u95f4&#xff0c;a\u662f\u989c\u8272\u7684alpha\u503c&#xff0c;\u7f3a\u7701\u662f255&#xff0c;\u53d6\u503c\u8303\u56f4\u4e5f\u662f0&#xff5e;255\u3002<\/p>\n<p>\u4ee5\u4e0a\u4ee3\u7801\u662fSliderRed\u7684valueChanged(int)\u4fe1\u53f7\u7684\u69fd\u51fd\u6570\u4ee3\u7801&#xff0c;\u5176\u4ed63\u4e2a\u6ed1\u52a8\u6761\u7684\u54cd\u5e94\u4ee3\u7801\u4e5f\u4e0e\u6b64\u5b8c\u5168\u76f8\u540c\u3002\u90a3\u4e48\u5728\u8bbe\u8ba1\u7a0b\u5e8f\u65f6&#xff0c;\u65e0\u9700\u4e3a\u5176\u4ed63\u4e2aSlider\u7684valueChanged(int)\u4fe1\u53f7\u518d\u751f\u6210\u69fd\u51fd\u6570&#xff0c;\u53ea\u9700\u5c06\u5b83\u4eec\u7684valueChanged(int)\u4fe1\u53f7\u4e0e\u69fd\u51fd\u6570on_SliderRed_valueChanged()\u5173\u8054\u5373\u53ef\u3002\u5728\u7a97\u53e3\u7c7bWidget\u7684\u6784\u9020\u51fd\u6570\u91cc\u5b9e\u73b0\u6b64\u529f\u80fd&#xff0c;\u4ee3\u7801\u5982\u4e0b&#xff1a;<\/p>\n<p>Widget::Widget(QWidget *parent) :   QWidget(parent),   ui(new Ui::Widget)<br \/>\n{<br \/>\n   ui-&gt;setupUi(this);<br \/>\n   this-&gt;setLayout(ui-&gt;horizontalLayout);<br \/>\n   QObject::connect(ui-&gt;SliderGreen,SIGNAL(valueChanged(int)),<br \/>\n                 this,SLOT(on_SliderRed_valueChanged(int)));<br \/>\n   QObject::connect(ui-&gt;SliderBlue,SIGNAL(valueChanged(int)),<br \/>\n                 this,SLOT(on_SliderRed_valueChanged(int)));<br \/>\n   QObject::connect(ui-&gt;SliderAlpha,SIGNAL(valueChanged(int)),<br \/>\n                 this,SLOT(on_SliderRed_valueChanged(int)));<br \/>\n}<\/p>\n<p>\u8fd9\u6837\u8bbe\u7f6e\u4fe1\u53f7\u4e0e\u69fd\u7684\u5173\u8054\u540e&#xff0c;\u8fd94\u4e2a\u6ed1\u52a8\u6761\u4e2d\u4efb\u4f55\u4e00\u4e2a\u7684\u503c\u6539\u53d8\u65f6&#xff0c;\u53d1\u5c04valueChanged(int)\u4fe1\u53f7&#xff0c;\u90fd\u8c03\u7528\u540c\u4e00\u4e2a\u69fd\u51fd\u6570on_SliderRed_valueChanged(int)&#xff0c;\u907f\u514d\u4e86\u91cd\u590d\u7f16\u5199\u4ee3\u7801\u3002<\/p>\n<h5>2&#xff0e;LCD\u503c\u663e\u793a<\/h5>\n<p>\u6ed1\u52a8\u8868\u76d8\u7ec4\u4ef6\u7684\u6307\u9488\u65f6&#xff0c;\u8bbe\u5b9aLCD\u7684\u663e\u793a\u503c\u7b49\u4e8e\u8868\u76d8\u7684\u503c\u3002\u5355\u51fb\u8fdb\u5236\u8bbe\u7f6e\u7684RadioButton\u53ef\u4ee5\u8bbe\u7f6eLCD\u7684\u663e\u793a\u8fdb\u5236\u548c\u663e\u793a\u6570\u4f4d\u6570\u3002\u4e3aDial\u7ec4\u4ef6\u7684valueChanged(int)\u4fe1\u53f7\u548c\u6bcf\u4e2aRadioButton\u7684clicked()\u4fe1\u53f7\u751f\u6210\u69fd\u51fd\u6570&#xff0c;\u7f16\u5199\u4ee3\u7801\u5b9e\u73b0\u76f8\u5e94\u7684\u529f\u80fd&#xff0c;\u4ee3\u7801\u5982\u4e0b&#xff1a;<\/p>\n<p>void Widget::on_dial_valueChanged(int value)<br \/>\n{ \/\/\u8bbe\u7f6eLCD\u7684\u663e\u793a\u503c\u7b49\u4e8eDial\u7684\u503c<br \/>\n   ui-&gt;LCDDisplay-&gt;display(value);<br \/>\n}<br \/>\nvoid Widget::on_radioBtnDec_clicked()<br \/>\n{ \/\/\u8bbe\u7f6eLCD\u663e\u793a\u5341\u8fdb\u5236\u6570<br \/>\n   ui-&gt;LCDDisplay-&gt;setDigitCount(3);  \/\/\u8bbe\u7f6e\u4f4d\u6570<br \/>\n   ui-&gt;LCDDisplay-&gt;setDecMode();<br \/>\n}<br \/>\nvoid Widget::on_radioBtnBin_clicked()<br \/>\n{ \/\/\u8bbe\u7f6eLCD\u663e\u793a\u4e8c\u8fdb\u5236\u6570<br \/>\n   ui-&gt;LCDDisplay-&gt;setDigitCount(8);<br \/>\n   ui-&gt;LCDDisplay-&gt;setBinMode();<br \/>\n}<br \/>\nvoid Widget::on_radioBtnOct_clicked()<br \/>\n{ \/\/\u8bbe\u7f6eLCD\u663e\u793a\u516b\u8fdb\u5236\u6570<br \/>\n   ui-&gt;LCDDisplay-&gt;setDigitCount(4);<br \/>\n   ui-&gt;LCDDisplay-&gt;setOctMode();<br \/>\n}<br \/>\nvoid Widget::on_radioBtnHex_clicked()<br \/>\n{ \/\/\u8bbe\u7f6eLCD\u663e\u793a\u5341\u516d\u8fdb\u5236\u6570<br \/>\n   ui-&gt;LCDDisplay-&gt;setDigitCount(3);<br \/>\n   ui-&gt;LCDDisplay-&gt;setHexMode();<br \/>\n}<\/p>\n<h3>4.4\u3000\u65f6\u95f4\u65e5\u671f\u4e0e\u5b9a\u65f6\u5668<\/h3>\n<h4>4.4.1\u3000\u65f6\u95f4\u65e5\u671f\u76f8\u5173\u7684\u7c7b<\/h4>\n<p>\u65f6\u95f4\u65e5\u671f\u662f\u7ecf\u5e38\u9047\u5230\u7684\u6570\u636e\u7c7b\u578b&#xff0c;Qt\u4e2d\u65f6\u95f4\u65e5\u671f\u7c7b\u578b\u7684\u7c7b\u5982\u4e0b\u3002<\/p>\n<ul>\n<li>\n<p>QTime: \u65f6\u95f4\u6570\u636e\u7c7b\u578b&#xff0c;\u4ec5\u8868\u793a\u65f6\u95f4&#xff0c;\u5982 15:23:13\u3002<\/p>\n<\/li>\n<li>\n<p>QDate: \u65e5\u671f\u6570\u636e\u7c7b\u578b&#xff0c;\u4ec5\u8868\u793a\u65e5\u671f&#xff0c;\u59822017-4-5\u3002<\/p>\n<\/li>\n<li>\n<p>QDateTime&#xff1a;\u65e5\u671f\u65f6\u95f4\u6570\u636e\u7c7b\u578b&#xff0c;\u8868\u793a\u65e5\u671f\u548c\u65f6\u95f4&#xff0c;\u59822017-03-23 08:12:43\u3002<\/p>\n<\/li>\n<\/ul>\n<p>Qt\u4e2d\u6709\u4e13\u95e8\u7528\u4e8e\u65e5\u671f\u3001\u65f6\u95f4\u7f16\u8f91\u548c\u663e\u793a\u7684\u754c\u9762\u7ec4\u4ef6&#xff0c;\u4ecb\u7ecd\u5982\u4e0b\u3002<\/p>\n<ul>\n<li>\n<p>QTimeEdit: \u7f16\u8f91\u548c\u663e\u793a\u65f6\u95f4\u7684\u7ec4\u4ef6\u3002<\/p>\n<\/li>\n<li>\n<p>QDateEdit&#xff1a;\u7f16\u8f91\u548c\u663e\u793a\u65e5\u671f\u7684\u7ec4\u4ef6\u3002<\/p>\n<\/li>\n<li>\n<p>QDateTimeEdit&#xff1a;\u7f16\u8f91\u548c\u663e\u793a\u65e5\u671f\u65f6\u95f4\u7684\u7ec4\u4ef6\u3002<\/p>\n<\/li>\n<li>\n<p>QCalendarWidget&#xff1a;\u4e00\u4e2a\u7528\u65e5\u5386\u5f62\u5f0f\u9009\u62e9\u65e5\u671f\u7684\u7ec4\u4ef6\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u5b9a\u65f6\u5668\u662f\u7528\u6765\u5904\u7406\u5468\u671f\u6027\u4e8b\u4ef6\u7684\u4e00\u79cd\u5bf9\u8c61&#xff0c;\u7c7b\u4f3c\u4e8e\u786c\u4ef6\u5b9a\u65f6\u5668\u3002\u4f8b\u5982\u8bbe\u7f6e\u4e00\u4e2a\u5b9a\u65f6\u5668\u7684\u5b9a\u65f6\u5468\u671f\u4e3a1000\u6beb\u79d2&#xff0c;\u90a3\u4e48\u6bcf1000\u6beb\u79d2\u5c31\u4f1a\u53d1\u5c04\u5b9a\u65f6\u5668\u7684timeout()\u4fe1\u53f7&#xff0c;\u5728\u4fe1\u53f7\u5173\u8054\u7684\u69fd\u51fd\u6570\u91cc\u5c31\u53ef\u4ee5\u505a\u76f8\u5e94\u7684\u5904\u7406\u3002Qt\u4e2d\u7684\u5b9a\u65f6\u5668\u7c7b\u662fQTimer&#xff0c;\u5b83\u76f4\u63a5\u4eceQObject\u7c7b\u7ee7\u627f\u800c\u6765&#xff0c;\u4e0d\u662f\u754c\u9762\u7ec4\u4ef6\u7c7b\u3002<\/p>\n<p>\u5b9e\u4f8b\u7a0b\u5e8fsamp4_5\u6f14\u793a\u8fd9\u4e9b\u65f6\u95f4\u65e5\u671f\u76f8\u5173\u7c7b\u7684\u4f7f\u7528&#xff0c;\u5176\u8fd0\u884c\u65f6\u754c\u9762\u5982\u539f\u4e66\u7684\u56fe4-5\u6240\u793a\u3002<\/p>\n<h4>4.4.2\u3000\u65e5\u671f\u65f6\u95f4\u6570\u636e\u4e0e\u5b57\u7b26\u4e32\u4e4b\u95f4\u7684\u8f6c\u6362<\/h4>\n<h5>1&#xff0e;\u65f6\u95f4\u3001\u65e5\u671f\u7f16\u8f91\u5668\u5c5e\u6027\u8bbe\u7f6e<\/h5>\n<p>\u5728\u56fe4-5\u7a97\u4f53\u5de6\u4e0a\u65b9\u7684\u201c\u65e5\u671f\u65f6\u95f4\u201dGroupbox\u4e2d&#xff0c;\u4f7f\u7528QTimeEdit\u3001QDateEdit\u3001QDateTimeEdit\u7ec4\u4ef6\u4f5c\u4e3a\u65f6\u95f4\u3001\u65e5\u671f\u3001\u65e5\u671f\u65f6\u95f4\u7f16\u8f91\u5668&#xff1b;\u5728\u5176\u53f3\u4fa7&#xff0c;\u5404\u653e\u7f6e\u4e00\u4e2aQLineEdit\u7ec4\u4ef6\u7528\u4e8e\u5b57\u7b26\u4e32\u663e\u793a\u3002<\/p>\n<p>QDateEdit\u548cQTimeEdit\u90fd\u4eceQDateTimeEdit\u7ee7\u627f\u800c\u6765&#xff0c;\u5b9e\u73b0\u9488\u5bf9\u65e5\u671f\u6216\u65f6\u95f4\u7684\u7279\u5b9a\u663e\u793a\u529f\u80fd\u3002\u5b9e\u9645\u4e0a&#xff0c;QDateEdit\u548cQTimeEdit\u7684\u663e\u793a\u529f\u80fd\u90fd\u53ef\u4ee5\u901a\u8fc7QDateTimeEdit\u5b9e\u73b0&#xff0c;\u53ea\u9700\u8bbe\u7f6e\u597d\u5c5e\u6027\u5373\u53ef\u3002<\/p>\n<p>QDateTimeEdit\u7c7b\u7684\u4e3b\u8981\u5c5e\u6027\u7684\u4ecb\u7ecd\u5982\u4e0b\u3002<\/p>\n<ul>\n<li>\n<p>datetime&#xff1a;\u65e5\u671f\u65f6\u95f4\u3002<\/p>\n<\/li>\n<li>\n<p>date&#xff1a;\u65e5\u671f&#xff0c;\u8bbe\u7f6edatetime\u65f6\u4f1a\u81ea\u52a8\u6539\u53d8date&#xff0c;\u540c\u6837&#xff0c;\u8bbe\u7f6edate\u65f6&#xff0c;\u4e5f\u4f1a\u81ea\u52a8\u6539\u53d8datetime\u91cc\u7684\u65e5\u671f\u3002<\/p>\n<\/li>\n<li>\n<p>time&#xff1a;\u65f6\u95f4&#xff0c;\u8bbe\u7f6edatetime\u65f6\u4f1a\u81ea\u52a8\u6539\u53d8time&#xff0c;\u540c\u6837&#xff0c;\u8bbe\u7f6etime\u65f6&#xff0c;\u4e5f\u4f1a\u81ea\u52a8\u6539\u53d8datetime\u91cc\u7684\u65f6\u95f4\u3002<\/p>\n<\/li>\n<li>\n<p>maximumDateTime\u3001minimumDateTime: \u6700\u5927\u3001\u6700\u5c0f\u65e5\u671f\u65f6\u95f4\u3002<\/p>\n<\/li>\n<li>\n<p>maximumDate\u3001minimumDate: \u6700\u5927\u3001\u6700\u5c0f\u65e5\u671f\u3002<\/p>\n<\/li>\n<li>\n<p>maximumTime\u3001minimumTime: \u6700\u5927\u3001\u6700\u5c0f\u65f6\u95f4\u3002<\/p>\n<\/li>\n<li>\n<p>currentSection&#xff1a;\u5f53\u524d\u8f93\u5165\u5149\u6807\u6240\u5728\u7684\u65f6\u95f4\u65e5\u671f\u6570\u636e\u6bb5&#xff0c;\u662f\u679a\u4e3e\u7c7b\u578bQDateTimeEdit::Section\u3002QDateTimeEdit\u663e\u793a\u65e5\u671f\u65f6\u95f4\u6570\u636e\u65f6\u5206\u4e3a\u591a\u4e2a\u6bb5&#xff0c;\u5355\u51fb\u7f16\u8f91\u6846\u53f3\u4fa7\u7684\u4e0a\u4e0b\u6309\u94ae\u53ef\u4fee\u6539\u5f53\u524d\u6bb5\u7684\u503c\u3002\u5982\u8f93\u5165\u5149\u6807\u5728YearSection\u6bb5&#xff0c;\u5c31\u4fee\u6539\u201c\u5e74\u201d\u7684\u503c\u3002<\/p>\n<\/li>\n<li>\n<p>currentSectionIndex&#xff1a;\u7528\u5e8f\u53f7\u8868\u793a\u7684\u8f93\u5165\u5149\u6807\u6240\u5728\u7684\u6bb5\u3002<\/p>\n<\/li>\n<li>\n<p>calendarPopup&#xff1a;\u662f\u5426\u5141\u8bb8\u5f39\u51fa\u4e00\u4e2a\u65e5\u5386\u9009\u62e9\u6846\u3002\u5f53\u53d6\u503c\u4e3atrue\u65f6&#xff0c;\u53f3\u4fa7\u7684\u8f93\u5165\u6309\u94ae\u53d8\u6210\u4e0eQComboBox\u7c7b\u4f3c\u7684\u4e0b\u62c9\u6309\u94ae&#xff0c;\u5355\u51fb\u6309\u94ae\u65f6\u51fa\u73b0\u4e00\u4e2a\u65e5\u5386\u9009\u62e9\u6846&#xff0c;\u7528\u4e8e\u5728\u65e5\u5386\u4e0a\u9009\u62e9\u65e5\u671f\u3002\u5bf9\u4e8eQTimeEdit&#xff0c;\u6b64\u5c5e\u6027\u65e0\u6548\u3002<\/p>\n<\/li>\n<li>\n<p>displayFormat&#xff1a;\u663e\u793a\u683c\u5f0f&#xff0c;\u65e5\u671f\u65f6\u95f4\u6570\u636e\u7684\u663e\u793a\u683c\u5f0f&#xff0c;\u4f8b\u5982\u8bbe\u7f6e\u4e3a\u201cyyyy-MM-dd HH:mm:ss\u201d&#xff0c;\u4e00\u4e2a\u65e5\u671f\u65f6\u95f4\u6570\u636e\u5c31\u663e\u793a\u4e3a\u201c2016-11-02 08:23:46\u201d\u3002<\/p>\n<\/li>\n<\/ul>\n<h5>2&#xff0e;\u65e5\u671f\u65f6\u95f4\u6570\u636e\u7684\u83b7\u53d6\u4e0e\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32<\/h5>\n<p>\u201c\u8bfb\u53d6\u5f53\u524d\u65e5\u671f\u65f6\u95f4\u201d\u6309\u94ae\u7684clicked()\u4fe1\u53f7\u7684\u69fd\u51fd\u6570\u4ee3\u7801\u5982\u4e0b&#xff1a;<\/p>\n<p>void Dialog::on_btnGetTime_clicked()<br \/>\n{ \/\/\u83b7\u53d6\u5f53\u524d\u65e5\u671f\u65f6\u95f4&#xff0c;\u4e3a\u4e09\u4e2a\u4e13\u7528\u7f16\u8f91\u5668\u8bbe\u7f6e\u65e5\u671f\u65f6\u95f4\u6570\u636e&#xff0c;\u5e76\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32<br \/>\n   QDateTime  curDateTime&#061;QDateTime::currentDateTime();<br \/>\n   ui-&gt;timeEdit-&gt;setTime(curDateTime.time());<br \/>\n   ui-&gt;editTime-&gt;setText(curDateTime.toString(&#034;hh:mm:ss&#034;));<br \/>\n   ui-&gt;dateEdit-&gt;setDate(curDateTime.date());<br \/>\n   ui-&gt;editDate-&gt;setText(curDateTime.toString(&#034;yyyy-MM-dd&#034;));<br \/>\n   ui-&gt;dateTimeEdit-&gt;setDateTime(curDateTime);<br \/>\n   ui-&gt;editDateTime-&gt;setText(curDateTime.toString(&#034;yyyy-MM-dd hh:mm:ss&#034;));<br \/>\n}<\/p>\n<p>\u9996\u5148\u7528QDateTime\u7c7b\u7684\u9759\u6001\u51fd\u6570currentDateTime()\u83b7\u53d6\u5f53\u524d\u65e5\u671f\u65f6\u95f4&#xff0c;\u5e76\u8d4b\u503c\u7ed9\u53d8\u91cfcurDate Time\u3002<\/p>\n<p>\u7136\u540e\u7528curDateTime\u53d8\u91cf\u8bbe\u7f6e\u754c\u9762\u4e0a3\u4e2a\u65e5\u671f\u3001\u65f6\u95f4\u7f16\u8f91\u5668\u7684\u65f6\u95f4\u6216\u65e5\u671f\u503c&#xff0c;\u5229\u7528\u4e86QDateTime\u7684time()\u548cdate()\u5206\u522b\u63d0\u53d6\u65f6\u95f4\u548c\u65e5\u671f\u3002<\/p>\n<p>\u5c06curDateTime\u8868\u793a\u7684\u65e5\u671f\u65f6\u95f4\u6570\u636e\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32&#xff0c;\u7136\u540e\u5728LineEdit\u7f16\u8f91\u6846\u4e0a\u663e\u793a\u3002\u65f6\u95f4\u65e5\u671f\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32\u4f7f\u7528\u4e86QDateTime\u7684toString()\u51fd\u6570&#xff0c;\u5206\u522b\u7528\u4e0d\u540c\u7684\u683c\u5f0f\u663e\u793a\u65f6\u95f4\u3001\u65e5\u671f\u3001\u65e5\u671f\u65f6\u95f4\u3002<\/p>\n<p>ui-&gt;editTime-&gt;setText(curDateTime.toString(&#034;hh:mm:ss&#034;));<br \/>\nui-&gt;editDate-&gt;setText(curDateTime.toString(&#034;yyyy-MM-dd&#034;));<br \/>\nui-&gt;editDateTime-&gt;setText(curDateTime.toString(&#034;yyyy-MM-dd hh:mm:ss&#034;));<\/p>\n<p>QDateTime::toString()\u51fd\u6570\u7684\u51fd\u6570\u539f\u578b\u662f&#xff1a;<\/p>\n<p>QString QDateTime::toString(const QString &amp;format) const<\/p>\n<p>\u5b83\u5c06\u65e5\u671f\u65f6\u95f4\u6570\u636e\u6309\u7167format\u6307\u5b9a\u7684\u683c\u5f0f\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32\u3002format\u662f\u4e00\u4e2a\u5b57\u7b26\u4e32&#xff0c;\u5305\u542b\u4e00\u4e9b\u7279\u5b9a\u7684\u5b57\u7b26&#xff0c;\u8868\u793a\u65e5\u671f\u6216\u65f6\u95f4\u7684\u5404\u4e2a\u90e8\u5206&#xff0c;\u88684-2\u662f\u7528\u4e8e\u65e5\u671f\u65f6\u95f4\u663e\u793a\u7684\u5e38\u7528\u683c\u5f0f\u7b26\u3002<\/p>\n<p>\u88684-2\u3000\u7528\u4e8e\u65e5\u671f\u663e\u793a\u7684\u683c\u5f0f\u7b26\u53ca\u5176\u610f\u4e49<\/p>\n<table>\n<tr>\u5b57\u7b26\u610f\u4e49<\/tr>\n<tbody>\n<tr>\n<td>d<\/td>\n<td>\u5929&#xff0c;\u4e0d\u8865\u96f6\u663e\u793a&#xff0c;1-31<\/td>\n<\/tr>\n<tr>\n<td>dd<\/td>\n<td>\u5929&#xff0c;\u8865\u96f6\u663e\u793a&#xff0c;01-31<\/td>\n<\/tr>\n<tr>\n<td>M<\/td>\n<td>\u6708&#xff0c;\u4e0d\u8865\u96f6\u663e\u793a&#xff0c;1-12<\/td>\n<\/tr>\n<tr>\n<td>MM<\/td>\n<td>\u6708&#xff0c;\u8865\u96f6\u663e\u793a&#xff0c;01-12<\/td>\n<\/tr>\n<tr>\n<td>yy<\/td>\n<td>\u5e74&#xff0c;\u4e24\u4f4d\u663e\u793a&#xff0c;00-99<\/td>\n<\/tr>\n<tr>\n<td>yyyy<\/td>\n<td>\u5e74&#xff0c;4\u4f4d\u6570\u5b57\u663e\u793a&#xff0c;\u59822016<\/td>\n<\/tr>\n<tr>\n<td>h<\/td>\n<td>\u5c0f\u65f6&#xff0c;\u4e0d\u8865\u96f6&#xff0c;0-23\u62161-12&#xff08;\u5982\u679c\u663e\u793aAM\/PM&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>hh<\/td>\n<td>\u5c0f\u65f6&#xff0c;\u8865\u96f62\u4f4d\u663e\u793a&#xff0c;00-23\u621601-12&#xff08;\u5982\u679c\u663e\u793aAM\/PM&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>H<\/td>\n<td>\u5c0f\u65f6&#xff0c;\u4e0d\u8865\u96f6&#xff0c;0-23&#xff08;\u5373\u4f7f\u663e\u793aAM\/PM&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>HH<\/td>\n<td>\u5c0f\u65f6&#xff0c;\u8865\u96f6\u663e\u793a&#xff0c;00-23&#xff08;\u5373\u4f7f\u663e\u793aAM\/PM&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>m<\/td>\n<td>\u5206\u949f&#xff0c;\u4e0d\u8865\u96f6&#xff0c;0-59<\/td>\n<\/tr>\n<tr>\n<td>mm<\/td>\n<td>\u5206\u949f&#xff0c;\u8865\u96f6\u663e\u793a&#xff0c;00-59<\/td>\n<\/tr>\n<tr>\n<td>z<\/td>\n<td>\u6beb\u79d2&#xff0c;\u4e0d\u8865\u96f6&#xff0c;0-999<\/td>\n<\/tr>\n<tr>\n<td>zzz<\/td>\n<td>\u6beb\u79d2&#xff0c;\u8865\u96f63\u4f4d\u663e\u793a&#xff0c;000-999<\/td>\n<\/tr>\n<tr>\n<td>AP\u6216A<\/td>\n<td>\u4f7f\u7528AM\/pm\u663e\u793a<\/td>\n<\/tr>\n<tr>\n<td>ap\u6216a<\/td>\n<td>\u4f7f\u7528am\/pm\u663e\u793a<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u5728\u8bbe\u7f6e\u65e5\u671f\u65f6\u95f4\u663e\u793a\u5b57\u7b26\u4e32\u683c\u5f0f\u65f6&#xff0c;\u8fd8\u53ef\u4ee5\u4f7f\u7528\u586b\u5b57\u7b26&#xff0c;\u751a\u81f3\u4f7f\u7528\u6c49\u5b57\u3002\u4f8b\u5982&#xff0c;\u65e5\u671f\u663e\u793a\u683c\u5f0f\u53ef\u4ee5\u8bbe\u7f6e\u4e3a&#xff1a;<\/p>\n<p>curDateTime.toString(&#034;yyyy\u5e74MM\u6708dd\u65e5&#034;);<\/p>\n<p>\u8fd9\u6837\u5f97\u5230\u7684\u5b57\u7b26\u4e32\u662f\u201c2016\u5e7411\u670821\u65e5\u201d\u3002<\/p>\n<h5>3&#xff0e;\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u65e5\u671f\u65f6\u95f4<\/h5>\n<p>\u540c\u6837\u7684&#xff0c;\u4e5f\u53ef\u4ee5\u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3aQTime\u3001QDate\u6216QDateTime\u7c7b\u578b&#xff0c;\u4f7f\u7528\u9759\u6001\u51fd\u6570QDateTime:: fromString()&#xff0c;\u5176\u51fd\u6570\u539f\u578b\u4e3a&#xff1a;<\/p>\n<p>QDateTime QDateTime::fromString(const QString &amp;string, const QString &amp;format)<\/p>\n<p>\u5176\u4e2d&#xff0c;\u7b2c1\u4e2a\u53c2\u6570string\u662f\u65e5\u671f\u65f6\u95f4\u5b57\u7b26\u4e32&#xff0c;\u7b2c2\u4e2a\u53c2\u6570format\u662f\u5b57\u7b26\u4e32\u8868\u793a\u7684\u683c\u5f0f&#xff0c;\u6309\u7167\u88684-2\u7684\u683c\u5f0f\u5b57\u7b26\u5b9a\u4e49\u3002<\/p>\n<p>\u5728\u7a0b\u5e8f\u8fd0\u884c\u65f6&#xff0c;\u624b\u5de5\u4fee\u6539\u201c\u65e5\u671f\u65f6\u95f4\u201d\u540e\u9762\u6587\u672c\u6846\u91cc\u7684\u65e5\u671f\u65f6\u95f4\u5b57\u7b26\u4e32&#xff0c;\u5355\u51fb\u201c\u8bbe\u7f6e\u65e5\u671f\u65f6\u95f4\u201d\u6309\u94ae&#xff0c;\u53ef\u4ee5\u5c06\u6587\u672c\u6846\u91cc\u7684\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3aQDateTime\u53d8\u91cf&#xff0c;\u5e76\u8bbe\u7f6e\u4e3a\u5de6\u4fa7DateTimeEdit\u7ec4\u4ef6\u7684\u65e5\u671f\u65f6\u95f4\u6570\u636e&#xff0c;\u4ee3\u7801\u5982\u4e0b&#xff1a;<\/p>\n<p>void Dialog::on_btnSetDateTime_clicked()<br \/>\n{\/\/\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a QDateTime<br \/>\n   QString str&#061;ui-&gt;editDateTime-&gt;text();<br \/>\n   str&#061;str.trimmed();<br \/>\n   if (!str.isEmpty())<br \/>\n   {<br \/>\n      QDateTime datetime&#061;QDateTime::fromString(str,&#034;yyyy-MM-dd hh:mm:ss&#034;);<br \/>\n      ui-&gt;dateTimeEdit-&gt;setDateTime(datetime);<br \/>\n   }<br \/>\n}<\/p>\n<p>\u9759\u6001\u51fd\u6570QDateTime::fromString()\u5c06\u4e00\u4e2a\u5b57\u7b26\u4e32\u6309\u7167\u683c\u5f0f\u8f6c\u6362\u4e3a\u65e5\u671f\u65f6\u95f4\u7c7b\u578b\u3002\u7a0b\u5e8f\u4e2d\u7684\u4ee3\u7801\u662f&#xff1a;<\/p>\n<p>datetime&#061;QDateTime::fromString(str,&#034;yyyy-MM-dd hh:mm:ss&#034;);<\/p>\n<p>\u8fd9\u91cc\u5c06\u5b57\u7b26\u4e32str\u6309\u7167\u683c\u5f0f&#034;yyyy-MM-dd hh:mm:ss&#034;\u8f6c\u6362\u4e3a\u65e5\u671f\u65f6\u95f4\u53d8\u91cf&#xff0c;\u683c\u5f0f\u662f\u6307\u5b57\u7b26\u4e32str\u6240\u8868\u793a\u7684\u65e5\u671f\u65f6\u95f4\u7684\u683c\u5f0f\u3002<\/p>\n<h4>4.4.3\u3000QCalendarWidget\u65e5\u5386\u7ec4\u4ef6<\/h4>\n<p>\u539f\u4e66\u7684\u56fe4-5\u7a97\u4f53\u53f3\u4fa7\u662f\u4e00\u4e2aQCalendarWidget\u7ec4\u4ef6&#xff0c;\u5b83\u4ee5\u65e5\u5386\u7684\u5f62\u5f0f\u663e\u793a\u65e5\u671f&#xff0c;\u53ef\u4ee5\u7528\u4e8e\u65e5\u671f\u9009\u62e9\u3002<\/p>\n<p>QCalendarWidget\u6709\u4e00\u4e2a\u4fe1\u53f7selectionChanged()&#xff0c;\u5728\u65e5\u5386\u4e0a\u9009\u62e9\u7684\u65e5\u671f\u53d8\u5316\u540e\u4f1a\u53d1\u5c04\u6b64\u4fe1\u53f7&#xff0c;\u4e3a\u6b64\u4fe1\u53f7\u521b\u5efa\u69fd\u51fd\u6570&#xff0c;\u7f16\u5199\u4ee3\u7801\u5982\u4e0b&#xff1a;<\/p>\n<p>void Dialog::on_calendarWidget_selectionChanged()<br \/>\n{ \/\/\u5728\u65e5\u5386\u4e0a\u9009\u62e9\u65e5\u671f<br \/>\n   QDate dt&#061;ui-&gt;calendarWidget-&gt;selectedDate();<br \/>\n   QString str&#061;dt.toString(&#034;yyyy\u5e74M\u6708d\u65e5&#034;);<br \/>\n   ui-&gt;editCalendar-&gt;setText(str);<br \/>\n}<\/p>\n<h4>4.4.4\u3000\u5b9a\u65f6\u5668\u7684\u4f7f\u7528<\/h4>\n<p>Qt\u4e2d\u7684\u5b9a\u65f6\u5668\u7c7b\u662fQTimer\u3002QTimer\u4e0d\u662f\u4e00\u4e2a\u53ef\u89c1\u7684\u754c\u9762\u7ec4\u4ef6&#xff0c;\u5728UI \u8bbe\u8ba1\u5668\u7684\u7ec4\u4ef6\u9762\u677f\u91cc\u627e\u4e0d\u5230\u5b83\u3002\u5b9e\u4f8b\u7a0b\u5e8f\u5b9e\u73b0\u4e86\u4e00\u4e2a\u8ba1\u65f6\u5668\u7684\u529f\u80fd&#xff0c;\u5c31\u662f\u8ba1\u7b97\u5b9a\u65f6\u5668\u5f00\u59cb\u5230\u505c\u6b62\u6301\u7eed\u7684\u65f6\u95f4\u957f\u5ea6&#xff0c;\u8ba1\u65f6\u5668\u662fQTime\u7c7b\u3002<\/p>\n<p>QTimer\u4e3b\u8981\u7684\u5c5e\u6027\u662finterval&#xff0c;\u662f\u5b9a\u65f6\u4e2d\u65ad\u7684\u5468\u671f&#xff0c;\u5355\u4f4d\u6beb\u79d2\u3002QTimer\u4e3b\u8981\u7684\u4fe1\u53f7\u662ftimeout()&#xff0c;\u5728\u5b9a\u65f6\u4e2d\u65ad\u65f6\u53d1\u5c04\u6b64\u4fe1\u53f7&#xff0c;\u8981\u60f3\u5728\u5b9a\u65f6\u4e2d\u65ad\u91cc\u505a\u51fa\u54cd\u5e94&#xff0c;\u8fd9\u5c31\u9700\u8981\u7f16\u5199timeout()\u4fe1\u53f7\u7684\u69fd\u51fd\u6570\u3002\u4e0b\u9762\u662f\u7a97\u53e3\u7c7b\u4e2d\u589e\u52a0\u7684\u5b9a\u4e49&#xff08;\u7701\u7565\u4e86\u5176\u4ed6\u4e0d\u76f8\u5173\u7684\u5b9a\u4e49&#xff09;&#xff1a;<\/p>\n<p>class Dialog : public QDialog<br \/>\n{<br \/>\nprivate:<br \/>\n   QTimer *fTimer;  \/\/\u5b9a\u65f6\u5668<br \/>\n   QTime fTimeCounter;\/\/\u8ba1\u65f6\u5668<br \/>\nprivate slots:<br \/>\n   void on_timer_timeout(); \/\/\u5b9a\u65f6\u6ea2\u51fa\u5904\u7406\u69fd\u51fd\u6570<br \/>\n};<\/p>\n<p>\u8fd9\u91cc\u5b9a\u4e49\u4e86\u4e00\u4e2a\u5b9a\u65f6\u5668fTimer&#xff0c;\u4e00\u4e2a\u8ba1\u65f6\u5668fTimeCounter\u3002\u8fd8\u5b9a\u4e49\u4e86\u4e00\u4e2a\u69fd\u51fd\u6570on_timer_timeout()&#xff0c;\u4f5c\u4e3a\u5b9a\u65f6\u5668\u7684timeout()\u4fe1\u53f7\u7684\u54cd\u5e94\u69fd\u51fd\u6570\u3002<\/p>\n<p>\u9700\u8981\u5728\u7a97\u53e3\u7c7b\u7684\u6784\u9020\u51fd\u6570\u91cc\u521b\u5efa\u5b9a\u65f6\u5668&#xff0c;\u5e76\u8fdb\u884c\u4fe1\u53f7\u4e0e\u69fd\u7684\u5173\u8054\u3002\u4ee3\u7801\u5982\u4e0b&#xff1a;<\/p>\n<p>Dialog::Dialog(QWidget *parent) :   QDialog(parent),   ui(new Ui::Dialog)<br \/>\n{<br \/>\n   ui-&gt;setupUi(this);<br \/>\n   fTimer&#061;new QTimer(this);<br \/>\n   fTimer-&gt;stop();<br \/>\n   fTimer-&gt;setInterval(1000);\/\/\u8bbe\u7f6e\u5b9a\u65f6\u5468\u671f, \u5355\u4f4d&#xff1a;\u6beb\u79d2<br \/>\n   connect(fTimer,SIGNAL(timeout()),this,SLOT(on_timer_timeout()));<br \/>\n}<\/p>\n<p>\u69fd\u51fd\u6570on_timer_timeout()\u7684\u5b9e\u73b0\u4ee3\u7801\u5982\u4e0b&#xff1a;<\/p>\n<p>void Dialog::on_timer_timeout()<br \/>\n{ \/\/\u5b9a\u65f6\u5668\u4e2d\u65ad\u54cd\u5e94<br \/>\n   QTime  curTime&#061;QTime::currentTime(); \/\/\u83b7\u53d6\u5f53\u524d\u65f6\u95f4<br \/>\n   ui-&gt;LCDHour-&gt;display(curTime.hour()); \/\/\u663e\u793a  \u5c0f\u65f6<br \/>\n   ui-&gt;LCDMin-&gt;display(curTime.minute());\/\/\u663e\u793a  \u5206\u949f<br \/>\n   ui-&gt;LCDSec-&gt;display(curTime.second());\/\/\u663e\u793a  \u79d2<br \/>\n   int va&#061;ui-&gt;progressBar-&gt;value();<br \/>\n   va&#043;&#043;;<br \/>\n   if (va&gt;100)<br \/>\n      va&#061;0;<br \/>\n   ui-&gt;progressBar-&gt;setValue(va);<br \/>\n}<\/p>\n<p>\u8fd9\u6bb5\u4ee3\u7801\u9996\u5148\u7528QTime\u7c7b\u7684\u9759\u6001\u51fd\u6570QTime::currentTime()\u83b7\u53d6\u5f53\u524d\u65f6\u95f4&#xff0c;\u7136\u540e\u7528QTime\u7684\u6210\u5458\u51fd\u6570hour()\u3001minute()\u3001second()\u5206\u522b\u83b7\u53d6\u5c0f\u65f6\u3001\u5206\u949f\u3001\u79d2&#xff0c;\u5e76\u5728\u51e0\u4e2aLCDNumber\u7ec4\u4ef6\u4e0a\u663e\u793a\u3002\u5faa\u73af\u66f4\u65b0progressBar\u7684\u503c&#xff0c;\u662f\u4e3a\u4e86\u8ba9\u754c\u9762\u6709\u53d8\u5316&#xff0c;\u8868\u793a\u5b9a\u65f6\u5668\u5728\u8fd0\u884c\u3002<\/p>\n<p>\u8bbe\u7f6e\u5b9a\u65f6\u5668\u7684\u5468\u671f&#xff0c;\u53ea\u9700\u8c03\u7528QTimer::setInterval()\u51fd\u6570\u5373\u53ef\u3002<\/p>\n<p>QTimer::start()\u51fd\u6570\u7528\u4e8e\u542f\u52a8\u5b9a\u65f6\u5668&#xff0c;\u754c\u9762\u4e0a\u7684\u201c\u5f00\u59cb\u201d\u6309\u94ae\u4ee3\u7801\u5982\u4e0b&#xff1a;<\/p>\n<p>void Dialog::on_btnStart_clicked()<br \/>\n{<br \/>\n   fTimer-&gt;start();\/\/\u5b9a\u65f6\u5668\u5f00\u59cb\u5de5\u4f5c<br \/>\n   fTimeCounter.start();\/\/\u8ba1\u65f6\u5668\u5f00\u59cb\u5de5\u4f5c<br \/>\n   ui-&gt;btnStart-&gt;setEnabled(false);<br \/>\n   ui-&gt;btnStop-&gt;setEnabled(true);<br \/>\n   ui-&gt;btnSetIntv-&gt;setEnabled(false);<br \/>\n}<\/p>\n<p>\u8ba1\u65f6\u5668fTimeCounter\u6267\u884cstart()\u662f\u5c06\u5f53\u524d\u65f6\u95f4\u4f5c\u4e3a\u8ba1\u65f6\u5668\u7684\u65f6\u95f4\u3002<\/p>\n<p>QTimer::stop()\u51fd\u6570\u505c\u6b62\u5b9a\u65f6\u5668&#xff0c;\u754c\u9762\u4e0a\u7684\u201c\u505c\u6b62\u201d\u6309\u94ae\u53ef\u5b9e\u73b0\u8fd9\u4e00\u529f\u80fd&#xff0c;\u5176\u4ee3\u7801\u5982\u4e0b&#xff1a;<\/p>\n<p>void Dialog::on_btnStop_clicked()<br \/>\n{<br \/>\n   fTimer-&gt;stop(); \/\/\u5b9a\u65f6\u5668\u505c\u6b62<br \/>\n   int tmMsec&#061;fTimeCounter.elapsed();\/\/\u6beb\u79d2\u6570<br \/>\n   int ms&#061;tmMsec%1000;<br \/>\n   int sec&#061;tmMsec\/1000;<br \/>\n   QString str&#061;QString::asprintf(&#034;\u6d41\u901d\u65f6\u95f4&#xff1a;%d \u79d2&#xff0c;%d \u6beb\u79d2&#034;,sec,ms);<br \/>\n   ui-&gt;LabElapsTime-&gt;setText(str);<br \/>\n   ui-&gt;btnStart-&gt;setEnabled(true);<br \/>\n   ui-&gt;btnStop-&gt;setEnabled(false);<br \/>\n   ui-&gt;btnSetIntv-&gt;setEnabled(true);<br \/>\n}<\/p>\n<h3>4.5\u3000QComboBox\u548cQPlainTextEdit<\/h3>\n<h4>4.5.1\u3000\u5b9e\u4f8b\u529f\u80fd\u6982\u8ff0<\/h4>\n<p>QComboBox\u662f\u4e0b\u62c9\u5217\u8868\u6846\u7ec4\u4ef6\u7c7b&#xff0c;\u5b83\u63d0\u4f9b\u4e00\u4e2a\u4e0b\u62c9\u5217\u8868\u4f9b\u7528\u6237\u9009\u62e9&#xff0c;\u4e5f\u53ef\u4ee5\u76f4\u63a5\u5f53\u4f5c\u4e00\u4e2aQLineEdit\u7528\u4f5c\u8f93\u5165\u3002QComboBox\u9664\u4e86\u663e\u793a\u53ef\u89c1\u4e0b\u62c9\u5217\u8868\u5916&#xff0c;\u6bcf\u4e2a\u9879&#xff08;item&#xff0c;\u6216\u79f0\u5217\u8868\u9879&#xff09;\u8fd8\u53ef\u4ee5\u5173\u8054\u4e00\u4e2aQVariant\u7c7b\u578b\u7684\u53d8\u91cf&#xff0c;\u7528\u4e8e\u5b58\u50a8\u4e00\u4e9b\u4e0d\u53ef\u89c1\u6570\u636e\u3002<\/p>\n<p>QPlainTextEdit\u662f\u4e00\u4e2a\u591a\u884c\u6587\u672c\u7f16\u8f91\u5668&#xff0c;\u7528\u4e8e\u663e\u793a\u548c\u7f16\u8f91\u591a\u884c\u7b80\u5355\u6587\u672c\u3002\u5b9e\u4f8bsamp4_6\u6f14\u793aQComboBox\u548cQPlainTextEdit\u7684\u4f7f\u7528&#xff0c;\u5176\u8fd0\u884c\u65f6\u754c\u9762\u5982\u539f\u4e66\u7684\u56fe4-6\u6240\u793a\u3002<\/p>\n<h4>4.5.2\u3000QComboBox\u7684\u4f7f\u7528<\/h4>\n<h5>1&#xff0e;\u8bbe\u8ba1\u65f6\u5c5e\u6027\u8bbe\u7f6e<\/h5>\n<p>QComboBox\u4e3b\u8981\u7684\u529f\u80fd\u662f\u63d0\u4f9b\u4e00\u4e2a\u4e0b\u62c9\u5217\u8868\u4f9b\u9009\u62e9\u8f93\u5165\u3002\u5728\u754c\u9762\u4e0a\u653e\u7f6e\u4e00\u4e2aQComboBox\u7ec4\u4ef6\u540e&#xff0c;\u53cc\u51fb\u6b64\u7ec4\u4ef6&#xff0c;\u53ef\u4ee5\u51fa\u73b0\u5982\u539f\u4e66\u7684\u56fe4-7\u6240\u793a\u7684\u5bf9\u8bdd\u6846&#xff0c;\u5bf9QComboBox\u7ec4\u4ef6\u7684\u4e0b\u62c9\u5217\u8868\u7684\u9879\u8fdb\u884c\u7f16\u8f91\u3002\u5728\u56fe4-7\u6240\u793a\u7684\u5bf9\u8bdd\u6846\u4e2d&#xff0c;\u53ef\u4ee5\u8fdb\u884c\u7f16\u8f91&#xff0c;\u5982\u6dfb\u52a0\u3001\u5220\u9664\u3001\u4e0a\u79fb\u3001\u4e0b\u79fb\u64cd\u4f5c&#xff0c;\u8fd8\u53ef\u4ee5\u8bbe\u7f6e\u9879\u7684\u56fe\u6807\u3002<\/p>\n<h5>2&#xff0e;\u7528\u4ee3\u7801\u6dfb\u52a0\u7b80\u5355\u9879<\/h5>\n<p>\u7a97\u53e3\u4e0a\u7684\u201c\u521d\u59cb\u5316\u5217\u8868\u201d\u6309\u94ae\u521d\u59cb\u5316\u4e0b\u62c9\u5217\u8868\u6846\u7684\u5217\u8868\u5185\u5bb9&#xff0c;\u5176\u4ee3\u7801\u5982\u4e0b&#xff1a;<\/p>\n<p>void Widget::on_btnIniItems_clicked()<br \/>\n{ \/\/&#034;\u521d\u59cb\u5316\u5217\u8868&#034;\u6309\u94ae<br \/>\n   QIcon   icon;<br \/>\n   icon.addFile(&#034;:\/images\/icons\/aim.ico&#034;);<br \/>\n   ui-&gt;comboBox-&gt;clear();<br \/>\n   for (int i&#061;0;i&lt;20;i&#043;&#043;)<br \/>\n      ui-&gt;comboBox-&gt;addItem(icon,QString::asprintf(&#034;Item %d&#034;,i)); \/\/\u5e26\u56fe\u6807<br \/>\n\/\/    ui-&gt;comboBox-&gt;addItem(QString::asprintf(&#034;Item %d&#034;,i)); \/\/\u4e0d\u5e26\u56fe\u6807<br \/>\n}<\/p>\n<p>\u6dfb\u52a0\u4e00\u4e2a\u9879\u65f6\u53ef\u4ee5\u6307\u5b9a\u4e00\u4e2a\u56fe\u6807&#xff0c;\u56fe\u6807\u6765\u6e90\u4e8e\u8d44\u6e90\u6587\u4ef6\u3002<\/p>\n<p>addItem()\u7528\u4e8e\u6dfb\u52a0\u4e00\u4e2a\u5217\u8868\u9879&#xff0c;\u5982\u679c\u53ea\u662f\u6dfb\u52a0\u5b57\u7b26\u4e32\u5217\u8868\u9879&#xff0c;\u800c\u4e14\u6570\u636e\u6765\u6e90\u4e8e\u4e00\u4e2aQStringList\u53d8\u91cf&#xff0c;\u53ef\u4ee5\u4f7f\u7528addItems()\u51fd\u6570&#xff0c;\u793a\u4f8b\u4ee3\u7801\u5982\u4e0b&#xff1a;<\/p>\n<p>ui-&gt;comboBox-&gt;clear();<br \/>\nQStringList strList;<br \/>\nstrList&lt;&lt;&#034;\u5317\u4eac&#034;&lt;&lt;&#034;\u4e0a\u6d77&#034;&lt;&lt;&#034;\u5929\u6d25&#034;&lt;&lt;&#034;\u6cb3\u5317\u7701&#034;&lt;&lt;&#034;\u5c71\u4e1c\u7701&#034;&lt;&lt;&#034;\u5c71\u897f\u7701&#034;;<br \/>\nui-&gt;comboBox-&gt;addItems(strList);<\/p>\n<h5>3&#xff0e;\u6dfb\u52a0\u5177\u6709\u7528\u6237\u6570\u636e\u7684\u9879<\/h5>\n<p>QComboBox::addItem()\u51fd\u6570\u7684\u4e24\u79cd\u53c2\u6570\u7684\u539f\u578b\u5b9a\u4e49\u5982\u4e0b&#xff1a;<\/p>\n<p>void addItem (const QString &amp;text, const QVariant &amp;userData &#061; QVariant())<br \/>\nvoid addItem (const QIcon &amp;icon, const QString &amp;text, const QVariant &amp;userData &#061; QVariant())<\/p>\n<p>\u4e0d\u7ba1\u662f\u54ea\u4e00\u4e2aaddItem()\u51fd\u6570&#xff0c;\u540e\u9762\u90fd\u6709\u4e00\u4e2a\u53ef\u9009\u7684QVariant\u7c7b\u578b\u7684\u53c2\u6570userData&#xff0c;\u53ef\u4ee5\u5229\u7528\u8fd9\u4e2a\u53d8\u91cf\u5b58\u50a8\u7528\u6237\u5b9a\u4e49\u6570\u636e\u3002<\/p>\n<p>\u754c\u9762\u4e0a\u53e6\u4e00\u4e2aComboBox\u7ec4\u4ef6\u4f7f\u7528\u4e86\u7528\u6237\u6570\u636e&#xff0c;\u201c\u521d\u59cb\u5316\u57ce\u5e02&#043;\u533a\u53f7\u201d\u6309\u94ae\u7684\u69fd\u51fd\u6570\u4ee3\u7801\u5982\u4e0b&#xff1a;<\/p>\n<p>void Widget::on_btnIni2_clicked()<br \/>\n{\/\/\u521d\u59cb\u5316\u5177\u6709\u81ea\u5b9a\u4e49\u6570\u636e\u7684ComboBox<br \/>\n   QMap&lt;QString, int&gt; City_Zone;<br \/>\n   City_Zone.insert(&#034;\u5317\u4eac&#034;,10);<br \/>\n   City_Zone.insert(&#034;\u4e0a\u6d77&#034;,21);<br \/>\n   City_Zone.insert(&#034;\u5929\u6d25&#034;,22);<br \/>\n   City_Zone.insert(&#034;\u5927\u8fde&#034;,411);<br \/>\n   City_Zone.insert(&#034;\u9526\u5dde&#034;,416);<br \/>\n   City_Zone.insert(&#034;\u5f90\u5dde&#034;,516);<br \/>\n   City_Zone.insert(&#034;\u798f\u5dde&#034;,591);<br \/>\n   City_Zone.insert(&#034;\u9752\u5c9b&#034;,532);<br \/>\n   ui-&gt;comboBox2-&gt;clear();<br \/>\n   foreach(const QString &amp;str,City_Zone.keys())<br \/>\n      ui-&gt;comboBox2-&gt;addItem(str,City_Zone.value(str));<br \/>\n}<\/p>\n<p>\u8fd9\u91cc\u5b9a\u4e49\u4e86\u4e00\u4e2a\u5173\u8054\u5bb9\u5668\u7c7bQMap&lt;QString, int&gt; City_Zone&#xff0c;\u7528\u4e8e\u5b58\u50a8&lt;\u57ce\u5e02&#xff0c;\u533a\u53f7&gt;\u6620\u5c04\u8868\u3002\u4e3aCity_Zone\u586b\u5145\u6570\u636e\u540e&#xff0c;\u7ed9comboBox2\u6dfb\u52a0\u9879\u65f6&#xff0c;\u4f7f\u7528\u4e86foreach\u5173\u952e\u5b57\u904d\u5386City_Zone.keys()\u3002\u6dfb\u52a0\u9879\u7684\u8bed\u53e5\u5982\u4e0b&#xff1a;<\/p>\n<p>ui-&gt;comboBox2-&gt;addItem(str,City_Zone.value(str));<\/p>\n<p>\u57ce\u5e02\u540d\u79f0\u4f5c\u4e3a\u9879\u663e\u793a\u7684\u5b57\u7b26\u4e32&#xff0c;\u7535\u8bdd\u533a\u53f7\u4f5c\u4e3a\u9879\u5173\u8054\u7684\u7528\u6237\u6570\u636e&#xff0c;\u4f46\u662f\u5728\u5217\u8868\u6846\u91cc\u53ea\u80fd\u770b\u5230\u57ce\u5e02\u540d\u79f0\u3002<\/p>\n<p>\u6ce8\u610f&#xff1a;\u5c06City_Zone\u7684\u5185\u5bb9\u6dfb\u52a0\u5230\u5217\u8868\u6846\u4e4b\u540e&#xff0c;\u5217\u8868\u6846\u91cc\u663e\u793a\u7684\u5217\u8868\u9879\u7684\u987a\u5e8f\u4e0e\u6e90\u7a0b\u5e8f\u4e2d\u8bbe\u7f6eCity_Zone\u7684\u987a\u5e8f\u4e0d\u4e00\u81f4&#xff0c;\u56e0\u4e3aQMap&lt;Key, T&gt;\u5bb9\u5668\u7c7b\u4f1a\u81ea\u52a8\u6309\u7167Key\u6392\u5e8f\u3002<\/p>\n<h5>4&#xff0e;QComboBox\u5217\u8868\u9879\u7684\u8bbf\u95ee<\/h5>\n<p>QComboBox\u5b58\u50a8\u7684\u9879\u662f\u4e00\u4e2a\u5217\u8868&#xff0c;\u4f46\u662fQComboBox\u4e0d\u63d0\u4f9b\u6574\u4e2a\u5217\u8868\u7528\u4e8e\u8bbf\u95ee&#xff0c;\u53ef\u4ee5\u901a\u8fc7\u7d22\u5f15\u8bbf\u95ee\u67d0\u4e2a\u9879\u3002\u8bbf\u95ee\u9879\u7684\u4e00\u4e9b\u51fd\u6570\u4e3b\u8981\u6709\u4ee5\u4e0b\u51e0\u79cd\u3002<\/p>\n<ul>\n<li>\n<p>int currentIndex()&#xff0c;\u8fd4\u56de\u5f53\u524d\u9879\u7684\u5e8f\u53f7&#xff0c;\u7b2c\u4e00\u4e2a\u9879\u7684\u5e8f\u53f7\u4e3a0\u3002<\/p>\n<\/li>\n<li>\n<p>QString currentText()&#xff0c;\u8fd4\u56de\u5f53\u524d\u9879\u7684\u6587\u5b57\u3002<\/p>\n<\/li>\n<li>\n<p>QVariant currentData(int role &#061; Qt::UserRole)&#xff0c;\u8fd4\u56de\u5f53\u524d\u9879\u7684\u5173\u8054\u6570\u636e&#xff0c;\u6570\u636e\u7684\u7f3a\u7701\u89d2\u8272\u4e3arole &#061; Qt::UserRole&#xff0c;\u89d2\u8272\u7684\u610f\u4e49\u57285.1\u8282\u8be6\u7ec6\u4ecb\u7ecd\u3002<\/p>\n<\/li>\n<li>\n<p>QString itemText(int index)&#xff0c;\u8fd4\u56de\u6307\u5b9a\u7d22\u5f15\u53f7\u7684\u9879\u7684\u6587\u5b57\u3002<\/p>\n<\/li>\n<li>\n<p>QVariant itemData(int index, int role &#061; Qt::UserRole)&#xff0c;\u8fd4\u56de\u6307\u5b9a\u7d22\u5f15\u53f7\u7684\u9879\u7684\u5173\u8054\u6570\u636e\u3002<\/p>\n<\/li>\n<li>\n<p>int count()&#xff0c;\u8fd4\u56de\u9879\u7684\u4e2a\u6570\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u5728\u4e00\u4e2aQComboBox\u7ec4\u4ef6\u4e0a\u9009\u62e9\u9879\u53d1\u751f\u53d8\u5316\u65f6&#xff0c;\u4f1a\u53d1\u5c04\u5982\u4e0b\u4e24\u4e2a\u4fe1\u53f7&#xff1a;<\/p>\n<p>void currentIndexChanged(int index)<br \/>\nvoid currentIndexChanged(const QString &amp;text)<\/p>\n<p>\u8fd9\u4e24\u4e2a\u4fe1\u53f7\u53ea\u662f\u4f20\u9012\u7684\u53c2\u6570\u4e0d\u540c&#xff0c;\u4e00\u4e2a\u4f20\u9012\u7684\u662f\u5f53\u524d\u9879\u7684\u7d22\u5f15\u53f7&#xff0c;\u4e00\u4e2a\u4f20\u9012\u7684\u5f53\u524d\u9879\u7684\u6587\u5b57\u3002<\/p>\n<p>\u4e3a\u4f7f\u7528\u65b9\u4fbf&#xff0c;\u9009\u62e9\u4e3acurrentIndexChanged(const QString &amp;text)\u4fe1\u53f7\u7f16\u5199\u69fd\u51fd\u6570\u3002\u7a97\u4f53\u4e0a\u53ea\u5b58\u50a8\u5b57\u7b26\u4e32\u5217\u8868\u7684comboBox\u7684\u69fd\u51fd\u6570\u4ee3\u7801\u5982\u4e0b&#xff1a;<\/p>\n<p>void Widget::on_comboBox_currentIndexChanged(const QString &amp;arg1)<br \/>\n{<br \/>\n   ui-&gt;plainTextEdit-&gt;appendPlainText(arg1);<br \/>\n}<\/p>\n<p>\u5173\u8054\u6709\u57ce\u5e02\u533a\u53f7\u7684comboBox2\u7684\u69fd\u51fd\u6570\u4ee3\u7801\u5982\u4e0b&#xff1a;<\/p>\n<p>void Widget::on_comboBox2_currentIndexChanged(const QString &amp;arg1)<br \/>\n{<br \/>\n   QString zone&#061;ui-&gt;comboBox2-&gt;currentData().toString();  \/\/\u9879\u5173\u8054\u7684\u6570\u636e<br \/>\n   ui-&gt;plainTextEdit-&gt;appendPlainText(arg1&#043;&#034;:\u533a\u53f7&#061;&#034;&#043;zone);<br \/>\n}<\/p>\n<h4>4.5.3\u3000QPlainTextEdit\u7684\u4f7f\u7528<\/h4>\n<h5>1&#xff0e;QPlainTextEdit\u7684\u529f\u80fd<\/h5>\n<p>QPlainTextEdit\u662f\u7528\u4e8e\u7f16\u8f91\u591a\u884c\u6587\u672c\u7684\u7f16\u8f91\u5668&#xff0c;\u53ef\u4ee5\u7f16\u8f91\u666e\u901a\u6587\u672c\u3002\u53e6\u5916&#xff0c;\u8fd8\u6709\u4e00\u4e2aQTextEdit\u7ec4\u4ef6&#xff0c;\u662f\u4e00\u4e2a\u6240\u89c1\u5373\u6240\u5f97\u7684\u53ef\u4ee5\u7f16\u8f91\u5e26\u683c\u5f0f\u6587\u672c\u7684\u7ec4\u4ef6&#xff0c;\u4ee5HTML\u683c\u5f0f\u6807\u8bb0\u7b26\u5b9a\u4e49\u6587\u672c\u683c\u5f0f\u3002<\/p>\n<p>\u4ece\u524d\u9762\u7684\u4ee3\u7801\u5df2\u7ecf\u770b\u51fa&#xff0c;\u4f7f\u7528QPlainTextEdit::appendPlainText(const QString &amp;text)\u51fd\u6570\u5c31\u53ef\u4ee5\u5411PlainTextEdit\u7ec4\u4ef6\u6dfb\u52a0\u4e00\u884c\u5b57\u7b26\u4e32\u3002<\/p>\n<p>QPlainTextEdit\u63d0\u4f9bcut()\u3001copy()\u3001paste()\u3001undo()\u3001redo()\u3001clear()\u3001selectAll()\u7b49\u6807\u51c6\u7f16\u8f91\u529f\u80fd\u7684\u69fd\u51fd\u6570&#xff0c;QPlainTextEdit\u8fd8\u63d0\u4f9b\u4e00\u4e2a\u6807\u51c6\u7684\u53f3\u952e\u5feb\u6377\u83dc\u5355\u3002<\/p>\n<h5>2&#xff0e;\u9010\u884c\u8bfb\u53d6\u6587\u5b57\u5185\u5bb9<\/h5>\n<p>\u5982\u679c\u8981\u5c06QPlainTextEdit\u7ec4\u4ef6\u91cc\u663e\u793a\u7684\u6240\u6709\u6587\u5b57\u8bfb\u53d6\u51fa\u6765&#xff0c;\u6709\u4e00\u4e2a\u7b80\u5355\u7684\u51fd\u6570toPlainText()\u53ef\u4ee5\u5c06\u5168\u90e8\u6587\u5b57\u5185\u5bb9\u8f93\u51fa\u4e3a\u4e00\u4e2a\u5b57\u7b26\u4e32&#xff0c;\u5176\u5b9a\u4e49\u5982\u4e0b&#xff1a;<\/p>\n<p>QString QPlainTextEdit::toPlainText() const<\/p>\n<p>\u4f46\u662f\u5982\u679c\u8981\u9010\u884c\u8bfb\u53d6QPlainTextEdit\u7ec4\u4ef6\u91cc\u7684\u5b57\u7b26\u4e32&#xff0c;\u5219\u7a0d\u5fae\u9ebb\u70e6\u4e00\u70b9\u3002<\/p>\n<p>\u4e0b\u9762\u662f\u539f\u4e66\u7684\u56fe4-6\u7a97\u53e3\u4e2d\u201c\u6587\u672c\u6846\u5185\u5bb9\u6dfb\u52a0\u5230ComboBox\u201d\u6309\u94ae\u7684\u54cd\u5e94\u4ee3\u7801&#xff0c;\u5b83\u5c06plainTextEdit\u91cc\u7684\u6bcf\u4e00\u884c\u4f5c\u4e3a\u4e00\u4e2a\u9879\u6dfb\u52a0\u5230comboBox\u91cc\u3002<\/p>\n<p>void Widget::on_btnToComboBox_clicked()<br \/>\n{ \/\/plainTextEdit \u7684\u5185\u5bb9\u9010\u884c\u6dfb\u52a0\u4e3a comboBox \u7684\u9879<br \/>\n   QTextDocument* doc&#061;ui-&gt;plainTextEdit-&gt;document();\/\/\u6587\u672c\u5bf9\u8c61<br \/>\n   int cnt&#061;doc-&gt;blockCount();\/\/\u56de\u8f66\u7b26\u662f\u4e00\u4e2ablock<br \/>\n   QIcon   icon(&#034;:\/images\/icons\/aim.ico&#034;);<br \/>\n   ui-&gt;comboBox-&gt;clear();<br \/>\n   for (int i&#061;0; i&lt;cnt;i&#043;&#043;)<br \/>\n   {<br \/>\n       QTextBlock  textLine&#061;doc-&gt;findBlockByNumber(i);\/\/ \u6587\u672c\u4e2d\u7684\u4e00\u6bb5<br \/>\n       QString str&#061;textLine.text();<br \/>\n       ui-&gt;comboBox-&gt;addItem(icon,str);<br \/>\n   }<br \/>\n}<\/p>\n<p>QPlainTextEdit\u7684\u6587\u5b57\u5185\u5bb9\u4ee5QTextDocument\u7c7b\u578b\u5b58\u50a8&#xff0c;\u51fd\u6570document()\u8fd4\u56de\u8fd9\u4e2a\u6587\u6863\u5bf9\u8c61\u7684\u6307\u9488\u3002<\/p>\n<p>QTextDocument\u662f\u5185\u5b58\u4e2d\u7684\u6587\u672c\u5bf9\u8c61&#xff0c;\u4ee5\u6587\u672c\u5757\u7684\u65b9\u5f0f\u5b58\u50a8&#xff0c;\u4e00\u4e2a\u6587\u672c\u5757\u5c31\u662f\u4e00\u4e2a\u6bb5\u843d&#xff0c;\u6bcf\u4e2a\u6bb5\u843d\u4ee5\u56de\u8f66\u7b26\u7ed3\u675f\u3002QTextDocument\u63d0\u4f9b\u4e00\u4e9b\u51fd\u6570\u5b9e\u73b0\u5bf9\u6587\u672c\u5185\u5bb9\u7684\u5b58\u53d6\u3002<\/p>\n<ul>\n<li>\n<p>int blockCount()&#xff0c;\u83b7\u5f97\u6587\u672c\u5757\u4e2a\u6570\u3002<\/p>\n<\/li>\n<li>\n<p>QTextBlock findBlockByNumber(int blockNumber)&#xff0c;\u8bfb\u53d6\u67d0\u4e00\u4e2a\u6587\u672c\u5757&#xff0c;\u5e8f\u53f7\u4ece0\u5f00\u59cb&#xff0c;\u81f3blockCount()-1\u7ed3\u675f\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u4e00\u4e2adocument\u6709\u591a\u4e2aTextBlock&#xff0c;\u4ecedocument\u4e2d\u8bfb\u53d6\u51fa\u7684\u4e00\u4e2a\u6587\u672c\u5757\u7c7b\u578b\u4e3aQTextBlock&#xff0c;\u901a\u8fc7QTextBlock::text()\u51fd\u6570\u53ef\u4ee5\u83b7\u53d6\u5176\u7eaf\u6587\u672c\u6587\u5b57\u3002<\/p>\n<h5>3&#xff0e;\u4f7f\u7528QPlainTextEdit\u81ea\u5e26\u7684\u5feb\u6377\u83dc\u5355<\/h5>\n<p>QPlainTextEdit\u662f\u4e00\u4e2a\u591a\u884c\u6587\u5b57\u7f16\u8f91\u6846&#xff0c;\u6709\u81ea\u5e26\u7684\u53f3\u952e\u5feb\u6377\u83dc\u5355&#xff0c;\u53ef\u5b9e\u73b0\u5e38\u89c1\u7684\u7f16\u8f91\u529f\u80fd\u3002\u5728UI\u8bbe\u8ba1\u5668\u91cc&#xff0c;\u9009\u62e9\u4e3aplainTextEdit\u7684customContextMenuRequested()\u4fe1\u53f7\u751f\u6210\u69fd\u51fd\u6570&#xff0c;\u7f16\u5199\u5982\u4e0b\u7684\u4ee3\u7801&#xff0c;\u5c31\u53ef\u4ee5\u521b\u5efa\u5e76\u663e\u793aQPlainTextEdit\u7684\u6807\u51c6\u5feb\u6377\u83dc\u5355&#xff1a;<\/p>\n<p>void Widget::on_plainTextEdit_customContextMenuRequested(const QPoint &amp;pos)<br \/>\n{ \/\/\u521b\u5efa\u5e76\u663e\u793a\u6807\u51c6\u5f39\u51fa\u5f0f\u83dc\u5355<br \/>\n   QMenu* menu&#061;ui-&gt;plainTextEdit-&gt;createStandardContextMenu();<br \/>\n   menu-&gt;exec(pos);<br \/>\n}<\/p>\n<h3>4.6\u3000QListWidget\u548cQToolButton<\/h3>\n<h4>4.6.1\u3000\u5b9e\u4f8b\u529f\u80fd\u7b80\u4ecb<\/h4>\n<p>Qt\u4e2d\u7528\u4e8e\u9879&#xff08;Item&#xff09;\u5904\u7406\u7684\u7ec4\u4ef6\u6709\u4e24\u7c7b&#xff0c;\u4e00\u7c7b\u662fItem Views&#xff0c;\u5305\u62ecQListView\u3001QTreeView\u3001QTableView\u3001QColumnView\u7b49&#xff1b;\u53e6\u4e00\u7c7b\u662fItem Widgets&#xff0c;\u5305\u62ecQListWidget\u3001QTreeWidget\u548cQTableWidget\u3002<\/p>\n<p>Item Views\u57fa\u4e8e\u6a21\u578b\/\u89c6\u56fe&#xff08;Model\/View&#xff09;\u7ed3\u6784&#xff0c;\u89c6\u56fe&#xff08;View&#xff09;\u4e0e\u6a21\u578b\u6570\u636e&#xff08;Model Data&#xff09;\u5173\u8054\u5b9e\u73b0\u6570\u636e\u7684\u663e\u793a\u548c\u7f16\u8f91&#xff0c;\u6a21\u578b\/\u89c6\u56fe\u7ed3\u6784\u7684\u4f7f\u7528\u5728\u7b2c5\u7ae0\u8be6\u7ec6\u4ecb\u7ecd\u3002<\/p>\n<p>Item Widgets\u662f\u76f4\u63a5\u5c06\u6570\u636e\u5b58\u50a8\u5728\u6bcf\u4e00\u4e2a\u9879\u91cc&#xff0c;\u4f8b\u5982&#xff0c;QListWidget\u7684\u6bcf\u4e00\u884c\u662f\u4e00\u4e2a\u9879&#xff0c;QTreeWidget\u7684\u6bcf\u4e2a\u8282\u70b9\u662f\u4e00\u4e2a\u9879&#xff0c;QTableWidget\u7684\u6bcf\u4e00\u4e2a\u5355\u5143\u683c\u662f\u4e00\u4e2a\u9879\u3002\u4e00\u4e2a\u9879\u5b58\u50a8\u4e86\u6587\u5b57\u3001\u6587\u5b57\u7684\u683c\u5f0f\u3001\u81ea\u5b9a\u4e49\u6570\u636e\u7b49\u3002<\/p>\n<p>Item Widgets\u662fGUI\u8bbe\u8ba1\u4e2d\u5e38\u7528\u7684\u7ec4\u4ef6&#xff0c;\u672c\u8282\u901a\u8fc7\u5b9e\u4f8bsamp4_7\u5148\u4ecb\u7ecdQListWidget\u4ee5\u53ca\u5176\u4ed6\u4e00\u4e9b\u7ec4\u4ef6\u7684\u7528\u6cd5&#xff0c;\u5b9e\u4f8b\u8fd0\u884c\u65f6\u754c\u9762\u5982\u539f\u4e66\u7684\u56fe4-8\u6240\u793a\u3002<\/p>\n<p>\u672c\u5b9e\u4f8b\u4e0d\u4ec5\u4ecb\u7ecdQListWidget\u7684\u4f7f\u7528&#xff0c;\u8fd8\u5305\u62ec\u5982\u4e0b\u4e00\u4e9b\u529f\u80fd\u7684\u5b9e\u73b0\u3002<\/p>\n<ul>\n<li>\n<p>\u4f7f\u7528QTabWidget\u8bbe\u8ba1\u591a\u9875\u754c\u9762&#xff0c;\u5de5\u4f5c\u533a\u53f3\u4fa7\u5c31\u662f\u4e00\u4e2a\u5177\u67093\u4e2a\u9875\u9762\u7684TabWidget\u7ec4\u4ef6\u3002<\/p>\n<\/li>\n<li>\n<p>\u4f7f\u7528QToolBox\u8bbe\u8ba1\u591a\u7ec4\u5de5\u5177\u7bb1&#xff0c;\u5de5\u4f5c\u533a\u5de6\u4fa7\u662f\u4e00\u4e2a\u67093\u4e2a\u7ec4\u7684ToolBox\u7ec4\u4ef6\u3002<\/p>\n<\/li>\n<li>\n<p>\u4f7f\u7528\u5206\u9694\u6761&#xff08;QSplitter&#xff09;\u8bbe\u8ba1\u53ef\u4ee5\u5de6\u53f3\u5206\u5272\u7684\u754c\u9762&#xff0c;\u5de5\u4f5c\u533a\u7684ToolBox\u548cTabWidget\u4e4b\u95f4\u6709\u4e00\u4e2asplitter&#xff0c;\u8fd0\u884c\u65f6\u53ef\u4ee5\u5206\u5272\u8c03\u6574\u4e24\u4e2a\u7ec4\u4ef6\u7684\u5927\u5c0f\u3002<\/p>\n<\/li>\n<li>\n<p>\u521b\u5efaActions&#xff0c;\u7528Actions\u8bbe\u8ba1\u4e3b\u5de5\u5177\u680f&#xff0c;\u7528Action\u5173\u8054QToolButton\u6309\u94ae\u3002<\/p>\n<\/li>\n<li>\n<p>\u4f7f\u7528QToolButton\u6309\u94ae&#xff0c;\u8bbe\u7f6e\u4e0eAction\u5173\u8054&#xff0c;\u8bbe\u8ba1\u5177\u6709\u4e0b\u62c9\u83dc\u5355\u529f\u80fd\u7684ToolButton\u6309\u94ae&#xff0c;\u5728\u4e3b\u5de5\u5177\u680f\u4e0a\u6dfb\u52a0\u5177\u6709\u4e0b\u62c9\u83dc\u5355\u7684ToolButton\u6309\u94ae\u3002<\/p>\n<\/li>\n<li>\n<p>\u4f7f\u7528QListWidget&#xff0c;\u6f14\u793a\u5982\u4f55\u521b\u5efa\u548c\u6dfb\u52a0\u9879&#xff0c;\u4e3a\u9879\u8bbe\u7f6e\u56fe\u6807\u548c\u590d\u9009\u6846&#xff0c;\u5982\u4f55\u904d\u5386\u5217\u8868\u8fdb\u884c\u9009\u62e9\u3002<\/p>\n<\/li>\n<li>\n<p>QListWidget\u7684\u4e3b\u8981\u4fe1\u53f7currentItemChanged()\u7684\u529f\u80fd&#xff0c;\u7f16\u5199\u54cd\u5e94\u69fd\u51fd\u6570\u3002<\/p>\n<\/li>\n<li>\n<p>\u4e3aQListWidget\u7ec4\u4ef6\u5229\u7528\u5df2\u8bbe\u8ba1\u7684Actions\u521b\u5efa\u81ea\u5b9a\u4e49\u5feb\u6377\u83dc\u5355\u3002<\/p>\n<\/li>\n<\/ul>\n<h4>4.6.2\u3000\u754c\u9762\u8bbe\u8ba1<\/h4>\n<h5>1&#xff0e;\u6df7\u5408\u5f0f\u754c\u9762\u8bbe\u8ba1<\/h5>\n<p>\u672c\u5b9e\u4f8b\u7684\u4e3b\u7a97\u53e3\u4eceQMainWindow\u7ee7\u627f\u800c\u6765&#xff0c;\u91c7\u7528\u6df7\u5408\u5f0f\u754c\u9762\u8bbe\u8ba1\u3002\u5728UI\u8bbe\u8ba1\u5668\u91cc\u5b8c\u6210\u7684\u7a97\u4f53\u754c\u9762\u5982\u539f\u4e66\u7684\u56fe4-9\u6240\u793a&#xff0c;\u4e0e\u539f\u4e66\u7684\u56fe4-8\u6240\u793a\u8fd0\u884c\u754c\u9762\u6709\u4e00\u4e9b\u533a\u522b\u3002\u8fd0\u884c\u65f6\u5728\u5de5\u5177\u680f\u4e0a\u589e\u52a0\u4e86\u4e00\u4e2a\u5177\u6709\u4e0b\u62c9\u83dc\u5355\u7684\u5de5\u5177\u680f\u6309\u94ae&#xff0c;\u4e3a\u5404\u4e2aToolButton\u6309\u94ae\u8bbe\u7f6e\u4e86\u5173\u8054\u7684Action\u3002<\/p>\n<p>\u56fe4-9\u4e2d\u754c\u9762\u4e0a\u7684\u6309\u94ae\u90fd\u4f7f\u7528QToolButton\u7ec4\u4ef6&#xff0c;\u5728\u8bbe\u8ba1\u65f6\u53ea\u4e3a\u5176\u547d\u540d&#xff0c;\u56fe\u4e2d\u6309\u94ae\u4e0a\u663e\u793a\u7684\u6587\u5b57\u5c31\u662f\u5176objectName\u3002QToolButton\u6709\u4e00\u4e2asetDefaultAction()\u51fd\u6570&#xff0c;\u53ef\u4ee5\u4f7f\u5176\u4e0e\u4e00\u4e2aAction\u5173\u8054&#xff0c;\u6309\u94ae\u7684\u6587\u5b57\u3001\u56fe\u6807\u3001ToolTip\u90fd\u5c06\u81ea\u52a8\u8bbe\u7f6e\u4e3a\u4e0e\u5173\u8054\u7684Action\u4e00\u81f4&#xff0c;\u5355\u51fb\u4e00\u4e2aQToolButton\u6309\u94ae\u5c31\u662f\u6267\u884cAction\u7684\u69fd\u51fd\u6570&#xff0c;\u4e0e\u5de5\u5177\u680f\u4e0a\u7684\u6309\u94ae\u4e00\u6837\u3002\u5b9e\u9645\u4e0a&#xff0c;\u4e3b\u5de5\u5177\u680f\u4e0a\u7684\u6309\u94ae\u5c31\u662f\u6839\u636eAction\u81ea\u52a8\u521b\u5efa\u7684QToolButton\u6309\u94ae\u3002<\/p>\n<p>QToolButton\u8fd8\u6709\u4e00\u4e2asetMenu()\u51fd\u6570&#xff0c;\u53ef\u4ee5\u4e3a\u5176\u8bbe\u7f6e\u4e00\u4e2a\u4e0b\u62c9\u5f0f\u83dc\u5355&#xff0c;\u914d\u5408QToolButton\u7684\u4e00\u4e9b\u5c5e\u6027\u8bbe\u7f6e&#xff0c;\u53ef\u4ee5\u6709\u4e0d\u540c\u7684\u4e0b\u62c9\u83dc\u5355\u6548\u679c\u3002\u5728\u56fe4-8\u4e2d&#xff0c;\u5de5\u5177\u680f\u4e0a\u7684\u201c\u9879\u9009\u62e9\u201d\u76f4\u63a5\u663e\u793a\u4e0b\u62c9\u83dc\u5355&#xff0c;\u800c\u5728\u5217\u8868\u6846\u4e0a\u65b9\u7684\u201c\u9879\u9009\u62e9\u201d\u6309\u94ae&#xff0c;\u53ea\u6709\u5355\u51fb\u53f3\u4fa7\u7684\u5411\u4e0b\u7bad\u5934\u624d\u5f39\u51fa\u4e0b\u62c9\u83dc\u5355&#xff0c;\u76f4\u63a5\u5355\u51fb\u6309\u94ae\u4f1a\u6267\u884c\u6309\u94ae\u5173\u8054\u7684Action\u7684\u4ee3\u7801\u3002<\/p>\n<p>\u6df7\u5408\u5f0f\u754c\u9762\u8bbe\u8ba1\u4e2d\u7528\u4ee3\u7801\u5b9e\u73b0\u7684\u90e8\u5206&#xff0c;\u5c31\u662f\u4e3a\u754c\u9762\u4e0a\u7684\u5404ToolButton\u6309\u94ae\u8bbe\u7f6e\u5173\u8054\u7684Action&#xff0c;\u5728\u5de5\u5177\u680f\u4e0a\u52a8\u6001\u6dfb\u52a0\u4e00\u4e2aToolButton&#xff0c;\u5e76\u8bbe\u7f6e\u5176\u4e0b\u62c9\u83dc\u5355\u529f\u80fd\u3002<\/p>\n<h5>2&#xff0e;QToolBox\u7ec4\u4ef6\u7684\u8bbe\u7f6e<\/h5>\n<p>\u5728UI\u8bbe\u8ba1\u5668\u91cc\u8bbe\u8ba1\u754c\u9762\u65f6&#xff0c;\u5728\u7a97\u53e3\u7684\u5de5\u4f5c\u533a\u653e\u7f6e\u4e00\u4e2aQToolBox\u7ec4\u4ef6\u3002<\/p>\n<p>\u5728ToolBox\u7ec4\u4ef6\u4e0a\u8c03\u51fa\u53f3\u952e\u5feb\u6377\u83dc\u5355&#xff0c;\u53ef\u4ee5\u4f7f\u7528\u201cInsert Page\u201d\u201cDelete Page\u201d\u7b49\u83dc\u5355\u9879\u5b9e\u73b0\u5206\u7ec4\u7684\u6dfb\u52a0\u6216\u5220\u9664\u3002\u5355\u51fb\u67d0\u4e2a\u5206\u7ec4\u7684\u6807\u9898&#xff0c;\u5c31\u53ef\u4ee5\u9009\u62e9\u4e3aToolBox\u7ec4\u4ef6\u7684\u5f53\u524d\u5206\u7ec4&#xff0c;\u5728Property Editor\u4e2d\u4e3b\u8981\u7684\u5c5e\u6027\u8bbe\u7f6e\u5982\u4e0b\u3002<\/p>\n<ul>\n<li>\n<p>currentIndex&#xff0c;\u5f53\u524d\u5206\u7ec4\u7f16\u53f7&#xff0c;\u7b2c1\u4e2a\u5206\u7ec4\u7684\u7f16\u53f7\u662f0&#xff0c;\u901a\u8fc7\u6539\u53d8\u8fd9\u4e2a\u503c&#xff0c;\u53ef\u4ee5\u9009\u62e9\u4e0d\u540c\u7684\u5206\u7ec4\u9875\u9762\u3002<\/p>\n<\/li>\n<li>\n<p>currentItemText&#xff0c;\u5f53\u524d\u5206\u7ec4\u7684\u6807\u9898\u3002<\/p>\n<\/li>\n<li>\n<p>currentItemName&#xff0c;\u5f53\u524d\u5206\u7ec4\u7684\u5bf9\u8c61\u540d\u79f0\u3002<\/p>\n<\/li>\n<li>\n<p>currentItemIcon&#xff0c;\u4e3a\u5f53\u524d\u5206\u7ec4\u8bbe\u7f6e\u4e00\u4e2a\u56fe\u6807&#xff0c;\u663e\u793a\u5728\u6587\u5b57\u6807\u9898\u7684\u5de6\u4fa7\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u5728\u4e00\u4e2aToolBox\u5185\u53ef\u4ee5\u653e\u7f6e\u4efb\u4f55\u754c\u9762\u7ec4\u4ef6&#xff0c;\u5982QGroupBox\u3001QLineEdit\u3001QPushButton\u7b49\u3002\u5728\u7b2c\u4e00\u4e2a\u5206\u7ec4\u91cc\u653e\u7f6e\u51e0\u4e2aQToolButton\u6309\u94ae&#xff0c;\u5e76\u8bbe\u7f6e\u4e3aGrid\u5e03\u5c40\u3002\u6ce8\u610f\u4e0d\u8981\u4f7f\u7528\u6c34\u5e73\u5e03\u5c40&#xff0c;\u56e0\u4e3a\u4f7f\u7528\u6c34\u5e73\u5e03\u5c40\u65f6&#xff0c;\u7ec4\u5185\u7684ToolButton\u6309\u952e\u90fd\u662f\u81ea\u52a8\u5411\u5de6\u9760\u9f50\u7684&#xff0c;\u800c\u4f7f\u7528Grid\u5e03\u5c40\u65f6&#xff0c;\u81ea\u52a8\u5c45\u4e2d\u3002<\/p>\n<h5>3&#xff0e;QTabWidget\u7ec4\u4ef6\u7684\u8bbe\u7f6e<\/h5>\n<p>QTabWidget\u662f\u4e00\u4e2a\u591a\u9875\u7684\u5bb9\u5668\u7c7b\u7ec4\u4ef6\u3002\u5728\u7a97\u53e3\u4e0a\u653e\u7f6e\u4e00\u4e2aQTabWidget\u7ec4\u4ef6&#xff0c;\u901a\u8fc7\u5176\u5feb\u6377\u83dc\u5355\u7684\u201cInsert Page\u201d\u201cDelete Page\u201d\u7b49\u83dc\u5355\u9879\u5b9e\u73b0\u9875\u9762\u7684\u6dfb\u52a0\u6216\u5220\u9664\u3002\u5728Property Editor\u4e2d\u4e3b\u8981\u7684\u5c5e\u6027\u8bbe\u7f6e\u5982\u4e0b\u3002<\/p>\n<ul>\n<li>\n<p>tabPosition&#xff1a;\u9875\u6807\u7b7e\u7684\u4f4d\u7f6e&#xff0c;\u4e1c\u3001\u897f\u3001\u5357\u3001\u5317\u56db\u4e2a\u65b9\u4f4d\u4e2d\u9009\u62e9\u4e00\u4e2a\u3002<\/p>\n<\/li>\n<li>\n<p>currentIndex&#xff1a;\u5f53\u524d\u9875\u7684\u7f16\u53f7\u3002<\/p>\n<\/li>\n<li>\n<p>currentTabText&#xff1a;\u5f53\u524d\u9875\u7684\u6807\u9898\u3002<\/p>\n<\/li>\n<li>\n<p>currentTabName&#xff1a;\u5f53\u524d\u9875\u7684\u5bf9\u8c61\u540d\u79f0\u3002<\/p>\n<\/li>\n<li>\n<p>currentTabIcon&#xff1a;\u53ef\u4ee5\u4e3a\u5f53\u524d\u9875\u8bbe\u7f6e\u4e00\u4e2a\u56fe\u6807&#xff0c;\u663e\u793a\u5728\u6587\u5b57\u6807\u9898\u7684\u5de6\u4fa7\u3002<\/p>\n<\/li>\n<\/ul>\n<h5>4&#xff0e;\u4f7f\u7528QSplitter\u8bbe\u8ba1\u5206\u5272\u754c\u9762<\/h5>\n<p>\u5177\u6709\u5206\u5272\u6548\u679c\u7684\u5178\u578b\u754c\u9762\u662fWindows\u7684\u8d44\u6e90\u7ba1\u7406\u5668&#xff0c;QSplitter\u7528\u4e8e\u8bbe\u8ba1\u5177\u6709\u5206\u5272\u6548\u679c\u7684\u754c\u9762&#xff0c;\u53ef\u4ee5\u5de6\u53f3\u6216\u4e0a\u4e0b\u5206\u5272\u3002<\/p>\n<p>\u672c\u5b9e\u4f8b\u4e3b\u7a97\u53e3\u4e24\u4e2a\u4e3b\u8981\u7684\u7ec4\u4ef6\u662ftoolBox\u548ctabWidget&#xff0c;\u5e0c\u671b\u8fd9\u4e24\u4e2a\u7ec4\u4ef6\u8bbe\u8ba1\u4e3a\u5de6\u53f3\u5206\u5272\u7684\u6548\u679c\u3002\u540c\u65f6\u9009\u62e9\u8fd9\u4e24\u4e2a\u7ec4\u4ef6&#xff0c;\u5355\u51fb\u4e3b\u7a97\u53e3\u5de5\u5177\u680f\u4e0a\u7684\u201cLay Out Horizontally in Splitter\u201d\u6309\u94ae&#xff0c;\u5c31\u53ef\u4ee5\u4e3a\u8fd9\u4e24\u4e2a\u7ec4\u4ef6\u521b\u5efa\u4e00\u4e2a\u6c34\u5e73\u5206\u5272\u7684\u5e03\u5c40\u7ec4\u4ef6splitter\u3002\u5728\u4e3b\u7a97\u53e3\u6784\u9020\u51fd\u6570\u91cc\u4f7f\u7528\u4e0b\u9762\u4e00\u884c\u8bed\u53e5\u5c31\u53ef\u4ee5\u4f7fsplitter\u586b\u5145\u6ee1\u6574\u4e2a\u5de5\u4f5c\u533a\u3002<\/p>\n<p>setCentralWidget(ui-&gt;splitter);<\/p>\n<p>\u5728\u4f7f\u7528\u5206\u5272\u6761\u8c03\u6574\u5927\u5c0f\u65f6&#xff0c;\u5982\u679c\u4e0d\u5e0c\u671bToolBox\u7684\u5bbd\u5ea6\u53d8\u5f97\u592a\u5c0f\u800c\u5f71\u54cd\u6309\u94ae\u7684\u663e\u793a&#xff0c;\u53ef\u4ee5\u8bbe\u7f6etoolBox\u7684minimumSize.Width\u5c5e\u6027&#xff0c;\u8bbe\u7f6e\u4e00\u4e2a\u6700\u5c0f\u5bbd\u5ea6\u3002<\/p>\n<h5>5&#xff0e;QListWidget\u7684\u8bbe\u7f6e<\/h5>\n<p>\u5728TabWidget\u7ec4\u4ef6\u7684\u7b2c\u4e00\u4e2a\u9875\u9762\u4e0a\u653e\u7f6e\u4e00\u4e2aQListWidget\u7ec4\u4ef6&#xff0c;\u4ee5\u53ca\u5176\u4ed6\u51e0\u4e2a\u6309\u94ae\u548c\u7f16\u8f91\u6846&#xff0c;\u7ec4\u6210\u5982\u539f\u4e66\u7684\u56fe4-9\u6240\u793a\u7684\u754c\u9762\u3002QListWidget\u662f\u5b58\u50a8\u591a\u4e2a\u9879\u7684\u5217\u8868\u7ec4\u4ef6&#xff0c;\u6bcf\u4e2a\u9879\u662f\u4e00\u4e2aQListWidgetItem\u7c7b\u578b\u7684\u5bf9\u8c61\u3002<\/p>\n<p>\u53cc\u51fbListWidget\u7ec4\u4ef6&#xff0c;\u53ef\u4ee5\u6253\u5f00\u5176\u5217\u8868\u9879\u7f16\u8f91\u5668&#xff0c;\u5982\u539f\u4e66\u7684\u56fe4-10\u6240\u793a\u3002\u5728\u8fd9\u4e2a\u7f16\u8f91\u5668\u91cc\u53ef\u4ee5\u589e\u52a0\u3001\u5220\u9664\u3001\u4e0a\u79fb\u3001\u4e0b\u79fb\u5217\u8868\u9879&#xff0c;\u53ef\u4ee5\u8bbe\u7f6e\u6bcf\u4e2a\u9879\u7684\u5c5e\u6027&#xff0c;\u5305\u62ec\u6587\u5b57\u5185\u5bb9\u3001\u5b57\u4f53\u3001\u6587\u5b57\u5bf9\u9f50\u65b9\u5f0f\u3001\u80cc\u666f\u8272\u3001\u524d\u666f\u8272\u7b49\u3002<\/p>\n<p>\u6bd4\u8f83\u91cd\u8981\u7684\u662f\u5176flags\u5c5e\u6027&#xff08;\u5982\u56fe4-10\u6240\u793a&#xff09;&#xff0c;\u7528\u4e8e\u8bbe\u7f6e\u9879\u7684\u4e00\u4e9b\u6807\u8bb0&#xff0c;\u8fd9\u4e9b\u6807\u8bb0\u662f\u679a\u4e3e\u7c7b\u578bQt::ItemFlag\u7684\u5177\u4f53\u503c&#xff0c;\u5305\u62ec\u4ee5\u4e0b\u51e0\u79cd\u3002<\/p>\n<ul>\n<li>\n<p>Selectable&#xff1a;\u9879\u662f\u5426\u53ef\u88ab\u9009\u62e9&#xff0c;\u5bf9\u5e94\u679a\u4e3e\u503cQt::ItemIsSelectable\u3002<\/p>\n<\/li>\n<li>\n<p>Editable&#xff1a;\u9879\u662f\u5426\u53ef\u88ab\u7f16\u8f91&#xff0c;\u5bf9\u5e94\u679a\u4e3e\u503cQt::ItemIsEditable\u3002<\/p>\n<\/li>\n<li>\n<p>DragEnabled&#xff1a;\u9879\u662f\u5426\u53ef\u4ee5\u88ab\u62d6\u52a8&#xff0c;\u5bf9\u5e94\u679a\u4e3e\u503cQt::ItemIsDragEnabled\u3002<\/p>\n<\/li>\n<li>\n<p>DropEnabled&#xff1a;\u9879\u662f\u5426\u53ef\u4ee5\u63a5\u6536\u62d6\u653e\u7684\u9879&#xff0c;\u5bf9\u5e94\u679a\u4e3e\u503cQt::ItemIsDropEnabled\u3002<\/p>\n<\/li>\n<li>\n<p>UserCheckable&#xff1a;\u9879\u662f\u5426\u53ef\u4ee5\u88ab\u590d\u9009&#xff0c;\u82e5\u4e3atrue&#xff0c;\u9879\u524d\u9762\u51fa\u73b0\u4e00\u4e2aCheckBox&#xff0c;\u5bf9\u5e94\u679a\u4e3e\u503cQt::ItemIsUserCheckable\u3002<\/p>\n<\/li>\n<li>\n<p>Enabled&#xff1a;\u9879\u662f\u5426\u88ab\u4f7f\u80fd&#xff0c;\u5bf9\u5e94\u679a\u4e3e\u503cQt::ItemIsEnabled\u3002<\/p>\n<\/li>\n<li>\n<p>Tristate&#xff1a;\u662f\u5426\u5141\u8bb8Check\u7684\u7b2c\u4e09\u79cd\u72b6\u6001&#xff0c;\u82e5\u4e3afalse&#xff0c;\u5219\u53ea\u6709checked\u548cunChecked\u4e24\u79cd\u72b6\u6001&#xff0c;\u5bf9\u5e94\u679a\u4e3e\u503cQt::ItemIsAutoTristate\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u5728\u4ee3\u7801\u4e2d\u8bbe\u7f6e\u9879\u7684flags\u5c5e\u6027\u65f6&#xff0c;\u4f7f\u7528\u51fd\u6570setFlags()&#xff0c;\u4f8b\u5982&#xff1a;<\/p>\n<p>aItem-&gt;setFlags(Qt::ItemIsSelectable |Qt::ItemIsUserCheckable |Qt::ItemIsEnabled);<\/p>\n<p>QListWidget\u7684\u5217\u8868\u9879\u4e00\u822c\u662f\u5728\u7a0b\u5e8f\u91cc\u52a8\u6001\u521b\u5efa&#xff0c;\u540e\u9762\u4f1a\u6f14\u793a\u5982\u4f55\u7528\u7a0b\u5e8f\u5b8c\u6210\u6dfb\u52a0\u3001\u5220\u9664\u5217\u8868\u9879\u7b49\u64cd\u4f5c\u3002<\/p>\n<h5>6&#xff0e;\u521b\u5efaAction<\/h5>\n<p>\u57282.4\u8282\u5df2\u7ecf\u4ecb\u7ecd\u4e86\u521b\u5efaAction&#xff0c;\u5b66\u4e60\u7528Action\u8bbe\u8ba1\u4e3b\u83dc\u5355\u548c\u4e3b\u5de5\u5177\u680f\u7684\u65b9\u6cd5\u3002\u672c\u5b9e\u4f8b\u4e5f\u91c7\u7528Action\u8bbe\u8ba1\u5de5\u5177\u680f&#xff0c;\u5e76\u4e14\u5c06Action\u7528\u4e8eQToolButton\u6309\u94ae\u3002\u521b\u5efa\u7684Action\u5217\u8868\u5982\u539f\u4e66\u7684\u56fe4-11\u6240\u793a\u3002\u5229\u7528\u8fd9\u4e9bAction\u521b\u5efa\u4e3b\u5de5\u5177\u680f&#xff0c;\u8bbe\u8ba1\u65f6\u5b8c\u6210\u7684\u4e3b\u5de5\u5177\u680f\u5982\u539f\u4e66\u7684\u56fe4-9\u6240\u793a\u3002<\/p>\n<p>actSelPopMenu\u7528\u4e8e\u201c\u9879\u9009\u62e9\u201d\u7684ToolButton\u6309\u94ae&#xff0c;\u4e5f\u5c31\u662f\u7a97\u53e3\u4e0a\u5177\u6709\u4e0b\u62c9\u83dc\u5355\u7684\u4e24\u4e2a\u6309\u94ae\u3002\u5c06actSelPopMenu\u7684\u529f\u80fd\u8bbe\u7f6e\u4e3a\u4e0eactSelInvs\u5b8c\u5168\u76f8\u540c&#xff0c;\u5728\u201cSignals &amp;Slots Editor\u201d\u91cc\u8bbe\u7f6e\u8fd9\u4e24\u4e2aAction\u5173\u8054&#xff08;\u5982\u539f\u4e66\u7684\u56fe4-12\u6240\u793a&#xff09;&#xff0c;\u8fd9\u6837&#xff0c;\u6267\u884cactSelPopMenu\u5c31\u662f\u6267\u884cactSelInvs\u3002<\/p>\n<h4>4.6.3\u3000QListWidget\u7684\u64cd\u4f5c<\/h4>\n<h5>1&#xff0e;\u521d\u59cb\u5316\u5217\u8868<\/h5>\n<p>actListIni\u5b9e\u73b0listWidget\u7684\u5217\u8868\u9879\u521d\u59cb\u5316&#xff0c;\u5176trigger()\u4fe1\u53f7\u69fd\u51fd\u6570\u4ee3\u7801\u5982\u4e0b&#xff1a;<\/p>\n<p>void MainWindow::on_actListIni_triggered()<br \/>\n{ \/\/\u521d\u59cb\u5316\u5217\u8868<br \/>\n   QListWidgetItem *aItem; \/\/\u6bcf\u4e00\u884c\u662f\u4e00\u4e2aQListWidgetItem<br \/>\n   QIcon aIcon;<br \/>\n   aIcon.addFile(&#034;:\/images\/icons\/check2.ico&#034;);<br \/>\n   bool chk&#061;ui-&gt;chkBoxListEditable-&gt;isChecked();\/\/\u662f\u5426\u53ef\u7f16\u8f91<\/p>\n<p>   ui-&gt;listWidget-&gt;clear();<br \/>\n   for (int i&#061;0; i&lt;10; i&#043;&#043;)<br \/>\n   {<br \/>\n      QString str&#061;QString::asprintf(&#034;Item %d&#034;,i);<br \/>\n      aItem&#061;new QListWidgetItem();<br \/>\n      aItem-&gt;setText(str);   \/\/\u8bbe\u7f6e\u6587\u5b57\u6807\u7b7e<br \/>\n      aItem-&gt;setIcon(aIcon);  \/\/\u8bbe\u7f6e\u56fe\u6807<br \/>\n      aItem-&gt;setCheckState(Qt::Checked);   \/\/\u8bbe\u7f6e\u4e3a\u9009\u4e2d\u72b6\u6001<br \/>\n      if (chk) \/\/\u53ef\u7f16\u8f91, \u8bbe\u7f6eflags<br \/>\n         aItem-&gt;setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable<br \/>\n|Qt::ItemIsUserCheckable |Qt::ItemIsEnabled);<br \/>\n      else\/\/\u4e0d\u53ef\u7f16\u8f91, \u8bbe\u7f6eflags<br \/>\n         aItem-&gt;setFlags(Qt::ItemIsSelectable |Qt::ItemIsUserCheckable<br \/>\n|Qt::ItemIsEnabled);<br \/>\n      ui-&gt;listWidget-&gt;addItem(aItem); \/\/\u589e\u52a0\u4e00\u4e2a\u9879<br \/>\n   }<br \/>\n}<\/p>\n<p>\u5217\u8868\u6846\u91cc\u4e00\u884c\u662f\u4e00\u4e2a\u9879&#xff0c;\u662f\u4e00\u4e2aQListWidgetItem\u7c7b\u578b\u7684\u5bf9\u8c61&#xff0c;\u5411\u5217\u8868\u6846\u6dfb\u52a0\u4e00\u4e2a\u9879&#xff0c;\u5c31\u9700\u8981\u521b\u5efa\u4e00\u4e2aQListWidgetItem\u7c7b\u578b\u7684\u5b9e\u4f8baItem&#xff0c;\u7136\u540e\u8bbe\u7f6eaItem\u7684\u4e00\u4e9b\u5c5e\u6027&#xff0c;\u518d\u7528QListWidget::AddItem()\u51fd\u6570\u5c06\u8be5aItem\u6dfb\u52a0\u5230\u5217\u8868\u6846\u91cc\u3002<\/p>\n<p>QListWidgetItem\u6709\u8bb8\u591a\u51fd\u6570\u65b9\u6cd5&#xff0c;\u53ef\u4ee5\u8bbe\u7f6e\u9879\u7684\u5f88\u591a\u5c5e\u6027&#xff0c;\u5982\u8bbe\u7f6e\u6587\u5b57\u3001\u56fe\u6807\u3001\u9009\u4e2d\u72b6\u6001&#xff0c;\u8fd8\u53ef\u4ee5\u8bbe\u7f6eflags&#xff0c;\u5c31\u662f\u539f\u4e66\u7684\u56fe4-10\u5bf9\u8bdd\u6846\u91cc\u8bbe\u7f6e\u529f\u80fd\u7684\u4ee3\u7801\u5316\u3002<\/p>\n<h5>2&#xff0e;\u63d2\u5165\u9879<\/h5>\n<p>\u63d2\u5165\u9879\u4f7f\u7528QListWidget\u7684insertItem(int row, QListWidgetItem *item)\u51fd\u6570&#xff0c;\u5728\u67d0\u4e00\u884crow\u7684\u524d\u9762\u63d2\u5165\u4e00\u4e2aQListWidgetItem\u5bf9\u8c61item&#xff0c;\u4e5f\u9700\u8981\u5148\u521b\u5efa\u8fd9\u4e2aitem&#xff0c;\u5e76\u8bbe\u7f6e\u597d\u5176\u5c5e\u6027\u3002actListInsert\u5b9e\u73b0\u8fd9\u4e2a\u529f\u80fd&#xff0c;\u5176\u69fd\u51fd\u6570\u4ee3\u7801\u5982\u4e0b&#xff1a;<\/p>\n<p>void MainWindow::on_actListInsert_triggered()<br \/>\n{  \/\/\u63d2\u5165\u4e00\u4e2a\u9879<br \/>\n   QIcon aIcon;<br \/>\n   aIcon.addFile(&#034;:\/images\/icons\/check2.ico&#034;);<br \/>\n   bool chk&#061;ui-&gt;chkBoxListEditable-&gt;isChecked();  <\/p>\n<p>   QListWidgetItem* aItem&#061;new QListWidgetItem(&#034;New Inserted Item&#034;);<br \/>\n   aItem-&gt;setIcon(aIcon);<br \/>\n   aItem-&gt;setCheckState(Qt::Checked);<br \/>\n   if (chk)<br \/>\n      aItem-&gt;setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable<br \/>\n|Qt::ItemIsUserCheckable |Qt::ItemIsEnabled);<br \/>\n   else<br \/>\n      aItem-&gt;setFlags(Qt::ItemIsSelectable |Qt::ItemIsUserCheckable<br \/>\n|Qt::ItemIsEnabled);<br \/>\n   ui-&gt;listWidget-&gt;insertItem(ui-&gt;listWidget-&gt;currentRow(),aItem);<br \/>\n}<\/p>\n<p>\u8fd9\u91cc\u8bbe\u7f6e\u65b0\u63d2\u5165\u7684\u9879\u662f\u53ef\u9009\u62e9\u7684\u3001\u80fd\u7528\u7684\u3001\u53ef\u590d\u9009\u7684\u3002\u8fd8\u6839\u636e\u754c\u9762\u8bbe\u7f6e&#xff0c;\u786e\u5b9a\u9879\u662f\u5426\u53ef\u7f16\u8f91\u3002<\/p>\n<h5>3&#xff0e;\u5220\u9664\u5f53\u524d\u9879\u548c\u6e05\u7a7a\u5217\u8868<\/h5>\n<p>\u5220\u9664\u5f53\u524d\u9879\u7684actListDelete\u7684\u69fd\u51fd\u6570\u4ee3\u7801\u5982\u4e0b&#xff1a;<\/p>\n<p>void MainWindow::on_actListDelete_triggered()<br \/>\n{ \/\/\u5220\u9664\u5f53\u524d\u9879<br \/>\n   int row&#061;ui-&gt;listWidget-&gt;currentRow();<br \/>\n   QListWidgetItem* aItem&#061;ui-&gt;listWidget-&gt;takeItem(row);<br \/>\n   delete aItem; \/\/\u624b\u5de5\u5220\u9664\u5bf9\u8c61<br \/>\n}<\/p>\n<p>takeItem()\u51fd\u6570\u53ea\u662f\u79fb\u9664\u4e00\u4e2a\u9879&#xff0c;\u5e76\u4e0d\u5220\u9664\u9879\u5bf9\u8c61&#xff0c;\u6240\u4ee5\u8fd8\u9700\u8981\u7528delete\u4ece\u5185\u5b58\u4e2d\u5220\u9664\u5b83\u3002<\/p>\n<p>\u8981\u6e05\u7a7a\u5217\u8868\u6846\u7684\u6240\u6709\u9879&#xff0c;\u53ea\u9700\u8c03\u7528QListWidget::clear()\u51fd\u6570\u5373\u53ef\u3002<\/p>\n<h5>4&#xff0e;\u904d\u5386\u5e76\u9009\u62e9\u9879<\/h5>\n<p>\u754c\u9762\u4e0a\u6709\u201c\u5168\u9009\u201d\u201c\u5168\u4e0d\u9009\u201d\u201c\u53cd\u9009\u201d3\u4e2a\u6309\u94ae&#xff0c;\u75313\u4e2aAction\u5b9e\u73b0&#xff0c;\u7528\u4e8e\u904d\u5386\u5217\u8868\u6846\u91cc\u7684\u9879&#xff0c;\u8bbe\u7f6e\u9009\u62e9\u72b6\u6001\u3002\u7528\u4e8e\u201c\u5168\u9009\u201d\u7684actSelALL\u7684\u69fd\u51fd\u6570\u4ee3\u7801\u5982\u4e0b&#xff1a;<\/p>\n<p>void MainWindow::on_actSelALL_triggered()<br \/>\n{ \/\/\u5168\u9009<br \/>\n   int cnt&#061;ui-&gt;listWidget-&gt;count();\/\/\u4e2a\u6570<br \/>\n   for (int i&#061;0; i&lt;cnt; i&#043;&#043;)<br \/>\n   {<br \/>\n      QListWidgetItem *aItem&#061;ui-&gt;listWidget-&gt;item(i);\/\/\u83b7\u53d6\u4e00\u4e2a\u9879<br \/>\n      aItem-&gt;setCheckState(Qt::Checked);\/\/\u8bbe\u7f6e\u4e3a\u9009\u4e2d<br \/>\n   }<br \/>\n}<\/p>\n<p>\u51fd\u6570QListWidgetItem::setCheckState(Qt::CheckState state)\u8bbe\u7f6e\u5217\u8868\u9879\u7684\u590d\u9009\u72b6\u6001&#xff0c;\u679a\u4e3e\u7c7b\u578bQt::CheckState\u67093\u79cd\u53d6\u503c\u3002<\/p>\n<ul>\n<li>\n<p>Qt::Unchecked&#xff0c;\u4e0d\u88ab\u9009\u4e2d\u3002<\/p>\n<\/li>\n<li>\n<p>Qt::PartiallyChecked&#xff0c;\u90e8\u5206\u9009\u4e2d\u3002\u5728\u76ee\u5f55\u6811\u4e2d\u7684\u8282\u70b9\u53ef\u80fd\u51fa\u73b0\u8fd9\u79cd\u72b6\u6001&#xff0c;\u6bd4\u5982\u5176\u5b50\u8282\u70b9\u6ca1\u6709\u5168\u90e8\u88ab\u52fe\u9009\u65f6\u3002<\/p>\n<\/li>\n<li>\n<p>Qt::Checked&#xff0c;\u88ab\u9009\u4e2d\u3002<\/p>\n<\/li>\n<\/ul>\n<h5>5&#xff0e;QListWidget\u7684\u5e38\u7528\u4fe1\u53f7<\/h5>\n<p>QListWidget\u5728\u5f53\u524d\u9879\u5207\u6362\u65f6\u53d1\u5c04\u4e24\u4e2a\u4fe1\u53f7&#xff0c;\u53ea\u662f\u4f20\u9012\u7684\u53c2\u6570\u4e0d\u540c\u3002<\/p>\n<ul>\n<li>\n<p>currentRowChanged(int currentRow)&#xff1a;\u4f20\u9012\u5f53\u524d\u9879\u7684\u884c\u53f7\u4f5c\u4e3a\u53c2\u6570\u3002<\/p>\n<\/li>\n<li>\n<p>currentItemChanged(QListWidgetItem current, QListWidgetItem previous)&#xff1a;\u4f20\u9012\u4e24\u4e2aQList WidgetItem\u5bf9\u8c61\u4f5c\u4e3a\u53c2\u6570&#xff0c;current\u8868\u793a\u5f53\u524d\u9879&#xff0c;previous\u662f\u524d\u4e00\u9879\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u5f53\u524d\u9879\u7684\u5185\u5bb9\u53d1\u751f\u53d8\u5316\u65f6\u53d1\u5c04\u4fe1\u53f7currentTextChanged(const QString &amp;currentText)\u3002<\/p>\n<p>\u4e3alistWidget\u7684currentItemChanged()\u4fe1\u53f7\u7f16\u5199\u69fd\u51fd\u6570&#xff0c;\u4ee3\u7801\u5982\u4e0b&#xff1a;<\/p>\n<p>void MainWindow::on_listWidget_currentItemChanged(QListWidgetItem *current, QListWidgetItem *previous)<br \/>\n{ \/\/listWidget\u5f53\u524d\u9009\u4e2d\u9879\u53d1\u751f\u53d8\u5316<br \/>\n  QString str;<br \/>\n  if (current !&#061; NULL)<br \/>\n  {<br \/>\n   if (previous&#061;&#061;NULL)<br \/>\n     str&#061;&#034;\u5f53\u524d\u9879&#xff1a;&#034;&#043;current-&gt;text();<br \/>\n   else<br \/>\n     str&#061;&#034;\u524d\u4e00\u9879&#xff1a;&#034;&#043;previous-&gt;text()&#043;&#034;; \u5f53\u524d\u9879&#xff1a;&#034;&#043;current-&gt;text();<br \/>\n   ui-&gt;editCutItemText-&gt;setText(str);<br \/>\n  }<br \/>\n}<\/p>\n<p>\u54cd\u5e94\u4ee3\u7801\u91cc\u9700\u8981\u5224\u65adcurrent\u548cprevious\u6307\u9488\u662f\u5426\u4e3a\u7a7a&#xff0c;\u5426\u5219\u4f7f\u7528\u5bf9\u8c61\u65f6\u53ef\u80fd\u51fa\u73b0\u8bbf\u95ee\u9519\u8bef\u3002<\/p>\n<h4>4.6.4\u3000QToolButton\u4e0e\u4e0b\u62c9\u5f0f\u83dc\u5355<\/h4>\n<h5>1&#xff0e;QToolButton\u5173\u8054QAction<\/h5>\n<p>\u539f\u4e66\u7684\u56fe4-9\u6240\u793a\u7684\u754c\u9762\u4e0a&#xff0c;\u5728ToolBox\u91cc\u653e\u7f6e\u4e86\u51e0\u4e2aQToolButton\u6309\u94ae&#xff0c;\u5e0c\u671b\u5b83\u4eec\u5b9e\u73b0\u4e0e\u5de5\u5177\u680f\u4e0a\u7684\u6309\u94ae\u76f8\u540c\u7684\u529f\u80fd&#xff1b;\u5217\u8868\u6846\u4e0a\u65b9\u653e\u7f6e\u4e86\u51e0\u4e2aQToolButton\u6309\u94ae&#xff0c;\u5e0c\u671b\u5b83\u4eec\u5b8c\u6210\u5217\u8868\u9879\u9009\u62e9\u7684\u529f\u80fd\u3002<\/p>\n<p>\u8fd9\u4e9b\u529f\u80fd\u90fd\u5df2\u7ecf\u6709\u76f8\u5e94\u7684Actions\u6765\u5b9e\u73b0&#xff0c;\u8981\u8ba9ToolButton\u6309\u94ae\u5b9e\u73b0\u8fd9\u4e9b\u529f\u80fd&#xff0c;\u65e0\u9700\u518d\u4e3a\u5176\u7f16\u5199\u4ee3\u7801&#xff0c;\u53ea\u9700\u8bbe\u7f6e\u4e00\u4e2a\u5173\u8054\u7684QAction\u5bf9\u8c61\u5373\u53ef\u3002<\/p>\n<p>QToolButton\u6709\u4e00\u4e2a\u51fd\u6570setDefaultAction()&#xff0c;\u5176\u51fd\u6570\u539f\u578b\u4e3a&#xff1a;<\/p>\n<p>void QToolButton::setDefaultAction(QAction *action)<\/p>\n<p>\u4f7f\u7528setDefaultAction()\u51fd\u6570\u4e3a\u4e00\u4e2aQToolButton\u6309\u94ae\u8bbe\u7f6e\u4e00\u4e2aAction\u4e4b\u540e&#xff0c;\u5c06\u81ea\u52a8\u83b7\u53d6Action\u7684\u6587\u5b57\u3001\u56fe\u6807\u3001ToolTip\u7b49\u8bbe\u7f6e\u4e3a\u6309\u94ae\u7684\u76f8\u5e94\u5c5e\u6027\u3002\u6240\u4ee5&#xff0c;\u5728\u754c\u9762\u8bbe\u8ba1\u65f6\u65e0\u9700\u4e3aQToolButton\u505a\u8fc7\u591a\u7684\u8bbe\u7f6e\u3002<\/p>\n<p>\u5728\u4e3b\u7a97\u4f53\u7c7b\u91cc\u5b9a\u4e49\u4e00\u4e2a\u79c1\u6709\u51fd\u6570setActionsForButton()&#xff0c;\u7528\u6765\u4e3a\u754c\u9762\u4e0a\u7684QToolButton\u6309\u94ae\u8bbe\u7f6e\u5173\u8054\u7684Actions&#xff0c;setActionsForButton()\u5728\u4e3b\u7a97\u53e3\u7684\u6784\u9020\u51fd\u6570\u91cc\u8c03\u7528&#xff0c;\u5176\u4ee3\u7801\u5982\u4e0b&#xff1a;<\/p>\n<p>void MainWindow::setActionsForButton()<br \/>\n{\/\/\u4e3aQToolButton\u6309\u94ae\u8bbe\u7f6eAction<br \/>\n   ui-&gt;tBtnListIni-&gt;setDefaultAction(ui-&gt;actListIni);<br \/>\n   ui-&gt;tBtnListClear-&gt;setDefaultAction(ui-&gt;actListClear);<br \/>\n   ui-&gt;tBtnListInsert-&gt;setDefaultAction(ui-&gt;actListInsert);<br \/>\n   ui-&gt;tBtnListAppend-&gt;setDefaultAction(ui-&gt;actListAppend);<br \/>\n   ui-&gt;tBtnListDelete-&gt;setDefaultAction(ui-&gt;actListDelete);<\/p>\n<p>   ui-&gt;tBtnSelALL-&gt;setDefaultAction(ui-&gt;actSelALL);<br \/>\n   ui-&gt;tBtnSelNone-&gt;setDefaultAction(ui-&gt;actSelNone);<br \/>\n   ui-&gt;tBtnSelInvs-&gt;setDefaultAction(ui-&gt;actSelInvs);<br \/>\n}<\/p>\n<p>\u5728\u7a0b\u5e8f\u542f\u52a8\u540e&#xff0c;\u754c\u9762\u4e0a\u7684ToolButton\u6309\u94ae\u81ea\u52a8\u6839\u636e\u5173\u8054\u7684Actions\u8bbe\u7f6e\u5176\u6309\u94ae\u6587\u5b57\u3001\u56fe\u6807\u548cToolTip\u3002\u5355\u51fb\u67d0\u4e2aToolButton\u6309\u94ae&#xff0c;\u5c31\u662f\u6267\u884c\u4e86\u5176\u5173\u8054\u7684Action\u7684\u69fd\u51fd\u6570\u4ee3\u7801\u3002\u4f7f\u7528Actions\u96c6\u4e2d\u8bbe\u8ba1\u529f\u80fd\u4ee3\u7801&#xff0c;\u7528\u4e8e\u83dc\u5355\u3001\u5de5\u5177\u680f\u3001ToolButton\u7684\u8bbe\u8ba1&#xff0c;\u662f\u907f\u514d\u91cd\u590d\u7f16\u5199\u4ee3\u7801\u7684\u4e00\u79cd\u65b9\u5f0f\u3002<\/p>\n<h5>2&#xff0e;\u4e3aQToolButton\u6309\u94ae\u8bbe\u8ba1\u4e0b\u62c9\u83dc\u5355<\/h5>\n<p>\u8fd8\u53ef\u4ee5\u4e3aQToolButton\u6309\u94ae\u8bbe\u8ba1\u4e0b\u62c9\u83dc\u5355&#xff0c;\u5728\u539f\u4e66\u7684\u56fe4-8\u7684\u8fd0\u884c\u7a97\u53e3\u4e2d&#xff0c;\u5355\u51fb\u5de5\u5177\u680f\u4e0a\u7684\u201c\u9879\u9009\u62e9\u201d\u6309\u94ae&#xff0c;\u4f1a\u5728\u6309\u94ae\u7684\u4e0b\u65b9\u5f39\u51fa\u4e00\u4e2a\u83dc\u5355&#xff0c;\u67093\u4e2a\u83dc\u5355\u9879\u7528\u4e8e\u9879\u9009\u62e9\u3002<\/p>\n<p>\u5728\u4e3b\u7a97\u53e3\u7c7b\u91cc\u5b9a\u4e49\u4e00\u4e2a\u79c1\u6709\u51fd\u6570createSelectionPopMenu()&#xff0c;\u5e76\u5728\u7a97\u53e3\u7684\u6784\u9020\u51fd\u6570\u91cc\u8c03\u7528&#xff0c;\u5176\u4ee3\u7801\u5982\u4e0b&#xff1a;<\/p>\n<p>void MainWindow::createSelectionPopMenu()<br \/>\n{\/\/\u521b\u5efa\u4e0b\u62c9\u83dc\u5355<br \/>\n   QMenu* menuSelection&#061;new QMenu(this); \/\/\u521b\u5efa\u5f39\u51fa\u5f0f\u83dc\u5355<br \/>\n   menuSelection-&gt;addAction(ui-&gt;actSelALL);<br \/>\n   menuSelection-&gt;addAction(ui-&gt;actSelNone);<br \/>\n   menuSelection-&gt;addAction(ui-&gt;actSelInvs);<br \/>\n\/\/listWidget\u4e0a\u65b9\u7684tBtnSelectItem\u6309\u94ae<br \/>\n   ui-&gt;tBtnSelectItem-&gt;setPopupMode(QToolButton::MenuButtonPopup);<br \/>\n   ui-&gt;tBtnSelectItem-&gt;setToolButtonStyle(Qt::ToolButtonTextBesideIcon);<br \/>\n   ui-&gt;tBtnSelectItem-&gt;setDefaultAction(ui-&gt;actSelPopMenu);\/\/\u5173\u8054Action<br \/>\n   ui-&gt;tBtnSelectItem-&gt;setMenu(menuSelection); \/\/\u8bbe\u7f6e\u4e0b\u62c9\u83dc\u5355<br \/>\n\/\/\u5de5\u5177\u680f\u4e0a\u7684 \u4e0b\u62c9\u5f0f\u83dc\u5355\u6309\u94ae<br \/>\n   QToolButton  *aBtn&#061;new QToolButton(this);<br \/>\n   aBtn-&gt;setPopupMode(QToolButton::InstantPopup);<br \/>\n   aBtn-&gt;setToolButtonStyle(Qt::ToolButtonTextUnderIcon);\/\/\u6309\u94ae\u6837\u5f0f<br \/>\n   aBtn-&gt;setDefaultAction(ui-&gt;actSelPopMenu);<br \/>\n   aBtn-&gt;setMenu(menuSelection);\/\/\u8bbe\u7f6e\u4e0b\u62c9\u83dc\u5355<br \/>\n   ui-&gt;mainToolBar-&gt;addWidget(aBtn); \/\/\u5de5\u5177\u680f\u6dfb\u52a0\u6309\u94ae<br \/>\n\/\/\u5de5\u5177\u680f\u6dfb\u52a0\u5206\u9694\u6761&#xff0c;\u548c&#034;\u9000\u51fa&#034;\u6309\u94ae<br \/>\n   ui-&gt;mainToolBar-&gt;addSeparator();<br \/>\n   ui-&gt;mainToolBar-&gt;addAction(ui-&gt;actQuit);<br \/>\n}<\/p>\n<p>\u8fd9\u6bb5\u4ee3\u7801\u9996\u5148\u521b\u5efa\u4e00\u4e2aQMenu\u5bf9\u8c61menuSelection&#xff0c;\u5c063\u4e2a\u7528\u4e8e\u9009\u62e9\u5217\u8868\u9879\u7684Action\u6dfb\u52a0\u4f5c\u4e3a\u83dc\u5355\u9879\u3002<\/p>\n<p>tBtnSelectItem\u662f\u7a97\u4f53\u4e0aListWidget\u4e0a\u65b9\u5177\u6709\u4e0b\u62c9\u83dc\u5355\u7684QToolButton\u6309\u94ae\u7684\u540d\u79f0&#xff0c;\u8c03\u7528\u4e86QToolButton\u7c7b\u76844\u4e2a\u51fd\u6570\u5bf9\u5176\u8fdb\u884c\u8bbe\u7f6e\u3002<\/p>\n<ul>\n<li>\n<p>setPopupMode(QToolButton::MenuButtonPopup)&#xff0c;\u8bbe\u7f6e\u5176\u5f39\u51fa\u83dc\u5355\u7684\u6a21\u5f0f\u3002QToolButton::MenuButtonPopup\u662f\u4e00\u4e2a\u679a\u4e3e\u5e38\u91cf&#xff0c;\u8fd9\u79cd\u6a21\u5f0f\u4e0b&#xff0c;\u6309\u94ae\u53f3\u4fa7\u6709\u4e00\u4e2a\u5411\u4e0b\u7684\u5c0f\u7bad\u5934&#xff0c;\u5fc5\u987b\u5355\u51fb\u8fd9\u4e2a\u5c0f\u6309\u94ae\u624d\u4f1a\u5f39\u51fa\u4e0b\u62c9\u83dc\u5355&#xff0c;\u76f4\u63a5\u5355\u51fb\u6309\u94ae\u4f1a\u6267\u884c\u6309\u94ae\u5173\u8054\u7684Action&#xff0c;\u800c\u4e0d\u4f1a\u5f39\u51fa\u4e0b\u62c9\u83dc\u5355\u3002<\/p>\n<\/li>\n<li>\n<p>setToolButtonStyle(Qt::ToolButtonTextBesideIcon)&#xff0c;\u8bbe\u7f6e\u6309\u94ae\u6837\u5f0f&#xff0c;\u6309\u94ae\u6807\u9898\u6587\u5b57\u5728\u56fe\u6807\u53f3\u4fa7\u663e\u793a\u3002<\/p>\n<\/li>\n<li>\n<p>setDefaultAction(ui-&gt;actSelPopMenu)&#xff0c;\u8bbe\u7f6e\u6309\u94ae\u7684\u5173\u8054Action&#xff0c;actSelPopMenu\u4e0eactSelInvs\u6709\u4fe1\u53f7\u4e0e\u69fd\u7684\u5173\u8054&#xff0c;\u6240\u4ee5&#xff0c;\u76f4\u63a5\u5355\u51fb\u6309\u94ae\u4f1a\u6267\u884c\u201c\u53cd\u9009\u201d\u7684\u529f\u80fd\u3002<\/p>\n<\/li>\n<li>\n<p>setMenu(menuSelection)&#xff0c;\u4e3a\u6309\u94ae\u8bbe\u7f6e\u4e0b\u62c9\u83dc\u5355\u5bf9\u8c61\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u5de5\u5177\u680f\u4e0a\u5177\u6709\u4e0b\u62c9\u83dc\u5355\u7684\u6309\u94ae\u9700\u8981\u52a8\u6001\u521b\u5efa\u3002\u5148\u521b\u5efaQToolButton\u5bf9\u8c61aBtn&#xff0c;\u540c\u6837\u7528\u4ee5\u4e0a4\u4e2a\u51fd\u6570\u8fdb\u884c\u8bbe\u7f6e&#xff0c;\u4f46\u662f\u8bbe\u7f6e\u7684\u53c2\u6570\u7a0d\u5fae\u4e0d\u540c&#xff0c;\u7279\u522b\u662f\u8bbe\u7f6e\u5f39\u51fa\u83dc\u5355\u6a21\u5f0f\u4e3a&#xff1a;<\/p>\n<p>aBtn-&gt;setPopupMode(QToolButton::InstantPopup)<\/p>\n<p>\u8fd9\u79cd\u6a21\u5f0f\u4e0b&#xff0c;\u5de5\u5177\u6309\u94ae\u7684\u53f3\u4e0b\u89d2\u663e\u793a\u4e00\u4e2a\u5c0f\u7684\u7bad\u5934&#xff0c;\u5355\u51fb\u6309\u94ae\u76f4\u63a5\u5f39\u51fa\u4e0b\u62c9\u83dc\u5355&#xff0c;\u5373\u4f7f\u4e3a\u8fd9\u4e2a\u6309\u94ae\u8bbe\u7f6e\u4e86\u5173\u8054\u7684Action&#xff0c;\u4e5f\u4e0d\u4f1a\u6267\u884cAction\u7684\u529f\u80fd\u3002\u8fd9\u662f\u8fd9\u4e24\u4e2a\u5177\u6709\u4e0b\u62c9\u83dc\u5355\u7684QToolButton\u6309\u94ae\u7684\u533a\u522b\u3002<\/p>\n<p>setActionsForButton()\u548ccreateSelectionPopMenu()\u51fd\u6570\u5728\u7a97\u53e3\u7684\u6784\u9020\u51fd\u6570\u91cc\u8c03\u7528&#xff0c;\u6784\u9020\u51fd\u6570\u7684\u5b8c\u6574\u4ee3\u7801\u5982\u4e0b&#xff1a;<\/p>\n<p>MainWindow::MainWindow(QWidget *parent) :  QMainWindow(parent),<br \/>\n   ui(new Ui::MainWindow)<br \/>\n{<br \/>\n   ui-&gt;setupUi(this);<br \/>\n   setCentralWidget(ui-&gt;splitter);<br \/>\n   setActionsForButton();<br \/>\n   createSelectionPopMenu();<br \/>\n}<\/p>\n<h4>4.6.5\u3000\u521b\u5efa\u53f3\u952e\u5feb\u6377\u83dc\u5355<\/h4>\n<p>\u6bcf\u4e2a\u4eceQWidget\u7ee7\u627f\u7684\u7c7b\u90fd\u6709\u4fe1\u53f7customContextMenuRequested()&#xff0c;\u8fd9\u4e2a\u4fe1\u53f7\u5728\u9f20\u6807\u53f3\u51fb\u65f6\u53d1\u5c04&#xff0c;\u4e3a\u6b64\u4fe1\u53f7\u7f16\u5199\u69fd\u51fd\u6570&#xff0c;\u53ef\u4ee5\u521b\u5efa\u548c\u8fd0\u884c\u53f3\u952e\u5feb\u6377\u83dc\u5355\u3002<\/p>\n<p>\u672c\u5b9e\u4f8b\u4e3alistWidget\u7ec4\u4ef6\u7684customContextMenuRequested()\u4fe1\u53f7\u521b\u5efa\u69fd\u51fd\u6570&#xff0c;\u5b9e\u73b0\u5feb\u6377\u83dc\u5355\u7684\u521b\u5efa\u4e0e\u663e\u793a&#xff0c;\u4ee3\u7801\u5982\u4e0b&#xff1a;<\/p>\n<p>void MainWindow::on_listWidget_customContextMenuRequested(const QPoint &amp;pos)<br \/>\n{<br \/>\n   Q_UNUSED(pos);<br \/>\n   QMenu* menuList&#061;new QMenu(this); \/\/\u521b\u5efa\u83dc\u5355<br \/>\n  \/\/\u6dfb\u52a0Actions\u521b\u5efa\u83dc\u5355\u9879<br \/>\n   menuList-&gt;addAction(ui-&gt;actListIni);<br \/>\n   menuList-&gt;addAction(ui-&gt;actListClear);<br \/>\n   menuList-&gt;addAction(ui-&gt;actListInsert);<br \/>\n   menuList-&gt;addAction(ui-&gt;actListAppend);<br \/>\n   menuList-&gt;addAction(ui-&gt;actListDelete);<br \/>\n   menuList-&gt;addSeparator();<br \/>\n   menuList-&gt;addAction(ui-&gt;actSelALL);<br \/>\n   menuList-&gt;addAction(ui-&gt;actSelNone);<br \/>\n   menuList-&gt;addAction(ui-&gt;actSelInvs);<br \/>\n   menuList-&gt;exec(QCursor::pos()); \/\/\u5728\u9f20\u6807\u5149\u6807\u4f4d\u7f6e\u663e\u793a\u53f3\u952e\u5feb\u6377\u83dc\u5355<br \/>\n   delete menuList;<br \/>\n}<\/p>\n<p>\u5728\u8fd9\u6bb5\u4ee3\u7801\u91cc&#xff0c;\u9996\u5148\u521b\u5efa\u4e00\u4e2aQMenu\u7c7b\u578b\u7684\u5bf9\u8c61menuList&#xff0c;\u7136\u540e\u5229\u7528QMenu\u7684addAction()\u65b9\u6cd5\u6dfb\u52a0\u5df2\u7ecf\u8bbe\u8ba1\u7684Actions\u4f5c\u4e3a\u83dc\u5355\u9879\u3002<\/p>\n<p>\u521b\u5efa\u5b8c\u83dc\u5355\u540e&#xff0c;\u4f7f\u7528QMenu::exec()\u51fd\u6570\u663e\u793a\u5feb\u6377\u83dc\u5355\u3002<\/p>\n<p>menuList-&gt;exec(QCursor::pos());<\/p>\n<p>\u8fd9\u6837\u4f1a\u5728\u9f20\u6807\u5f53\u524d\u4f4d\u7f6e\u663e\u793a\u5f39\u51fa\u5f0f\u83dc\u5355&#xff0c;\u9759\u6001\u51fd\u6570QCursor::pos()\u83b7\u5f97\u9f20\u6807\u5149\u6807\u5f53\u524d\u4f4d\u7f6e\u3002\u5feb\u6377\u83dc\u5355\u7684\u8fd0\u884c\u6548\u679c\u5982\u539f\u4e66\u7684\u56fe4-13\u6240\u793a\u3002<\/p>\n<h3>4.7\u3000QTreeWidget\u548cQDockWidget<\/h3>\n<h4>4.7.1\u3000\u5b9e\u4f8b\u529f\u80fd\u6982\u8ff0<\/h4>\n<p>\u672c\u8282\u4ecb\u7ecdQTreeWidget\u3001QDockWidget\u7684\u4f7f\u7528&#xff0c;\u4ee5\u53ca\u7528QLabel\u663e\u793a\u56fe\u7247\u7684\u65b9\u6cd5\u3002\u5b9e\u4f8bsamp4_8\u4ee5QTreeWidget\u4e3a\u4e3b\u8981\u7ec4\u4ef6&#xff0c;\u521b\u5efa\u4e00\u4e2a\u7167\u7247\u7ba1\u7406\u5668&#xff0c;\u5b9e\u4f8b\u8fd0\u884c\u65f6\u7684\u754c\u9762\u5982\u539f\u4e66\u7684\u56fe4-14\u6240\u793a\u3002<\/p>\n<p>\u8fd9\u4e2a\u5b9e\u4f8b\u4e3b\u8981\u6f14\u793a\u5982\u4e0b\u51e0\u4e2a\u7ec4\u4ef6\u7684\u4f7f\u7528\u65b9\u6cd5\u3002<\/p>\n<ul>\n<li>QTreeWidget\u76ee\u5f55\u6811\u7ec4\u4ef6<\/li>\n<\/ul>\n<p>QTreeWidget\u7c7b\u662f\u521b\u5efa\u548c\u7ba1\u7406\u76ee\u5f55\u6811\u7ed3\u6784\u7684\u7c7b\u3002\u5b9e\u4f8b\u4f7f\u7528\u4e00\u4e2aQTreeWidget\u7ec4\u4ef6\u7ba1\u7406\u7167\u7247\u76ee\u5f55&#xff0c;\u53ef\u4ee5\u6dfb\u52a0\u3001\u5220\u9664\u8282\u70b9&#xff0c;\u6bcf\u4e2a\u8282\u70b9\u8bbe\u7f6e\u4e00\u4e2a\u81ea\u5b9a\u4e49\u7c7b\u578b&#xff0c;\u53e6\u5916&#xff0c;\u8fd8\u8bbe\u7f6e\u4e86\u4e00\u4e2a\u81ea\u5b9a\u4e49\u6570\u636e&#xff0c;\u56fe\u7247\u8282\u70b9\u5b58\u50a8\u5b8c\u6574\u6587\u4ef6\u540d&#xff0c;\u4ee5\u4fbf\u5355\u51fb\u8282\u70b9\u65f6\u663e\u793a\u8be5\u56fe\u7247\u3002<\/p>\n<ul>\n<li>QDockWidget\u505c\u9760\u533a\u57df\u7ec4\u4ef6<\/li>\n<\/ul>\n<p>QDockWidget\u662f\u53ef\u4ee5\u5728QMainWindow\u7a97\u53e3\u505c\u9760&#xff0c;\u6216\u5728\u684c\u9762\u6700\u4e0a\u5c42\u6d6e\u52a8\u7684\u754c\u9762\u7ec4\u4ef6\u3002\u672c\u5b9e\u4f8b\u5c06\u4e00\u4e2aQTreeWidget\u7ec4\u4ef6\u653e\u7f6e\u5728QDockWidget\u533a\u57df\u4e0a&#xff0c;\u8bbe\u7f6e\u5176\u53ef\u4ee5\u5728\u4e3b\u7a97\u53e3\u7684\u5de6\u6216\u53f3\u4fa7\u505c\u9760&#xff0c;\u4e5f\u53ef\u4ee5\u6d6e\u52a8\u3002<\/p>\n<ul>\n<li>QLabel\u7ec4\u4ef6\u663e\u793a\u56fe\u7247<\/li>\n<\/ul>\n<p>\u53f3\u4fa7\u662f\u4e00\u4e2aQScrollArea\u7ec4\u4ef6&#xff0c;ScrollArea\u4e0a\u9762\u653e\u7f6e\u4e00\u4e2aQLabel\u7ec4\u4ef6&#xff0c;\u901a\u8fc7\u4e3aQLabel\u8bbe\u7f6e\u4e00\u4e2aQPixmap\u663e\u793a\u56fe\u7247\u3002\u901a\u8fc7QPixmap\u64cd\u4f5c\u53ef\u8fdb\u884c\u7f29\u653e\u663e\u793a&#xff0c;\u5305\u62ec\u653e\u5927\u3001\u7f29\u5c0f\u3001\u5b9e\u9645\u5927\u5c0f\u3001\u9002\u5408\u5bbd\u5ea6\u3001\u9002\u5408\u9ad8\u5ea6\u7b49\u3002<\/p>\n<h4>4.7.2\u3000\u754c\u9762\u8bbe\u8ba1<\/h4>\n<h5>1&#xff0e;\u754c\u9762\u5e03\u5c40\u8bbe\u8ba1<\/h5>\n<p>\u5b9e\u4f8bSamp4_8\u7684\u4e3b\u7a97\u53e3\u4eceQMainWindow\u7ee7\u627f\u800c\u6765&#xff0c;\u754c\u9762\u91c7\u7528\u53ef\u89c6\u5316\u8bbe\u8ba1&#xff0c;\u7a0b\u5e8f\u529f\u80fd\u4e3b\u8981\u7528Action\u5b9e\u73b0&#xff0c;\u4e3b\u83dc\u5355\u548c\u4e3b\u5de5\u5177\u680f\u4e5f\u90fd\u7531\u5176\u5b9e\u73b0\u3002<\/p>\n<p>\u5de5\u4f5c\u533a\u5de6\u4fa7\u662f\u4e00\u4e2aQDockWidget\u7ec4\u4ef6&#xff0c;\u5728DockWidget\u4e0a\u653e\u7f6e\u4e00\u4e2aQTreeWidget\u7ec4\u4ef6&#xff0c;\u7528\u6c34\u5e73\u5e03\u5c40\u4f7ftreeWidget\u586b\u5145\u6ee1\u505c\u9760\u533a\u3002<\/p>\n<p>\u5de5\u4f5c\u533a\u53f3\u4fa7\u662f\u4e00\u4e2aQScrollArea\u7ec4\u4ef6&#xff0c;QScrollArea\u7ec4\u4ef6\u91cc\u653e\u7f6e\u4e00\u4e2aQLabel\u7ec4\u4ef6&#xff0c;\u5229\u7528QLabel\u7684pixmap\u5c5e\u6027\u663e\u793a\u56fe\u7247\u3002scrollArea\u5185\u90e8\u7684\u7ec4\u4ef6\u91c7\u7528\u6c34\u5e73\u5e03\u5c40&#xff0c;\u5f53\u56fe\u7247\u8f83\u5c0f\u65f6&#xff0c;Label\u663e\u793a\u7684\u56fe\u7247\u53ef\u4ee5\u81ea\u52a8\u5c45\u4e8escrollArea\u7684\u4e2d\u95f4&#xff1b;\u5f53Label\u663e\u793a\u7684\u56fe\u7247\u8d85\u8fc7scrollArea\u53ef\u663e\u793a\u533a\u57df\u7684\u5927\u5c0f\u540e&#xff0c;scrollArea\u4f1a\u81ea\u52a8\u663e\u793a\u6c34\u5e73\u6216\u5782\u76f4\u65b9\u5411\u7684\u5377\u6eda\u6761&#xff0c;\u7528\u4e8e\u663e\u793a\u66f4\u5927\u7684\u533a\u57df\u3002<\/p>\n<p>\u5728\u4e3b\u7a97\u53e3\u6784\u9020\u51fd\u6570\u91cc\u5c06ScrollArea\u7ec4\u4ef6\u8bbe\u7f6e\u4e3a\u4e3b\u7a97\u53e3\u5de5\u4f5c\u533a\u7684\u4e2d\u5fc3\u7ec4\u4ef6\u540e&#xff0c;DockWidget\u4e0eScrollArea\u4e4b\u95f4\u81ea\u52a8\u51fa\u73b0\u5206\u5272\u6761&#xff0c;\u53ef\u4ee5\u5206\u5272\u4e24\u4e2a\u7ec4\u4ef6\u7684\u5927\u5c0f\u3002<\/p>\n<h5>2&#xff0e;QDockWidget\u7ec4\u4ef6\u5c5e\u6027\u8bbe\u7f6e<\/h5>\n<p>\u5728UI\u8bbe\u8ba1\u5668\u91cc\u5bf9DockWidget\u7ec4\u4ef6\u7684\u4e3b\u8981\u5c5e\u6027\u8fdb\u884c\u8bbe\u7f6e&#xff0c;\u4e3b\u8981\u5c5e\u6027\u5982\u4e0b\u3002<\/p>\n<ul>\n<li>allowedAreas\u5c5e\u6027&#xff0c;\u8bbe\u7f6e\u5141\u8bb8\u505c\u9760\u533a\u57df\u3002<\/li>\n<\/ul>\n<p>\u7531\u51fd\u6570setAllowedAreas(Qt::DockWidgetAreas areas)\u8bbe\u7f6e\u5141\u8bb8\u505c\u9760\u533a&#xff0c;\u53c2\u6570areas\u662f\u679a\u4e3e\u7c7b\u578bQt::DockWidgetArea\u7684\u503c\u7684\u7ec4\u5408&#xff0c;\u53ef\u4ee5\u8bbe\u7f6e\u5728\u7a97\u53e3\u7684\u5de6\u3001\u53f3\u3001\u9876\u3001\u5e95\u505c\u9760&#xff0c;\u6216\u6240\u6709\u533a\u57df\u90fd\u53ef\u505c\u9760&#xff0c;\u6216\u4e0d\u5141\u8bb8\u505c\u9760\u3002<\/p>\n<p>\u672c\u5b9e\u4f8b\u8bbe\u7f6e\u4e3a\u5141\u8bb8\u5de6\u4fa7\u548c\u53f3\u4fa7\u505c\u9760\u3002<\/p>\n<ul>\n<li>features\u5c5e\u6027&#xff0c;\u8bbe\u7f6e\u505c\u9760\u533a\u7ec4\u4ef6\u7684\u7279\u6027\u3002<\/li>\n<\/ul>\n<p>\u7531setFeatures(DockWidgetFeatures features)\u51fd\u6570\u8bbe\u7f6e\u505c\u9760\u533a\u7ec4\u4ef6\u7684\u7279\u6027&#xff0c;\u53c2\u6570features\u662f\u679a\u4e3e\u7c7b\u578bQDockWidget::DockWidgetFeature\u7684\u503c\u7684\u7ec4\u5408&#xff0c;\u679a\u4e3e\u503c\u5982\u4e0b\u3002<\/p>\n<p>&#8211; QDockWidget::DockWidgetClosable&#xff1a;\u505c\u9760\u533a\u53ef\u5173\u95ed\u3002<br \/>\n&#8211; QDockWidget::DockWidgetMovable&#xff1a;\u505c\u9760\u533a\u53ef\u79fb\u52a8\u3002<br \/>\n&#8211; QDockWidget::DockWidgetFloatable&#xff1a;\u505c\u9760\u533a\u53ef\u6d6e\u52a8\u3002<br \/>\n&#8211; QDockWidget::DockWidgetVerticalTitleBar&#xff1a;\u5728\u505c\u9760\u533a\u5de6\u4fa7\u663e\u793a\u5782\u76f4\u6807\u9898\u680f\u3002<br \/>\n&#8211; QDockWidget::AllDockWidgetFeatures&#xff1a;\u4f7f\u7528\u4ee5\u4e0a\u6240\u6709\u7279\u5f81\u3002<br \/>\n&#8211; QDockWidget::NoDockWidgetFeatures&#xff1a;\u4e0d\u80fd\u505c\u9760\u3001\u79fb\u52a8\u548c\u5173\u95ed\u3002<\/p>\n<p>\u672c\u5b9e\u4f8b\u8bbe\u7f6e\u4e3a\u53ef\u5173\u95ed\u3001\u53ef\u505c\u9760\u3001\u53ef\u6d6e\u52a8\u3002<\/p>\n<h5>3&#xff0e;QTreeWidget\u7ec4\u4ef6\u7684\u8bbe\u7f6e<\/h5>\n<p>\u5728UI\u8bbe\u8ba1\u5668\u91cc&#xff0c;\u53cc\u51fb\u754c\u9762\u4e0a\u7684QTreeWidget\u7ec4\u4ef6&#xff0c;\u53ef\u4ee5\u6253\u5f00\u539f\u4e66\u7684\u56fe4-15\u6240\u793a\u7684\u8bbe\u8ba1\u5668&#xff0c;\u8bbe\u8ba1\u5668\u6709\u4e24\u9875&#xff0c;\u53ef\u5206\u522b\u5bf9Columns\u548cItems\u8fdb\u884c\u8bbe\u8ba1\u3002<\/p>\n<p>Columns\u9875\u7528\u4e8e\u8bbe\u8ba1\u76ee\u5f55\u6811\u7684\u5217&#xff0c;\u76ee\u5f55\u6811\u53ef\u4ee5\u6709\u591a\u4e2a\u5217\u3002\u5728\u8bbe\u8ba1\u5668\u91cc\u53ef\u4ee5\u6dfb\u52a0\u3001\u5220\u9664\u3001\u79fb\u52a8\u5217&#xff0c;\u8bbe\u7f6e\u5217\u7684\u6587\u5b57\u3001\u5b57\u4f53\u3001\u524d\u666f\u8272\u3001\u80cc\u666f\u8272\u3001\u6587\u5b57\u5bf9\u9f50\u65b9\u5f0f\u3001\u56fe\u6807\u7b49\u3002\u672c\u5b9e\u4f8b\u8bbe\u7f6e\u4e86\u4e24\u4e2a\u5217&#xff0c;\u6807\u9898\u5206\u522b\u4e3a\u201c\u8282\u70b9\u201d\u548c\u201c\u8282\u70b9\u7c7b\u578b\u201d\u3002<\/p>\n<p>Items\u9875\u9762\u7528\u4e8e\u8bbe\u8ba1\u76ee\u5f55\u6811\u7684\u8282\u70b9&#xff0c;\u53ef\u5bf9\u6bcf\u4e2a\u8282\u70b9\u8bbe\u7f6e\u5c5e\u6027&#xff0c;\u5982\u6587\u5b57\u3001\u5b57\u4f53\u3001\u56fe\u6807\u7b49&#xff0c;\u7279\u522b\u662fflags\u5c5e\u6027&#xff0c;\u53ef\u4ee5\u8bbe\u7f6e\u8282\u70b9\u662f\u5426\u53ef\u9009\u3001\u662f\u5426\u53ef\u7f16\u8f91\u3001\u662f\u5426\u6709CheckBox\u7b49&#xff0c;\u8fd8\u53ef\u4ee5\u8bbe\u7f6e\u8282\u70b9\u7684CheckState\u3002\u5728\u539f\u4e66\u7684\u56fe4-15\u4e0b\u65b9\u6709\u4e00\u7ec4\u6309\u94ae\u53ef\u4ee5\u65b0\u589e\u8282\u70b9\u3001\u65b0\u589e\u4e0b\u7ea7\u8282\u70b9\u3001\u5220\u9664\u8282\u70b9\u3001\u6539\u53d8\u8282\u70b9\u7ea7\u522b\u3001\u5e73\u7ea7\u79fb\u52a8\u8282\u70b9\u7b49\u3002<\/p>\n<p>\u4f7f\u7528\u8bbe\u8ba1\u5668\u8bbe\u8ba1\u76ee\u5f55\u6811\u7684\u5217\u548c\u8282\u70b9&#xff0c;\u9002\u7528\u4e8e\u521b\u5efa\u56fa\u5b9a\u7ed3\u6784\u7684\u76ee\u5f55\u6811&#xff0c;\u4f46\u662f\u76ee\u5f55\u6811\u4e00\u822c\u662f\u6839\u636e\u5185\u5bb9\u52a8\u6001\u521b\u5efa\u7684&#xff0c;\u9700\u8981\u8fd0\u7528\u4ee3\u7801\u5b9e\u73b0\u8282\u70b9\u7684\u521b\u5efa\u3002<\/p>\n<h5>4&#xff0e;Action\u8bbe\u8ba1<\/h5>\n<p>\u672c\u4f8b\u7684\u529f\u80fd\u4ee3\u7801\u5927\u591a\u91c7\u7528Action\u5b9e\u73b0&#xff0c;\u5728Action Editor\u91cc\u8bbe\u8ba1Action&#xff0c;\u7136\u540e\u5229\u7528Action\u8bbe\u8ba1\u4e3b\u83dc\u5355\u548c\u4e3b\u5de5\u5177\u680f\u3002\u8bbe\u8ba1\u5b8c\u6210\u7684Action\u5982\u539f\u4e66\u7684\u56fe4-16\u6240\u793a\u3002<\/p>\n<h4>4.7.3\u3000QTreeWidget\u64cd\u4f5c<\/h4>\n<h5>1&#xff0e;\u672c\u5b9e\u4f8b\u7684\u76ee\u5f55\u6811\u8282\u70b9\u64cd\u4f5c\u89c4\u5219<\/h5>\n<p>\u672c\u5b9e\u4f8b\u7684\u76ee\u5f55\u6811\u8282\u70b9\u64cd\u4f5c\u5b9a\u4e49\u5982\u4e0b\u4e00\u4e9b\u89c4\u5219\u3002<\/p>\n<ul>\n<li>\n<p>\u5c06\u76ee\u5f55\u6811\u7684\u8282\u70b9\u5206\u4e3a3\u79cd\u7c7b\u578b&#xff0c;\u9876\u5c42\u8282\u70b9\u3001\u5206\u7ec4\u8282\u70b9\u548c\u56fe\u7247\u8282\u70b9\u3002<\/p>\n<\/li>\n<li>\n<p>\u7a97\u53e3\u521b\u5efa\u65f6\u521d\u59cb\u5316\u76ee\u5f55\u6811&#xff0c;\u5b83\u53ea\u6709\u4e00\u4e2a\u9876\u5c42\u8282\u70b9&#xff0c;\u8fd9\u4e2a\u9876\u5c42\u8282\u70b9\u4e0d\u80fd\u88ab\u5220\u9664&#xff0c;\u800c\u4e14\u4e0d\u5141\u8bb8\u518d\u65b0\u5efa\u9876\u5c42\u8282\u70b9\u3002<\/p>\n<\/li>\n<li>\n<p>\u9876\u5c42\u8282\u70b9\u4e0b\u5141\u8bb8\u6dfb\u52a0\u5206\u7ec4\u8282\u70b9\u548c\u56fe\u7247\u8282\u70b9\u3002<\/p>\n<\/li>\n<li>\n<p>\u5206\u7ec4\u8282\u70b9\u4e0b\u53ef\u4ee5\u6dfb\u52a0\u5206\u7ec4\u8282\u70b9\u548c\u56fe\u7247\u8282\u70b9&#xff0c;\u5206\u7ec4\u8282\u70b9\u7684\u7ea7\u6570\u65e0\u9650\u5236\u3002<\/p>\n<\/li>\n<li>\n<p>\u56fe\u7247\u8282\u70b9\u662f\u7ec8\u7aef\u8282\u70b9&#xff0c;\u53ef\u4ee5\u5728\u56fe\u7247\u8282\u70b9\u540c\u7ea7\u518d\u6dfb\u52a0\u56fe\u7247\u8282\u70b9\u3002<\/p>\n<\/li>\n<li>\n<p>\u6bcf\u4e2a\u8282\u70b9\u521b\u5efa\u65f6\u8bbe\u7f6e\u5176\u7c7b\u578b\u4fe1\u606f&#xff0c;\u56fe\u7247\u8282\u70b9\u5b58\u50a8\u5176\u5b8c\u6574\u6587\u4ef6\u540d\u4f5c\u4e3a\u81ea\u5b9a\u4e49\u6570\u636e\u3002<\/p>\n<\/li>\n<li>\n<p>\u5355\u51fb\u4e00\u4e2a\u56fe\u7247\u6587\u4ef6\u8282\u70b9\u65f6&#xff0c;\u663e\u793a\u5176\u5173\u8054\u6587\u4ef6\u7684\u56fe\u7247\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u4e3a\u4fbf\u4e8e\u540e\u9762\u8bf4\u660e\u4ee3\u7801\u7684\u5b9e\u73b0&#xff0c;\u5c06\u4e3b\u7a97\u53e3\u7c7bMainWindow\u4e2d\u589e\u52a0\u7684\u81ea\u5b9a\u4e49\u5185\u5bb9\u5148\u5217\u51fa\u6765&#xff0c;\u4ee3\u7801\u5982\u4e0b\u3002\u8fd9\u4e9b\u679a\u4e3e\u7c7b\u578b\u3001\u53d8\u91cf\u548c\u51fd\u6570\u7684\u529f\u80fd\u5728\u540e\u9762\u518d\u5177\u4f53\u4ecb\u7ecd\u3002<\/p>\n<p>class MainWindow : public QMainWindow<br \/>\n{<br \/>\nprivate:<br \/>\n\/\/\u679a\u4e3e\u7c7b\u578btreeItemType&#xff0c;\u521b\u5efa\u8282\u70b9\u65f6\u7528\u4f5ctype\u53c2\u6570&#xff0c;\u81ea\u5b9a\u4e49\u7c7b\u578b\u5fc5\u987b\u5927\u4e8e1000<br \/>\n   enum   treeItemType{itTopItem&#061;1001, itGroupItem, itImageItem};<br \/>\n   enum   treeColNum{colItem&#061;0, colItemType&#061;1}; \/\/\u76ee\u5f55\u6811\u5217\u7684\u7f16\u53f7<\/p>\n<p>   QLabel  *LabFileName; \/\/\u7528\u4e8e\u72b6\u6001\u680f\u6587\u4ef6\u540d\u663e\u793a<br \/>\n   QPixmap curPixmap;   \/\/\u5f53\u524d\u7684\u56fe\u7247<br \/>\n   float   pixRatio;    \/\/\u5f53\u524d\u56fe\u7247\u7f29\u653e\u6bd4\u4f8b<\/p>\n<p>   void   iniTree();\/\/\u76ee\u5f55\u6811\u521d\u59cb\u5316<br \/>\n   void   addFolderItem(QTreeWidgetItem *parItem, QString dirName);\/\/\u6dfb\u52a0\u76ee\u5f55<br \/>\n   QString  getFinalFolderName(const QString &amp;fullPathName); \/\/\u63d0\u53d6\u76ee\u5f55\u540d\u79f0<br \/>\n   void   addImageItem(QTreeWidgetItem *parItem,QString aFilename);\/\/\u6dfb\u52a0\u56fe\u7247<br \/>\n   void   displayImage(QTreeWidgetItem *item); \/\/\u663e\u793a\u4e00\u4e2a\u56fe\u7247\u8282\u70b9\u7684\u56fe\u7247<br \/>\n   void   changeItemCaption(QTreeWidgetItem *item); \/\/\u904d\u5386\u6539\u53d8\u8282\u70b9\u6807\u9898<br \/>\n};<\/p>\n<h5>2&#xff0e;\u76ee\u5f55\u6811\u521d\u59cb\u5316\u6dfb\u52a0\u9876\u5c42\u8282\u70b9<\/h5>\n<p>\u4e3b\u7a97\u53e3MainWindow\u7684\u6784\u9020\u51fd\u6570\u4f1a\u8c03\u7528\u81ea\u5b9a\u4e49\u51fd\u6570iniTree()&#xff0c;\u5bf9\u76ee\u5f55\u6811\u8fdb\u884c\u521d\u59cb\u5316&#xff0c;\u7a97\u53e3\u6784\u9020\u51fd\u6570\u548ciniTree()\u4ee3\u7801\u5982\u4e0b&#xff1a;<\/p>\n<p>MainWindow::MainWindow(QWidget *parent) :   QMainWindow(parent),<br \/>\n   ui(new Ui::MainWindow)<br \/>\n{<br \/>\n   ui-&gt;setupUi(this);<br \/>\n   LabFileName&#061;new QLabel(&#034;&#034;);<br \/>\n   ui-&gt;statusBar-&gt;addWidget(LabFileName);<br \/>\n   this-&gt;setCentralWidget(ui-&gt;scrollArea);<br \/>\n   iniTree();\/\/\u521d\u59cb\u5316\u76ee\u5f55\u6811<br \/>\n}<\/p>\n<p>void MainWindow::iniTree()<br \/>\n{ \/\/\u521d\u59cb\u5316\u76ee\u5f55\u6811<br \/>\n   QString   dataStr&#061;&#034;&#034;; \/\/ Item\u7684Data \u5b58\u50a8\u7684string<br \/>\n   ui-&gt;treeFiles-&gt;clear();<br \/>\n   QIcon   icon;<br \/>\n   icon.addFile(&#034;:\/images\/icons\/15.ico&#034;);  <\/p>\n<p>   QTreeWidgetItem* item&#061;new QTreeWidgetItem(MainWindow::itTopItem);<br \/>\n   item-&gt;setIcon(MainWindow::colItem,icon); \/\/\u7b2c1\u5217\u7684\u56fe\u6807<br \/>\n   item-&gt;setText(MainWindow::colItem,&#034;\u56fe\u7247\u6587\u4ef6&#034;); \/\/\u7b2c1\u5217\u7684\u6587\u5b57<br \/>\n   item-&gt;setText(MainWindow::colItemType,&#034;type&#061;itTopItem&#034;);  \/\/\u7b2c2\u5217<br \/>\n   item-&gt;setFlags(Qt::ItemIsSelectable | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsAutoTristate);<br \/>\n   item-&gt;setCheckState(colItem,Qt::Checked);<\/p>\n<p>   item-&gt;setData(MainWindow::colItem,Qt::UserRole,QVariant(dataStr));<br \/>\n   ui-&gt;treeFiles-&gt;addTopLevelItem(item);\/\/\u6dfb\u52a0\u9876\u5c42\u8282\u70b9<br \/>\n}<\/p>\n<p>QTreeWidget\u7684\u6bcf\u4e2a\u8282\u70b9\u90fd\u662f\u4e00\u4e2aQTreeWidgetItem\u5bf9\u8c61&#xff0c;\u6dfb\u52a0\u4e00\u4e2a\u8282\u70b9\u524d\u9700\u5148\u521b\u5efa\u5b83&#xff0c;\u5e76\u505a\u597d\u76f8\u5173\u8bbe\u7f6e\u3002<\/p>\n<p>\u521b\u5efa\u8282\u70b9\u7684\u8bed\u53e5\u662f&#xff1a;<\/p>\n<p>item&#061;new QTreeWidgetItem(MainWindow::itTopItem);<\/p>\n<p>\u4f20\u9012\u4e86\u4e00\u4e2a\u679a\u4e3e\u5e38\u91cfMainWindow::itTopItem\u4f5c\u4e3a\u6784\u9020\u51fd\u6570\u7684\u53c2\u6570&#xff0c;\u8868\u793a\u8282\u70b9\u7684\u7c7b\u578b\u3002\u5728\u6784\u9020\u51fd\u6570\u91cc\u4f20\u9012\u4e00\u4e2a\u7c7b\u578b\u503c\u4e4b\u540e&#xff0c;\u5c31\u53ef\u4ee5\u7528QTreeWidgetItem::type()\u8fd4\u56de\u8fd9\u4e2a\u8282\u70b9\u7684\u7c7b\u578b\u503c\u3002<\/p>\n<p>itTopItem\u662f\u5728MainWindow\u91cc\u5b9a\u4e49\u7684\u679a\u4e3e\u7c7b\u578btreeItemType\u7684\u4e00\u4e2a\u5e38\u91cf\u503c\u3002\u679a\u4e3e\u7c7b\u578btreeItemType\u5b9a\u4e49\u4e86\u8282\u70b9\u7684\u7c7b\u578b&#xff0c;\u81ea\u5b9a\u4e49\u7684\u8282\u70b9\u7c7b\u578b\u503c\u5fc5\u987b\u5927\u4e8e1000\u3002<\/p>\n<p>QTreeWidgetItem\u7684setIcon()\u548csetText()\u90fd\u9700\u8981\u4f20\u9012\u4e00\u4e2a\u5217\u53f7\u4f5c\u4e3a\u53c2\u6570&#xff0c;\u6307\u5b9a\u5bf9\u54ea\u4e2a\u5217\u8fdb\u884c\u8bbe\u7f6e\u3002\u5217\u53f7\u53ef\u4ee5\u76f4\u63a5\u7528\u6570\u5b57&#xff0c;\u4f46\u662f\u4e3a\u4e86\u4fbf\u4e8e\u7406\u89e3\u4ee3\u7801\u548c\u7edf\u4e00\u4fee\u6539&#xff0c;\u5728MainWindow\u91cc\u5b9a\u4e49\u4e86\u679a\u4e3e\u7c7b\u578btreeColNum&#xff0c;colItem\u8868\u793a\u7b2c1\u5217&#xff0c;colItemType\u8868\u793a\u7b2c2\u5217\u3002<\/p>\n<p>setFlags()\u51fd\u6570\u8bbe\u7f6e\u8282\u70b9\u7684\u4e00\u4e9b\u5c5e\u6027\u6807\u8bb0&#xff0c;\u662fQt::ItemFlag\u679a\u4e3e\u7c7b\u578b\u5e38\u91cf\u7684\u7ec4\u5408\u3002<\/p>\n<p>setData()\u51fd\u6570\u4e3a\u8282\u70b9\u7684\u67d0\u4e00\u5217\u8bbe\u7f6e\u4e00\u4e2a\u89d2\u8272\u6570\u636e&#xff0c;setData()\u51fd\u6570\u539f\u578b\u4e3a&#xff1a;<\/p>\n<p>void QTreeWidgetItem::setData(int column, int role, const QVariant &amp;value)<\/p>\n<p>\u5176\u4e2d&#xff0c;column\u662f\u5217\u53f7&#xff0c;role\u662f\u89d2\u8272\u7684\u503c&#xff0c;value\u662f\u4e00\u4e2aQVariant\u7c7b\u578b\u7684\u6570\u3002<\/p>\n<p>\u4ee3\u7801\u4e2d\u8bbe\u7f6e\u8282\u70b9\u6570\u636e\u7684\u8bed\u53e5\u662f&#xff1a;<\/p>\n<p>item-&gt;setData(MainWindow::colItem,Qt::UserRole,QVariant(dataStr)); <\/p>\n<p>\u5b83\u4e3a\u8282\u70b9\u7684\u7b2c1\u5217&#xff0c;\u89d2\u8272Qt::UserRole&#xff0c;\u8bbe\u7f6e\u4e86\u4e00\u4e2a\u5b57\u7b26\u4e32\u6570\u636edataStr\u3002Qt::UserRole\u662f\u679a\u4e3e\u7c7b\u578bQt::ItemDataRole\u4e2d\u4e00\u4e2a\u9884\u5b9a\u4e49\u7684\u503c&#xff0c;\u5173\u4e8e\u8282\u70b9\u7684\u89d2\u8272\u548cQt::ItemDataRole\u57285.1\u8282\u8be6\u7ec6\u4ecb\u7ecd\u3002<\/p>\n<p>\u521b\u5efa\u5e76\u8bbe\u7f6e\u597d\u8282\u70b9\u540e&#xff0c;\u7528QTreeWidget::addTopLevelItem()\u51fd\u6570\u5c06\u8282\u70b9\u4f5c\u4e3a\u9876\u5c42\u8282\u70b9\u6dfb\u52a0\u5230\u76ee\u5f55\u6811\u3002<\/p>\n<h5>3&#xff0e;\u6dfb\u52a0\u76ee\u5f55\u8282\u70b9<\/h5>\n<p>actAddFolder\u662f\u7528\u4e8e\u6dfb\u52a0\u7ec4\u8282\u70b9\u7684Action&#xff0c;\u5f53\u76ee\u5f55\u6811\u4e0a\u7684\u5f53\u524d\u8282\u70b9\u7c7b\u578b\u662fitTopItem\u6216itGroupItem\u7c7b\u578b\u65f6&#xff0c;\u624d\u53ef\u4ee5\u6dfb\u52a0\u7ec4\u8282\u70b9\u3002actAddFolder\u7684triggered()\u4fe1\u53f7\u7684\u69fd\u51fd\u6570&#xff0c;\u4ee5\u53ca\u76f8\u5173\u81ea\u5b9a\u4e49\u51fd\u6570\u7684\u4ee3\u7801\u5982\u4e0b&#xff1a;<\/p>\n<p>void MainWindow::on_actAddFolder_triggered()<br \/>\n{\/\/ \u6dfb\u52a0\u7ec4\u8282\u70b9<br \/>\n  QString dir&#061;QFileDialog::getExistingDirectory();\/\/\u9009\u62e9\u76ee\u5f55<br \/>\n  if (!dir.isEmpty())<br \/>\n  {<br \/>\n     QTreeWidgetItem  *parItem&#061;ui-&gt;treeFiles-&gt;currentItem(); \/\/\u5f53\u524d\u8282\u70b9<br \/>\n     addFolderItem(parItem,dir);\/\/\u5728\u7236\u8282\u70b9\u4e0b\u9762\u6dfb\u52a0\u4e00\u4e2a\u7ec4\u8282\u70b9<br \/>\n  }<br \/>\n}<\/p>\n<p>void MainWindow::addFolderItem(QTreeWidgetItem *parItem, QString dirName)<br \/>\n{\/\/\u6dfb\u52a0\u4e00\u4e2a\u7ec4\u8282\u70b9<br \/>\n   QIcon   icon(&#034;:\/images\/icons\/open3.bmp&#034;);<br \/>\n   QString  NodeText&#061;getFinalFolderName(dirName); \/\/\u83b7\u5f97\u6700\u540e\u7684\u6587\u4ef6\u5939\u540d\u79f0<\/p>\n<p>   QTreeWidgetItem *item;<br \/>\n   item&#061;new QTreeWidgetItem(MainWindow::itGroupItem); \/\/\u8282\u70b9\u7c7b\u578bitGroupItem<br \/>\n   item-&gt;setIcon(colItem,icon);<br \/>\n   item-&gt;setText(colItem,NodeText);<br \/>\n   item-&gt;setText(colItemType,&#034;type&#061;itGroupItem&#034;);<br \/>\n   item-&gt;setFlags(Qt::ItemIsSelectable | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsAutoTristate);<br \/>\n   item-&gt;setCheckState(colItem,Qt::Checked);<br \/>\n   item-&gt;setData(colItem,Qt::UserRole,QVariant(dirName));<br \/>\n   parItem-&gt;addChild(item); \/\/\u5728\u7236\u8282\u70b9\u4e0b\u9762\u6dfb\u52a0\u5b50\u8282\u70b9<br \/>\n}<\/p>\n<p>QString MainWindow::getFinalFolderName(const QString &amp;fullPathName)<br \/>\n{\/\/\u4ece\u4e00\u4e2a\u5b8c\u6574\u76ee\u5f55\u540d\u79f0\u91cc&#xff0c;\u83b7\u5f97\u6700\u540e\u7684\u6587\u4ef6\u5939\u540d\u79f0<br \/>\n   int cnt&#061;fullPathName.length();<br \/>\n   int i&#061;fullPathName.lastIndexOf(&#034;\/&#034;);<br \/>\n   QString str&#061;fullPathName.right(cnt-i-1);<br \/>\n   return str;<br \/>\n}<\/p>\n<p>actAddFolder\u7684\u69fd\u51fd\u6570\u9996\u5148\u7528\u6587\u4ef6\u5bf9\u8bdd\u6846\u83b7\u53d6\u4e00\u4e2a\u76ee\u5f55\u540d\u79f0&#xff0c;\u518d\u83b7\u53d6\u76ee\u5f55\u6811\u7684\u5f53\u524d\u8282\u70b9&#xff0c;\u7136\u540e\u8c03\u7528\u81ea\u5b9a\u4e49\u51fd\u6570addFolderItem()\u6dfb\u52a0\u4e00\u4e2a\u7ec4\u8282\u70b9&#xff0c;\u65b0\u6dfb\u52a0\u7684\u8282\u70b9\u5c06\u4f1a\u4f5c\u4e3a\u5f53\u524d\u8282\u70b9\u7684\u5b50\u8282\u70b9\u3002<\/p>\n<p>addFolderItem()\u51fd\u6570\u6839\u636e\u4f20\u9012\u6765\u7684\u7236\u8282\u70b9parItem\u548c\u76ee\u5f55\u5168\u79f0dirName&#xff0c;\u521b\u5efa\u5e76\u6dfb\u52a0\u8282\u70b9\u3002\u9996\u5148\u7528\u81ea\u5b9a\u4e49\u51fd\u6570getFinalFolderName()\u83b7\u53d6\u76ee\u5f55\u5168\u79f0\u7684\u6700\u540e\u4e00\u7ea7\u7684\u6587\u4ef6\u5939\u540d\u79f0&#xff0c;\u8fd9\u4e2a\u6587\u4ef6\u5939\u540d\u79f0\u5c06\u4f5c\u4e3a\u65b0\u5efa\u8282\u70b9\u7684\u6807\u9898&#xff1b;\u7136\u540e\u521b\u5efa\u4e00\u4e2a\u8282\u70b9&#xff0c;\u521b\u5efa\u65f6\u8bbe\u7f6e\u5176\u8282\u70b9\u7c7b\u578b\u4e3aitGroupItem&#xff0c;\u8868\u793a\u5206\u7ec4\u8282\u70b9&#xff0c;\u518d\u8bbe\u7f6e\u5c5e\u6027\u548c\u5173\u8054\u6570\u636e&#xff0c;\u5173\u8054\u6570\u636e\u5c31\u662f\u76ee\u5f55\u7684\u5168\u8def\u5f84\u5b57\u7b26\u4e32&#xff1b;\u6700\u540e\u8c03\u7528QTreeWidgetItem:: addChild()\u51fd\u6570&#xff0c;\u5c06\u521b\u5efa\u7684\u8282\u70b9\u4f5c\u4e3a\u7236\u8282\u70b9\u7684\u4e00\u4e2a\u5b50\u8282\u70b9\u6dfb\u52a0\u5230\u76ee\u5f55\u6811\u3002<\/p>\n<h5>4&#xff0e;\u6dfb\u52a0\u56fe\u7247\u6587\u4ef6\u8282\u70b9<\/h5>\n<p>actAddFiles\u662f\u6dfb\u52a0\u56fe\u7247\u6587\u4ef6\u8282\u70b9\u7684Action&#xff0c;\u76ee\u5f55\u6811\u7684\u5f53\u524d\u8282\u70b9\u4e3a\u4efb\u4f55\u7c7b\u578b\u65f6\u8fd9\u4e2aAction\u90fd\u53ef\u7528\u3002actAddFiles\u7684\u69fd\u51fd\u6570&#xff0c;\u4ee5\u53ca\u76f8\u5173\u81ea\u5b9a\u4e49\u51fd\u6570\u7684\u4ee3\u7801\u5982\u4e0b&#xff1a;<\/p>\n<p>void MainWindow::on_actAddFiles_triggered()<br \/>\n{\/\/\u6dfb\u52a0\u56fe\u7247\u6587\u4ef6\u8282\u70b9<br \/>\nQStringList files&#061;QFileDialog::getOpenFileNames(this,<br \/>\n               &#034;\u9009\u62e9\u4e00\u4e2a\u6216\u591a\u4e2a\u6587\u4ef6&#034;,&#034;&#034;,&#034;Images(*.jpg)&#034;);<br \/>\n   if (files.isEmpty())<br \/>\n      return;<br \/>\n   QTreeWidgetItem *parItem,*item;<br \/>\n   item&#061;ui-&gt;treeFiles-&gt;currentItem();<br \/>\n   if (item-&gt;type()&#061;&#061;itImageItem)  \/\/\u5f53\u524d\u8282\u70b9\u662f\u56fe\u7247\u8282\u70b9<br \/>\n      parItem&#061;item-&gt;parent();<br \/>\n   else<br \/>\n      parItem&#061;item;<\/p>\n<p>   for (int i &#061; 0; i &lt; files.size(); &#043;&#043;i)<br \/>\n   {<br \/>\n      QString aFilename&#061;files.at(i); \/\/\u5f97\u5230\u4e00\u4e2a\u6587\u4ef6\u540d<br \/>\n      addImageItem(parItem,aFilename); \/\/\u6dfb\u52a0\u4e00\u4e2a\u56fe\u7247\u8282\u70b9<br \/>\n   }<br \/>\n}<br \/>\nvoid MainWindow::addImageItem(QTreeWidgetItem *parItem, QString aFilename)<br \/>\n{\/\/\u6dfb\u52a0\u4e00\u4e2a\u56fe\u7247\u6587\u4ef6\u8282\u70b9<br \/>\n   QIcon   icon(&#034;:\/images\/icons\/31.ico&#034;);<br \/>\n   QString NodeText&#061;getFinalFolderName(aFilename); \/\/\u83b7\u5f97\u6700\u540e\u7684\u6587\u4ef6\u540d\u79f0<br \/>\n   QTreeWidgetItem *item;<br \/>\n   item&#061;new QTreeWidgetItem(MainWindow::itImageItem); \/\/\u8282\u70b9\u7c7b\u578bitImageItem<br \/>\n   item-&gt;setIcon(colItem,icon);<br \/>\n   item-&gt;setText(colItem,NodeText);<br \/>\n   item-&gt;setText(colItemType,&#034;type&#061;itImageItem&#034;);<br \/>\n   item-&gt;setFlags(Qt::ItemIsSelectable | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsAutoTristate);<br \/>\n   item-&gt;setCheckState(colItem,Qt::Checked);<br \/>\n   item-&gt;setData(colItem,Qt::UserRole,QVariant(aFilename));\/\/\u5b8c\u6574\u6587\u4ef6\u540d\u79f0<br \/>\n   parItem-&gt;addChild(item); \/\/\u5728\u7236\u8282\u70b9\u4e0b\u9762\u6dfb\u52a0\u5b50\u8282\u70b9<br \/>\n}<\/p>\n<p>actAddFiles\u7684\u69fd\u51fd\u6570\u9996\u5148\u7528QFileDialog::getOpenFileNames()&#xff0c;\u83b7\u53d6\u56fe\u7247\u6587\u4ef6\u5217\u8868&#xff0c;\u901a\u8fc7QTreeWidget::currentItem()\u51fd\u6570\u83b7\u5f97\u76ee\u5f55\u6811\u7684\u5f53\u524d\u8282\u70b9item\u3002<\/p>\n<p>item-&gt;type()\u5c06\u8fd4\u56de\u8282\u70b9\u7684\u7c7b\u578b&#xff0c;\u4e5f\u5c31\u662f\u521b\u5efa\u8282\u70b9\u65f6\u4f20\u9012\u7ed9\u6784\u9020\u51fd\u6570\u7684\u90a3\u4e2a\u53c2\u6570\u3002\u5982\u679c\u5f53\u524d\u8282\u70b9\u7c7b\u578b\u662f\u56fe\u7247\u8282\u70b9&#xff08;itImageItem&#xff09;&#xff0c;\u5c31\u4f7f\u7528\u5f53\u524d\u8282\u70b9\u7684\u7236\u8282\u70b9&#xff0c;\u4f5c\u4e3a\u5c06\u8981\u6dfb\u52a0\u7684\u56fe\u7247\u8282\u70b9\u7684\u7236\u8282\u70b9&#xff0c;\u5426\u5219\u5c31\u7528\u5f53\u524d\u8282\u70b9\u4f5c\u4e3a\u7236\u8282\u70b9\u3002<\/p>\n<p>\u7136\u540e\u904d\u5386\u6240\u9009\u56fe\u7247\u6587\u4ef6\u5217\u8868&#xff0c;\u8c03\u7528\u81ea\u5b9a\u4e49\u51fd\u6570addImageItem()\u9010\u4e00\u6dfb\u52a0\u56fe\u7247\u8282\u70b9\u5230\u7236\u8282\u70b9\u4e0b\u3002<\/p>\n<p>addImageItem()\u6839\u636e\u56fe\u7247\u6587\u4ef6\u540d\u79f0&#xff0c;\u521b\u5efa\u4e00\u4e2a\u8282\u70b9\u5e76\u6dfb\u52a0\u5230\u7236\u8282\u70b9\u4e0b\u9762&#xff0c;\u5728\u4f7f\u7528setData()\u8bbe\u7f6e\u8282\u70b9\u6570\u636e\u65f6&#xff0c;\u5c06\u56fe\u7247\u5e26\u8def\u5f84\u7684\u6587\u4ef6\u540daFilename\u4f5c\u4e3a\u8282\u70b9\u7684\u6570\u636e&#xff0c;\u8fd9\u4e2a\u6570\u636e\u5728\u5355\u51fb\u8282\u70b9\u6253\u5f00\u56fe\u7247\u65f6\u4f1a\u7528\u5230\u3002<\/p>\n<h5>5&#xff0e;\u5f53\u524d\u8282\u70b9\u53d8\u5316\u540e\u7684\u54cd\u5e94<\/h5>\n<p>\u76ee\u5f55\u6811\u4e0a\u5f53\u524d\u8282\u70b9\u53d8\u5316\u65f6&#xff0c;\u4f1a\u53d1\u5c04currentItemChanged()\u4fe1\u53f7&#xff0c;\u4e3a\u6b64\u4fe1\u53f7\u521b\u5efa\u69fd\u51fd\u6570&#xff0c;\u5b9e\u73b0\u5f53\u524d\u8282\u70b9\u7c7b\u578b\u5224\u65ad\u3001\u51e0\u4e2aAction\u7684\u4f7f\u80fd\u63a7\u5236\u3001\u663e\u793a\u56fe\u7247\u7b49\u529f\u80fd&#xff0c;\u4ee3\u7801\u5982\u4e0b&#xff1a;<\/p>\n<p>void MainWindow::on_treeFiles_currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous)<br \/>\n{ \/\/\u5f53\u524d\u8282\u70b9\u53d8\u5316\u65f6\u7684\u5904\u7406<br \/>\n   Q_UNUSED(previous);<br \/>\n   if  (current&#061;&#061;NULL)<br \/>\n      return;<br \/>\n   int var&#061;current-&gt;type();\/\/\u8282\u70b9\u7684\u7c7b\u578b<br \/>\n   switch(var)<br \/>\n   {<br \/>\n      case  itTopItem: \/\/\u9876\u5c42\u8282\u70b9<br \/>\n        ui-&gt;actAddFolder-&gt;setEnabled(true);<br \/>\n        ui-&gt;actAddFiles-&gt;setEnabled(true);<br \/>\n        ui-&gt;actDeleteItem-&gt;setEnabled(false);  \/\/\u9876\u5c42\u8282\u70b9\u4e0d\u80fd\u5220\u9664<br \/>\n        break;<\/p>\n<p>      case  itGroupItem: \/\/\u7ec4\u8282\u70b9<br \/>\n        ui-&gt;actAddFolder-&gt;setEnabled(true);<br \/>\n        ui-&gt;actAddFiles-&gt;setEnabled(true);<br \/>\n        ui-&gt;actDeleteItem-&gt;setEnabled(true);<br \/>\n        break;<\/p>\n<p>      case  itImageItem: \/\/\u56fe\u7247\u6587\u4ef6\u8282\u70b9<br \/>\n        ui-&gt;actAddFolder-&gt;setEnabled(false); \/\/\u56fe\u7247\u8282\u70b9\u4e0b\u4e0d\u80fd\u6dfb\u52a0\u76ee\u5f55\u8282\u70b9<br \/>\n        ui-&gt;actAddFiles-&gt;setEnabled(true);<br \/>\n        ui-&gt;actDeleteItem-&gt;setEnabled(true);<br \/>\n        displayImage(current); \/\/\u663e\u793a\u56fe\u7247<br \/>\n        break;<br \/>\n   }<br \/>\n}<\/p>\n<p>current\u662f\u53d8\u5316\u540e\u7684\u5f53\u524d\u8282\u70b9&#xff0c;\u901a\u8fc7current-&gt;type()\u83b7\u5f97\u5f53\u524d\u8282\u70b9\u7684\u7c7b\u578b&#xff0c;\u6839\u636e\u8282\u70b9\u7c7b\u578b\u63a7\u5236\u754c\u9762\u4e0a3\u4e2aAction\u7684\u4f7f\u80fd\u72b6\u6001\u3002\u5982\u679c\u662f\u56fe\u7247\u6587\u4ef6\u8282\u70b9&#xff0c;\u8fd8\u8c03\u7528displayImage ()\u51fd\u6570\u663e\u793a\u8282\u70b9\u5173\u8054\u7684\u56fe\u7247\u3002<\/p>\n<p>displayImage()\u51fd\u6570\u7684\u529f\u80fd\u5b9e\u73b0\u5728\u540e\u9762\u4ecb\u7ecdQLabel\u56fe\u7247\u663e\u793a\u7684\u90e8\u5206\u4f1a\u8be6\u7ec6\u8bf4\u660e\u3002<\/p>\n<h5>6&#xff0e;\u5220\u9664\u8282\u70b9<\/h5>\n<p>\u9664\u4e86\u9876\u5c42\u8282\u70b9\u4e4b\u5916&#xff0c;\u9009\u4e2d\u4e00\u4e2a\u8282\u70b9\u540e\u4e5f\u53ef\u4ee5\u5220\u9664\u5b83\u3002actDeleteItem\u5b9e\u73b0\u8282\u70b9\u5220\u9664&#xff0c;\u5176\u4ee3\u7801\u5982\u4e0b&#xff1a;<\/p>\n<p>void MainWindow::on_actDeleteItem_triggered()<br \/>\n{\/\/\u5220\u9664\u8282\u70b9<br \/>\n   QTreeWidgetItem* item &#061;ui-&gt;treeFiles-&gt;currentItem(); \/\/\u5f53\u524d\u8282\u70b9<br \/>\n   QTreeWidgetItem* parItem&#061;item-&gt;parent(); \/\/\u7236\u8282\u70b9<br \/>\n   parItem-&gt;removeChild(item);\/\/\u79fb\u9664\u4e00\u4e2a\u5b50\u8282\u70b9&#xff0c;\u5e76\u4e0d\u4f1a\u5220\u9664<br \/>\n   delete item;<br \/>\n}<\/p>\n<p>\u4e00\u4e2a\u8282\u70b9\u4e0d\u80fd\u79fb\u9664\u81ea\u5df1&#xff0c;\u6240\u4ee5\u9700\u8981\u83b7\u53d6\u5176\u7236\u8282\u70b9&#xff0c;\u4f7f\u7528\u7236\u8282\u70b9\u7684removeChild()\u51fd\u6570\u6765\u79fb\u9664\u81ea\u5df1\u3002removeChild()\u79fb\u9664\u4e00\u4e2a\u8282\u70b9&#xff0c;\u4f46\u662f\u4e0d\u4ece\u5185\u5b58\u4e2d\u5220\u9664\u5b83&#xff0c;\u6240\u4ee5\u8fd8\u9700\u8c03\u7528delete\u3002<\/p>\n<p>\u82e5\u8981\u5220\u9664\u9876\u5c42\u8282\u70b9&#xff0c;\u5219\u4f7f\u7528QTreeWidget::takeTopLevelItem(int index)\u51fd\u6570\u3002<\/p>\n<h5>7&#xff0e;\u8282\u70b9\u7684\u904d\u5386<\/h5>\n<p>\u76ee\u5f55\u6811\u7684\u8282\u70b9\u90fd\u662fQTreeWidgetItem\u7c7b&#xff0c;\u53ef\u4ee5\u5d4c\u5957\u591a\u5c42\u3002\u6709\u65f6\u9700\u8981\u5728\u76ee\u5f55\u6811\u4e2d\u904d\u5386\u6240\u6709\u8282\u70b9&#xff0c;\u6bd4\u5982\u6309\u6761\u4ef6\u67e5\u627e\u67d0\u4e9b\u8282\u70b9\u3001\u7edf\u4e00\u4fee\u6539\u8282\u70b9\u7684\u6807\u9898\u7b49\u3002\u904d\u5386\u8282\u70b9\u9700\u8981\u7528\u5230QTreeWidgetItem\u7c7b\u7684\u4e00\u4e9b\u5173\u952e\u51fd\u6570&#xff0c;\u8fd8\u9700\u8981\u8bbe\u8ba1\u5d4c\u5957\u51fd\u6570\u3002<\/p>\n<p>actScanItems\u5b9e\u73b0\u5de5\u5177\u680f\u4e0a\u201c\u904d\u5386\u8282\u70b9\u201d\u7684\u529f\u80fd&#xff0c;\u5176\u69fd\u51fd\u6570\u53ca\u76f8\u5173\u81ea\u5b9a\u4e49\u51fd\u6570\u4ee3\u7801\u5982\u4e0b&#xff1a;<\/p>\n<p>void MainWindow::on_actScanItems_triggered()<br \/>\n{\/\/\u904d\u5386\u8282\u70b9<br \/>\n   for (int i&#061;0;i&lt;ui-&gt;treeFiles-&gt;topLevelItemCount();i&#043;&#043;)<br \/>\n   {<br \/>\n      QTreeWidgetItem *item&#061;ui-&gt;treeFiles-&gt;topLevelItem(i); \/\/\u9876\u5c42\u8282\u70b9<br \/>\n      changeItemCaption(item); \/\/\u66f4\u6539\u8282\u70b9\u6807\u9898<br \/>\n   }<br \/>\n}<br \/>\nvoid MainWindow::changeItemCaption(QTreeWidgetItem *item)<br \/>\n{ \/\/\u6539\u53d8\u8282\u70b9\u7684\u6807\u9898\u6587\u5b57<br \/>\n   QString str&#061;&#034;*&#034;&#043; item-&gt;text(colItem);  \/\/\u8282\u70b9\u6807\u9898\u524d\u52a0\u201c*\u201d<br \/>\n   item-&gt;setText(colItem,str);<br \/>\n   if (item-&gt;childCount()&gt;0)<br \/>\n   for (int i&#061;0;i&lt; item-&gt;childCount();i&#043;&#043;) \/\/\u904d\u5386\u5b50\u8282\u70b9<br \/>\n      changeItemCaption(item-&gt;child(i));  \/\/\u8c03\u7528\u81ea\u5df1&#xff0c;\u53ef\u91cd\u5165\u7684\u51fd\u6570<br \/>\n}<\/p>\n<p>QTreeWidget\u7ec4\u4ef6\u7684\u9876\u5c42\u8282\u70b9\u6ca1\u6709\u7236\u8282\u70b9&#xff0c;\u8981\u8bbf\u95ee\u6240\u6709\u9876\u5c42\u8282\u70b9&#xff0c;\u7528\u5230\u4e24\u4e2a\u51fd\u6570\u3002<\/p>\n<ul>\n<li>\n<p>int topLevelItemCount()&#xff1a;\u8fd4\u56de\u9876\u5c42\u8282\u70b9\u4e2a\u6570\u3002<\/p>\n<\/li>\n<li>\n<p>QTreeWidgetItem* topLevelItem(int index)&#xff1a;\u8fd4\u56de\u5e8f\u53f7\u4e3aindex\u7684\u9876\u5c42\u8282\u70b9\u3002<\/p>\n<\/li>\n<\/ul>\n<p>on_actScanItems_triggered()\u51fd\u6570\u7684for\u5faa\u73af\u8bbf\u95ee\u6240\u6709\u9876\u5c42\u8282\u70b9&#xff0c;\u83b7\u53d6\u4e00\u4e2a\u9876\u5c42\u8282\u70b9item\u4e4b\u540e&#xff0c;\u8c03\u7528changeItemCaption(item)\u6539\u53d8\u8fd9\u4e2a\u8282\u70b9\u53ca\u5176\u6240\u6709\u5b50\u8282\u70b9\u7684\u6807\u9898\u3002<\/p>\n<p>changeItemCaption(QTreeWidgetItem *item)\u662f\u4e00\u4e2a\u5d4c\u5957\u8c03\u7528\u51fd\u6570&#xff0c;\u5373\u5728\u8fd9\u4e2a\u51fd\u6570\u91cc\u8fd8\u4f1a\u8c03\u7528\u5b83\u81ea\u5df1\u3002\u5b83\u7684\u524d\u4e24\u884c\u66f4\u6539\u4f20\u9012\u6765\u7684\u8282\u70b9item\u7684\u6807\u9898&#xff0c;\u5373\u5728\u6807\u9898\u524d\u52a0\u661f\u53f7\u3002\u540e\u9762\u7684\u4ee3\u7801\u6839\u636eitem-&gt;childCount()\u662f\u5426\u5927\u4e8e0&#xff0c;\u5224\u65ad\u8fd9\u4e2a\u8282\u70b9\u662f\u5426\u6709\u5b50\u8282\u70b9&#xff0c;\u5982\u679c\u6709\u5b50\u8282\u70b9&#xff0c;\u5219\u5728\u540e\u9762\u7684for\u5faa\u73af\u91cc&#xff0c;\u9010\u4e00\u83b7\u53d6&#xff0c;\u5e76\u4f5c\u4e3a\u53c2\u6570\u8c03\u7528changeItemCaption()\u51fd\u6570\u3002<\/p>\n<h4>4.7.4\u3000QLabel\u548cQPixmap\u663e\u793a\u56fe\u7247<\/h4>\n<h5>1&#xff0e;\u663e\u793a\u8282\u70b9\u5173\u8054\u7684\u56fe\u7247<\/h5>\n<p>\u5728\u76ee\u5f55\u6811\u4e0a\u5355\u51fb\u4e00\u4e2a\u8282\u70b9\u540e&#xff0c;\u5982\u679c\u5176\u7c7b\u578b\u4e3a\u56fe\u7247\u8282\u70b9&#xff08;itImageItem&#xff09;&#xff0c;\u5c31\u4f1a\u8c03\u7528displayImage(QTreeWidgetItem *item)\u51fd\u6570\u663e\u793a\u8282\u70b9\u7684\u56fe\u7247&#xff0c;\u5f53\u524d\u8282\u70b9\u4f5c\u4e3a\u51fd\u6570\u7684\u4f20\u9012\u53c2\u6570\u3002displayImage()\u51fd\u6570\u7684\u4ee3\u7801\u5982\u4e0b&#xff1a;<\/p>\n<p>void MainWindow::displayImage(QTreeWidgetItem *item)<br \/>\n{\/\/\u663e\u793a\u56fe\u7247,\u8282\u70b9item\u5b58\u50a8\u4e86\u56fe\u7247\u6587\u4ef6\u540d<br \/>\n   QString filename&#061;item-&gt;data(colItem,Qt::UserRole).toString();\/\/\u6587\u4ef6\u540d<br \/>\n   LabFileName-&gt;setText(filename);<br \/>\n   curPixmap.load(filename);<br \/>\n   on_actZoomFitH_triggered(); \/\/\u81ea\u52a8\u9002\u5e94\u9ad8\u5ea6\u663e\u793a<br \/>\n}<\/p>\n<p>QTreeWidgetItem::data()\u8fd4\u56de\u8282\u70b9\u5b58\u50a8\u7684\u6570\u636e&#xff0c;\u4e5f\u5c31\u662f\u7528setData()\u8bbe\u7f6e\u7684\u6570\u636e\u3002\u524d\u9762\u5728\u6dfb\u52a0\u56fe\u7247\u8282\u70b9\u65f6&#xff0c;\u5c06\u6587\u4ef6\u540d\u7684\u5e26\u8def\u5f84\u5168\u540d\u5b58\u50a8\u4e3a\u8282\u70b9\u7684\u6570\u636e&#xff0c;\u8fd9\u91cc\u7684\u7b2c\u4e00\u884c\u8bed\u53e5\u5c31\u53ef\u4ee5\u83b7\u5f97\u8282\u70b9\u5b58\u50a8\u7684\u56fe\u7247\u6587\u4ef6\u5168\u540d\u3002<\/p>\n<p>curPixmap\u662f\u5728MainWindow \u4e2d\u5b9a\u4e49\u7684\u4e00\u4e2aQPixmap\u7c7b\u578b\u7684\u53d8\u91cf&#xff0c;\u7528\u4e8e\u64cd\u4f5c\u56fe\u7247\u3002QPixmap::load(QString &amp;fileName)\u76f4\u63a5\u5c06\u4e00\u4e2a\u56fe\u7247\u6587\u4ef6\u8f7d\u5165\u3002<\/p>\n<p>\u6700\u540e\u8c03\u7528\u51fd\u6570on_actZoomFitH_triggered()\u663e\u793a\u56fe\u7247&#xff0c;\u8fd9\u662factZoomFitH\u7684\u69fd\u51fd\u6570&#xff0c;\u4ee5\u9002\u5e94\u9ad8\u5ea6\u7684\u5f62\u5f0f\u663e\u793a\u56fe\u7247\u3002<\/p>\n<h5>2&#xff0e;\u56fe\u7247\u7f29\u653e\u4e0e\u663e\u793a<\/h5>\n<p>\u6709\u51e0\u4e2aAction\u5b9e\u73b0\u56fe\u7247\u7684\u7f29\u653e\u663e\u793a&#xff0c;\u5305\u62ec\u9002\u5408\u5bbd\u5ea6\u3001\u9002\u5408\u9ad8\u5ea6\u3001\u653e\u5927\u3001\u7f29\u5c0f\u3001\u5b9e\u9645\u5927\u5c0f&#xff0c;\u90e8\u5206\u69fd\u51fd\u6570\u4ee3\u7801\u5982\u4e0b&#xff1a;<\/p>\n<p>void MainWindow::on_actZoomFitH_triggered()<br \/>\n{\/\/\u9002\u5e94\u9ad8\u5ea6\u663e\u793a\u56fe\u7247<br \/>\n   int H&#061;ui-&gt;scrollArea-&gt;height();<br \/>\n   int realH&#061;curPixmap.height();<br \/>\n   pixRatio&#061;float(H)\/realH;  \/\/\u5f53\u524d\u663e\u793a\u6bd4\u4f8b&#xff0c;\u5fc5\u987b\u8f6c\u6362\u4e3a\u6d6e\u70b9\u6570<br \/>\n   QPixmap pix&#061;curPixmap.scaledToHeight(H-30); \/\/\u56fe\u7247\u7f29\u653e\u5230\u6307\u5b9a\u9ad8\u5ea6<br \/>\n   ui-&gt;LabPicture-&gt;setPixmap(pix);<br \/>\n}<br \/>\nvoid MainWindow::on_actZoomIn_triggered()<br \/>\n{\/\/\u653e\u5927\u663e\u793a<br \/>\n   pixRatio&#061;pixRatio*1.2;<br \/>\n   int w&#061;pixRatio*curPixmap.width();<br \/>\n   int h&#061;pixRatio*curPixmap.height();<br \/>\n   QPixmap pix&#061;curPixmap.scaled(w,h);<br \/>\n   ui-&gt;LabPicture-&gt;setPixmap(pix);<br \/>\n}<br \/>\nvoid MainWindow::on_actZoomRealSize_triggered()<br \/>\n{ \/\/\u5b9e\u9645\u5927\u5c0f\u663e\u793a<br \/>\n   pixRatio&#061;1;<br \/>\n   ui-&gt;LabPicture-&gt;setPixmap(curPixmap);<br \/>\n}<\/p>\n<p>QPixmap\u5b58\u50a8\u56fe\u7247\u6570\u636e&#xff0c;\u53ef\u4ee5\u7f29\u653e\u56fe\u7247&#xff0c;\u6709\u4ee5\u4e0b\u51e0\u4e2a\u51fd\u6570\u3002<\/p>\n<ul>\n<li>\n<p>QPixmap scaledToHeight(int height)&#xff1a;\u8fd4\u56de\u4e00\u4e2a\u7f29\u653e\u540e\u7684\u56fe\u7247\u7684\u526f\u672c&#xff0c;\u56fe\u7247\u7f29\u653e\u5230\u4e00\u4e2a\u9ad8\u5ea6height\u3002<\/p>\n<\/li>\n<li>\n<p>QPixmap scaledToWidth(int width)&#xff1a;\u8fd4\u56de\u4e00\u4e2a\u7f29\u653e\u540e\u7684\u56fe\u7247\u7684\u526f\u672c&#xff0c;\u56fe\u7247\u7f29\u653e\u5230\u4e00\u4e2a\u5bbd\u5ea6width\u3002<\/p>\n<\/li>\n<li>\n<p>QPixmap scaled(int width, int height)&#xff1a;\u8fd4\u56de\u4e00\u4e2a\u7f29\u653e\u540e\u7684\u56fe\u7247\u7684\u526f\u672c&#xff0c;\u56fe\u7247\u7f29\u653e\u5230\u5bbd\u5ea6width\u548c\u9ad8\u5ea6height&#xff0c;\u7f3a\u7701\u4e3a\u4e0d\u4fdd\u6301\u6bd4\u4f8b\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u53d8\u91cfcurPixmap\u4fdd\u5b58\u4e86\u56fe\u7247\u7684\u539f\u59cb\u526f\u672c&#xff0c;\u8981\u7f29\u653e\u53ea\u9700\u8c03\u7528curPixmap\u7684\u76f8\u5e94\u51fd\u6570&#xff0c;\u8fd4\u56de\u7f29\u653e\u540e\u7684\u56fe\u7247\u526f\u672c\u3002<\/p>\n<p>\u5728\u754c\u9762\u4e0a\u7684\u4e00\u4e2a\u6807\u7b7eLabPicture\u4e0a\u663e\u793a\u56fe\u7247&#xff0c;\u4f7f\u7528\u4e86QLabel\u7684setPixmap(const QPixmap &amp;)\u51fd\u6570\u3002<\/p>\n<h4>4.7.5\u3000QDockWidget\u7684\u64cd\u4f5c<\/h4>\n<p>\u7a0b\u5e8f\u8fd0\u884c\u65f6&#xff0c;\u4e3b\u7a97\u53e3\u4e0a\u7684DockWidget\u7ec4\u4ef6\u53ef\u4ee5\u88ab\u62d6\u52a8&#xff0c;\u5728\u4e3b\u7a97\u53e3\u7684\u5de6\u3001\u53f3\u4e24\u4fa7\u505c\u9760&#xff0c;\u6216\u5728\u684c\u9762\u4e0a\u6d6e\u52a8\u3002\u5de5\u5177\u680f\u4e0a\u201c\u7a97\u4f53\u6d6e\u52a8\u201d\u548c\u201c\u7a97\u53e3\u53ef\u89c1\u201d\u4e24\u4e2a\u6309\u94ae\u53ef\u4ee5\u7528\u4ee3\u7801\u63a7\u5236\u505c\u9760\u533a\u662f\u5426\u6d6e\u52a8\u3001\u662f\u5426\u53ef\u89c1&#xff0c;\u5176\u4ee3\u7801\u5982\u4e0b&#xff1a;<\/p>\n<p>void MainWindow::on_actDockVisible_toggled(bool arg1)<br \/>\n{\/\/ \u505c\u9760\u533a\u7684\u53ef\u89c1\u6027<br \/>\n   ui-&gt;dockWidget-&gt;setVisible(arg1);<br \/>\n}<br \/>\nvoid MainWindow::on_actDockFloat_triggered(bool checked)<br \/>\n{\/\/\u505c\u9760\u533a\u6d6e\u52a8\u6027<br \/>\n   ui-&gt;dockWidget-&gt;setFloating(checked);<br \/>\n}<\/p>\n<p>\u5355\u51fbDockWidget\u7ec4\u4ef6\u6807\u9898\u680f\u7684\u5173\u95ed\u6309\u94ae\u65f6&#xff0c;\u4f1a\u9690\u85cf\u505c\u9760\u533a\u5e76\u53d1\u5c04\u4fe1\u53f7visibilityChanged(bool)&#xff1b;\u5f53\u62d6\u52a8DockWidget\u7ec4\u4ef6&#xff0c;\u4f7f\u5176\u6d6e\u52a8\u6216\u505c\u9760\u65f6&#xff0c;\u4f1a\u53d1\u5c04\u4fe1\u53f7topLevelChanged(bool)\u3002\u4e3a\u8fd9\u4e24\u4e2a\u4fe1\u53f7\u7f16\u5199\u69fd\u51fd\u6570&#xff0c;\u53ef\u66f4\u65b0\u4e24\u4e2aActions\u7684\u72b6\u6001\u3002<\/p>\n<p>void MainWindow::on_dockWidget_visibilityChanged(bool visible)<br \/>\n{\/\/\u505c\u9760\u533a\u53ef\u89c1\u6027\u53d8\u5316<br \/>\n   ui-&gt;actDockVisible-&gt;setChecked(visible);<br \/>\n}<br \/>\nvoid MainWindow::on_dockWidget_topLevelChanged(bool topLevel)<br \/>\n{\/\/\u505c\u9760\u533a\u6d6e\u52a8\u6027\u53d8\u5316<br \/>\n   ui-&gt;actDockFloat-&gt;setChecked(topLevel);<br \/>\n}<\/p>\n<h3>4.8\u3000QTableWidget\u7684\u4f7f\u7528<\/h3>\n<h4>4.8.1\u3000QTableWidget\u6982\u8ff0<\/h4>\n<p>QTableWidget\u662fQt\u4e2d\u7684\u8868\u683c\u7ec4\u4ef6\u7c7b\u3002\u5728\u7a97\u4f53\u4e0a\u653e\u7f6e\u4e00\u4e2aQTableWidget\u7ec4\u4ef6\u540e&#xff0c;\u53ef\u4ee5\u5728Property Editor\u91cc\u5bf9\u5176\u8fdb\u884c\u5c5e\u6027\u8bbe\u7f6e&#xff0c;\u53cc\u51fb\u8fd9\u4e2a\u7ec4\u4ef6&#xff0c;\u53ef\u4ee5\u6253\u5f00\u4e00\u4e2a\u7f16\u8f91\u5668&#xff0c;\u5bf9\u5176Colum\u3001Row\u548cItem\u8fdb\u884c\u7f16\u8f91\u3002\u4e00\u4e2aQTableWidget\u7ec4\u4ef6\u7684\u754c\u9762\u57fa\u672c\u7ed3\u6784\u5982\u539f\u4e66\u7684\u56fe4-17\u6240\u793a&#xff0c;\u8fd9\u4e2a\u8868\u683c\u8bbe\u7f6e\u4e3a6\u884c5\u5217\u3002<\/p>\n<p>\u8868\u683c\u7684\u7b2c1\u884c\u79f0\u4e3a\u884c\u8868\u5934&#xff0c;\u7528\u4e8e\u8bbe\u7f6e\u6bcf\u4e00\u5217\u7684\u6807\u9898&#xff0c;\u7b2c1\u5217\u79f0\u4e3a\u5217\u8868\u5934&#xff0c;\u53ef\u4ee5\u8bbe\u7f6e\u5176\u6807\u9898&#xff0c;\u4f46\u4e00\u822c\u4f7f\u7528\u7f3a\u7701\u7684\u6807\u9898&#xff0c;\u5373\u4e3a\u884c\u53f7\u3002\u884c\u8868\u5934\u548c\u5217\u8868\u5934\u4e00\u822c\u662f\u4e0d\u53ef\u7f16\u8f91\u7684\u3002<\/p>\n<p>\u9664\u4e86\u884c\u8868\u5934\u548c\u5217\u8868\u5934\u4e4b\u5916\u7684\u8868\u683c\u533a\u57df\u662f\u5185\u5bb9\u533a&#xff0c;\u5185\u5bb9\u533a\u662f\u89c4\u5219\u7684\u7f51\u683c\u72b6&#xff0c;\u5982\u540c\u4e00\u4e2a\u4e8c\u7ef4\u6570\u7ec4&#xff0c;\u6bcf\u4e2a\u7f51\u683c\u5355\u5143\u79f0\u4e3a\u4e00\u4e2a\u5355\u5143\u683c\u3002\u6bcf\u4e2a\u5355\u5143\u683c\u6709\u4e00\u4e2a\u884c\u53f7\u3001\u5217\u53f7&#xff0c;\u539f\u4e66\u7684\u56fe4-17\u8868\u793a\u4e86\u884c\u53f7\u3001\u5217\u53f7\u7684\u53d8\u5316\u89c4\u5f8b\u3002<\/p>\n<p>\u5728QTableWidget\u8868\u683c\u4e2d&#xff0c;\u6bcf\u4e00\u4e2a\u5355\u5143\u683c\u662f\u4e00\u4e2aQTableWidgetItem\u5bf9\u8c61&#xff0c;\u53ef\u4ee5\u8bbe\u7f6e\u6587\u5b57\u5185\u5bb9\u3001\u5b57\u4f53\u3001\u524d\u666f\u8272\u3001\u80cc\u666f\u8272\u3001\u56fe\u6807&#xff0c;\u4e5f\u53ef\u4ee5\u8bbe\u7f6e\u7f16\u8f91\u548c\u663e\u793a\u6807\u8bb0\u3002\u6bcf\u4e2a\u5355\u5143\u683c\u8fd8\u53ef\u4ee5\u5b58\u50a8\u4e00\u4e2aQVariant\u6570\u636e&#xff0c;\u7528\u4e8e\u8bbe\u7f6e\u7528\u6237\u81ea\u5b9a\u4e49\u6570\u636e\u3002<\/p>\n<p>\u5b9e\u4f8bsamp4_9\u4ee5QTableWidget\u4e3a\u4e3b\u8981\u7ec4\u4ef6&#xff0c;\u6f14\u793aQTableWidget\u4e00\u4e9b\u4e3b\u8981\u64cd\u4f5c\u7684\u5b9e\u73b0\u3002\u5b9e\u4f8b\u8fd0\u884c\u65f6\u7684\u754c\u9762\u5982\u539f\u4e66\u7684\u56fe4-18\u6240\u793a&#xff0c;\u8be5\u5b9e\u4f8b\u5c06\u6f14\u793a\u4ee5\u4e0b\u529f\u80fd\u7684\u5b9e\u73b0\u65b9\u6cd5\u3002<\/p>\n<ul>\n<li>\n<p>\u8bbe\u7f6e\u8868\u683c\u7684\u5217\u6570\u548c\u884c\u6570&#xff0c;\u8bbe\u7f6e\u8868\u5934\u7684\u6587\u5b57\u3001\u683c\u5f0f\u7b49\u3002<\/p>\n<\/li>\n<li>\n<p>\u521d\u59cb\u5316\u8868\u683c\u6570\u636e&#xff0c;\u8bbe\u7f6e\u4e00\u6279\u5b9e\u4f8b\u6570\u636e\u586b\u5145\u5230\u8868\u683c\u91cc\u3002<\/p>\n<\/li>\n<li>\n<p>\u63d2\u5165\u884c\u3001\u6dfb\u52a0\u884c\u3001\u5220\u9664\u5f53\u524d\u884c\u7684\u64cd\u4f5c\u3002<\/p>\n<\/li>\n<li>\n<p>\u904d\u5386\u8868\u683c\u6240\u6709\u5355\u5143\u683c&#xff0c;\u8bfb\u53d6\u8868\u683c\u5185\u5bb9\u5230\u4e00\u4e2aQPlainTextEdit\u91cc&#xff0c;\u8868\u683c\u7684\u4e00\u884c\u6570\u636e\u4f5c\u4e3a\u4e00\u884c\u6587\u672c\u3002<\/p>\n<\/li>\n<li>\n<p>\u8868\u683c\u4e0a\u9009\u62e9\u7684\u5f53\u524d\u5355\u5143\u683c\u53d8\u5316\u65f6&#xff0c;\u5728\u72b6\u6001\u680f\u663e\u793a\u5355\u5143\u683c\u5b58\u50a8\u7684\u4fe1\u606f\u3002<\/p>\n<\/li>\n<\/ul>\n<h4>4.8.2\u3000\u754c\u9762\u8bbe\u8ba1\u4e0e\u521d\u59cb\u5316<\/h4>\n<p>Samp4_9\u7684\u4e3b\u7a97\u4f53\u4eceQMainWindow\u7ee7\u627f\u800c\u6765\u3002\u5728\u539f\u4e66\u7684\u56fe4-18\u6240\u793a\u7684\u7a97\u53e3\u4e0a&#xff0c;\u4e00\u4e2aQTableWidget\u7ec4\u4ef6\u548c\u4e00\u4e2aQPlainTextEdit\u7ec4\u4ef6\u7ec4\u6210\u4e0a\u4e0b\u5206\u5272\u5e03\u5c40splitter\u3002\u5de6\u4fa7\u7684\u6309\u94ae\u90fd\u653e\u5728\u4e00\u4e2aQGroupBox\u7ec4\u4ef6\u91cc&#xff0c;\u91c7\u7528Grid\u5e03\u5c40&#xff0c;\u7136\u540e\u5c06groupBox\u4e0esplitter\u91c7\u7528\u5de6\u53f3\u5206\u5272\u5e03\u5c40\u3002\u8fd9\u662f\u4e00\u4e2a\u5178\u578b\u7684\u4e09\u533a\u5206\u5272\u7684\u5e03\u5c40\u3002<\/p>\n<p>\u5728\u4e3b\u7a97\u53e3\u7c7bMainWindow\u91cc\u81ea\u5b9a\u4e49\u4e86\u4e00\u4e9b\u53d8\u91cf\u548c\u51fd\u6570&#xff0c;\u7528\u4e8e\u540e\u9762\u7684\u4ee3\u7801\u5b9e\u73b0&#xff0c;\u4e0b\u9762\u662f\u5728MainWindow\u7684private\u90e8\u5206\u81ea\u5b9a\u4e49\u7684\u53d8\u91cf\u548c\u51fd\u6570&#xff1a;<\/p>\n<p>private:<br \/>\n\/\/  \u81ea\u5b9a\u4e49\u5355\u5143\u683cType\u7684\u7c7b\u578b&#xff0c;\u5728\u521b\u5efa\u5355\u5143\u683c\u7684 item\u65f6\u4f7f\u7528<br \/>\n  enum   CellType{ctName&#061;1000,ctSex,ctBirth,ctNation,ctPartyM,ctScore};<br \/>\n\/\/  \u5404\u5b57\u6bb5\u5728\u8868\u683c\u4e2d\u7684\u5217\u53f7<br \/>\n  enum  FieldColNum{colName&#061;0,colSex,colBirth,<br \/>\n                   colNation,colScore,colPartyM};<br \/>\n  QLabel  *labCellIndex; \/\/\u72b6\u6001\u680f\u4e0a\u7528\u4e8e\u663e\u793a\u5355\u5143\u683c\u7684\u884c\u53f7\u3001\u5217\u53f7<br \/>\n  QLabel  *labCellType;\/\/\u72b6\u6001\u680f\u4e0a\u7528\u4e8e\u663e\u793a\u5355\u5143\u683c\u7684type<br \/>\n  QLabel  *labStudID; \/\/\u72b6\u6001\u680f\u4e0a\u7528\u4e8e\u663e\u793a\u5b66\u53f7<br \/>\n  void   createItemsARow(int rowNo,QString Name,QString Sex,QDate birth,<br \/>\n            QString Nation,bool isPM,int score); \/\/\u4e3a\u67d0\u4e00\u884c\u521b\u5efaitems<\/p>\n<p>\u679a\u4e3e\u7c7b\u578bCellType\u662f\u7528\u6765\u8868\u793a\u5355\u5143\u683c\u7c7b\u578b\u7684&#xff0c;\u5728\u521b\u5efa\u5355\u5143\u683c\u65f6\u4f7f\u7528\u3002<\/p>\n<p>\u679a\u4e3e\u7c7b\u578bFieldColNum\u7528\u679a\u4e3e\u5e38\u91cf\u8868\u793a\u5404\u5b57\u6bb5\u5728\u8868\u683c\u4e2d\u7684\u5217\u53f7\u3002<\/p>\n<p>\u5728MainWindow\u7684\u6784\u9020\u51fd\u6570\u91cc\u5bf9\u754c\u9762\u8fdb\u884c\u521d\u59cb\u5316&#xff0c;\u4ee3\u7801\u5982\u4e0b&#xff1a;<\/p>\n<p> MainWindow::MainWindow(QWidget *parent) :   QMainWindow(parent),<br \/>\n   ui(new Ui::MainWindow)<br \/>\n{<br \/>\n   ui-&gt;setupUi(this);<br \/>\n   setCentralWidget(ui-&gt;splitterMain);<br \/>\n\/\/\u72b6\u6001\u680f\u521d\u59cb\u5316\u521b\u5efa<br \/>\n   labCellIndex &#061; new QLabel(&#034;\u5f53\u524d\u5355\u5143\u683c\u5750\u6807&#xff1a;&#034;,this);<br \/>\n   labCellIndex-&gt;setMinimumWidth(250);<br \/>\n   labCellType&#061;new QLabel(&#034;\u5f53\u524d\u5355\u5143\u683c\u7c7b\u578b&#xff1a;&#034;,this);<br \/>\n   labCellType-&gt;setMinimumWidth(200);<br \/>\n   labStudID&#061;new QLabel(&#034;\u5b66\u751fID&#xff1a;&#034;,this);<br \/>\n   labStudID-&gt;setMinimumWidth(200);<br \/>\n   ui-&gt;statusBar-&gt;addWidget(labCellIndex);\/\/\u52a0\u5230\u72b6\u6001\u680f<br \/>\n   ui-&gt;statusBar-&gt;addWidget(labCellType);<br \/>\n   ui-&gt;statusBar-&gt;addWidget(labStudID);<br \/>\n}<\/p>\n<h4>4.8.3\u3000QTableWidget\u64cd\u4f5c<\/h4>\n<h5>1&#xff0e;\u8bbe\u7f6e\u8868\u5934<\/h5>\n<p>\u754c\u9762\u4e0a\u7684\u201c\u8bbe\u7f6e\u8868\u5934\u201d\u6309\u94ae\u5b9e\u73b0\u5bf9\u8868\u5934\u7684\u8bbe\u7f6e&#xff0c;\u5176clicked()\u4fe1\u53f7\u7684\u69fd\u51fd\u6570\u4ee3\u7801\u5982\u4e0b&#xff1a;<\/p>\n<p>void MainWindow::on_btnSetHeader_clicked()<br \/>\n{ \/\/\u8bbe\u7f6e\u8868\u5934<br \/>\n   QTableWidgetItem  *headerItem;<br \/>\n   QStringList  headerText;<br \/>\n   headerText&lt;&lt;&#034;\u59d3 \u540d&#034;&lt;&lt;&#034;\u6027 \u522b&#034;&lt;&lt;&#034;\u51fa\u751f\u65e5\u671f&#034;&lt;&lt;&#034;\u6c11 \u65cf&#034;&lt;&lt;&#034;\u5206\u6570&#034;&lt;&lt;&#034;\u662f\u5426\u515a\u5458&#034;;<br \/>\n\/\/   ui-&gt;tableInfo-&gt;setHorizontalHeaderLabels(headerText);<br \/>\n   ui-&gt;tableInfo-&gt;setColumnCount(headerText.count());<br \/>\n   for (int i&#061;0;i&lt;ui-&gt;tableInfo-&gt;columnCount();i&#043;&#043;)<br \/>\n   {<br \/>\n     headerItem&#061;new  QTableWidgetItem(headerText.at(i));<br \/>\n     QFont font&#061;headerItem-&gt;font();<br \/>\n     font.setBold(true);\/\/\u8bbe\u7f6e\u4e3a\u7c97\u4f53<br \/>\n     font.setPointSize(12);\/\/\u5b57\u4f53\u5927\u5c0f<br \/>\n     headerItem-&gt;setTextColor(Qt::red);\/\/\u5b57\u4f53\u989c\u8272<br \/>\n     headerItem-&gt;setFont(font);\/\/\u8bbe\u7f6e\u5b57\u4f53<br \/>\n     ui-&gt;tableInfo-&gt;setHorizontalHeaderItem(i,headerItem);<br \/>\n   }<br \/>\n}<\/p>\n<p>\u884c\u8868\u5934\u5404\u5217\u7684\u6587\u5b57\u6807\u9898\u7531\u4e00\u4e2aQStringList\u5bf9\u8c61headerText\u521d\u59cb\u5316\u5b58\u50a8&#xff0c;\u5982\u679c\u53ea\u662f\u8bbe\u7f6e\u884c\u8868\u5934\u5404\u5217\u7684\u6807\u9898&#xff0c;\u4f7f\u7528\u4e0b\u9762\u4e00\u884c\u8bed\u53e5\u5373\u53ef&#xff1a;<\/p>\n<p>ui-&gt;tableInfo-&gt;setHorizontalHeaderLabels(headerText);<\/p>\n<p>\u5982\u679c\u9700\u8981\u8fdb\u884c\u66f4\u52a0\u5177\u4f53\u7684\u683c\u5f0f\u8bbe\u7f6e&#xff0c;\u9700\u8981\u4e3a\u884c\u8868\u5934\u7684\u6bcf\u4e2a\u5355\u5143\u683c\u521b\u5efa\u4e00\u4e2aQTableWidgetItem\u7c7b\u578b\u7684\u53d8\u91cf&#xff0c;\u5e76\u8fdb\u884c\u76f8\u5e94\u8bbe\u7f6e\u3002<\/p>\n<p>\u5728\u4e00\u4e2a\u8868\u683c\u4e2d&#xff0c;\u4e0d\u7ba1\u662f\u8868\u5934\u8fd8\u662f\u5de5\u4f5c\u533a&#xff0c;\u6bcf\u4e2a\u5355\u5143\u683c\u90fd\u662f\u4e00\u4e2aQTableWidgetItem\u5bf9\u8c61\u3002QTableWidgetItem\u5bf9\u8c61\u5b58\u50a8\u4e86\u5355\u5143\u683c\u7684\u6240\u6709\u5185\u5bb9&#xff0c;\u5305\u62ec\u5b57\u6807\u9898\u3001\u683c\u5f0f\u8bbe\u7f6e&#xff0c;\u4ee5\u53ca\u5173\u8054\u7684\u6570\u636e\u3002<\/p>\n<p>\u4e0a\u9762\u7a0b\u5e8f\u4e2d\u7684for\u5faa\u73af\u904d\u5386headerText\u7684\u6bcf\u4e00\u884c&#xff0c;\u7528\u6bcf\u4e00\u884c\u7684\u6587\u5b57\u521b\u5efa\u4e00\u4e2aQTableWidgetItem\u5bf9\u8c61headerItem&#xff0c;\u7136\u540e\u8bbe\u7f6eheaderItem\u7684\u5b57\u4f53\u5927\u5c0f\u4e3a12\u3001\u7c97\u4f53\u3001\u7ea2\u8272&#xff0c;\u7136\u540e\u5c06headerItem\u8d4b\u7ed9\u8868\u5934\u7684\u67d0\u4e00\u5217&#xff1a;<\/p>\n<p>ui-&gt;tableInfo-&gt;setHorizontalHeaderItem(i,headerItem);<\/p>\n<h5>2&#xff0e;\u521d\u59cb\u5316\u8868\u683c\u6570\u636e<\/h5>\n<p>\u754c\u9762\u4e0a\u7684\u201c\u521d\u59cb\u5316\u8868\u683c\u6570\u636e\u201d\u6309\u94ae\u6839\u636e\u8868\u683c\u7684\u884c\u6570&#xff0c;\u751f\u6210\u6570\u636e\u586b\u5145\u8868\u683c&#xff0c;\u5e76\u4e3a\u6bcf\u4e2a\u5355\u5143\u683c\u751f\u6210QTableWidgetItem\u5bf9\u8c61&#xff0c;\u8bbe\u7f6e\u76f8\u5e94\u5c5e\u6027\u3002\u4e0b\u9762\u662fbtnIniData\u7684clicked()\u4fe1\u53f7\u7684\u69fd\u51fd\u6570\u4ee3\u7801&#xff1a;<\/p>\n<p>void MainWindow::on_btnIniData_clicked()<br \/>\n{ \/\/\u521d\u59cb\u5316\u8868\u683c\u5185\u5bb9<br \/>\n   QString strName,strSex;<br \/>\n   bool   isParty&#061;false;<br \/>\n   QDate   birth;<br \/>\n   birth.setDate(1980,4,7);\/\/\u521d\u59cb\u5316\u4e00\u4e2a\u65e5\u671f<br \/>\n   ui-&gt;tableInfo-&gt;clearContents();\/\/\u53ea\u6e05\u9664\u5de5\u4f5c\u533a&#xff0c;\u4e0d\u6e05\u9664\u8868\u5934<br \/>\n   int Rows&#061;ui-&gt;tableInfo-&gt;rowCount(); \/\/\u6570\u636e\u533a\u884c\u6570<br \/>\n   for (int i&#061;0;i&lt;Rows;i&#043;&#043;)<br \/>\n   {<br \/>\n      strName&#061;QString::asprintf(&#034;\u5b66\u751f%d&#034;,i);<br \/>\n      if ((i % 2)&#061;&#061;0) \/\/\u5206\u5947\u6570\u3001\u5076\u6570\u884c\u8bbe\u7f6e\u6027\u522b&#xff0c;\u53ca\u5176\u56fe\u6807<br \/>\n         strSex&#061;&#034;\u7537&#034;;<br \/>\n      else<br \/>\n         strSex&#061;&#034;\u5973&#034;;<br \/>\n      createItemsARow(i, strName, strSex, birth,&#034;\u6c49\u65cf&#034;,isParty,70);<br \/>\n      birth&#061;birth.addDays(20); \/\/\u65e5\u671f\u52a020\u5929<br \/>\n      isParty &#061;!isParty;<br \/>\n   }<br \/>\n}<\/p>\n<p>QTableWidget::clearContents()\u51fd\u6570\u6e05\u9664\u8868\u683c\u6570\u636e\u533a\u7684\u6240\u6709\u5185\u5bb9&#xff0c;\u4f46\u662f\u4e0d\u6e05\u9664\u8868\u5934\u3002<\/p>\n<p>QTableWidget::rowCount()\u51fd\u6570\u8fd4\u56de\u8868\u683c\u6570\u636e\u533a\u7684\u884c\u6570\u3002<\/p>\n<p>\u5728for\u5faa\u73af\u91cc\u4e3a\u6bcf\u4e00\u884c\u751f\u6210\u9700\u8981\u663e\u793a\u7684\u6570\u636e&#xff0c;\u7136\u540e\u8c03\u7528\u81ea\u5b9a\u4e49\u51fd\u6570createItemsARow()&#xff0c;\u4e3a\u8868\u683c\u4e00\u884c\u7684\u5404\u4e2a\u5355\u5143\u683c\u751f\u6210QTableWidgetItem\u5bf9\u8c61\u3002<\/p>\n<p>createItemsARow()\u662f\u5728\u7a97\u4f53\u7c7b\u91cc\u81ea\u5b9a\u4e49\u7684\u51fd\u6570&#xff0c;\u5176\u5b9e\u73b0\u4ee3\u7801\u5982\u4e0b&#xff1a;<\/p>\n<p>void MainWindow::createItemsARow(int rowNo,QString Name,QString Sex,QDate birth,QString Nation,bool isPM,int score)<br \/>\n{ \/\/\u4e3a\u4e00\u884c\u7684\u5355\u5143\u683c\u521b\u5efa Items<br \/>\n   QTableWidgetItem   *item;<br \/>\n   QString str;<br \/>\n   uint StudID&#061;201605000; \/\/\u5b66\u53f7\u57fa\u6570<br \/>\n\/\/\u59d3\u540d<br \/>\n   item&#061;new  QTableWidgetItem(Name,MainWindow::ctName);<br \/>\n   item-&gt;setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);<br \/>\n   StudID  &#043;&#061;rowNo; \/\/\u5b66\u53f7&#061;\u57fa\u6570&#043; \u884c\u53f7<br \/>\n   item-&gt;setData(Qt::UserRole,QVariant(StudID));  \/\/\u8bbe\u7f6estudID\u4e3adata<br \/>\n   ui-&gt;tableInfo-&gt;setItem(rowNo,MainWindow::colName,item);<br \/>\n\/\/\u6027\u522b<br \/>\n   QIcon   icon;<br \/>\n   if (Sex&#061;&#061;&#034;\u7537&#034;)<br \/>\n      icon.addFile(&#034;:\/images\/icons\/boy.ico&#034;);<br \/>\n   else<br \/>\n      icon.addFile(&#034;:\/images\/icons\/girl.ico&#034;);<br \/>\n   item&#061;new  QTableWidgetItem(Sex,MainWindow::ctSex);<br \/>\n   item-&gt;setIcon(icon);<br \/>\n   item-&gt;setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);<br \/>\n   ui-&gt;tableInfo-&gt;setItem(rowNo,MainWindow::colSex,item);<br \/>\n\/\/\u51fa\u751f\u65e5\u671f<br \/>\n   str&#061;birth.toString(&#034;yyyy-MM-dd&#034;); \/\/\u65e5\u671f\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32<br \/>\n   item&#061;new  QTableWidgetItem(str,MainWindow::ctBirth);<br \/>\n   item-&gt;setTextAlignment(Qt::AlignLeft | Qt::AlignVCenter);<br \/>\n   ui-&gt;tableInfo-&gt;setItem(rowNo,MainWindow::colBirth,item);<br \/>\n\/\/\u6c11\u65cf<br \/>\n   item&#061;new  QTableWidgetItem(Nation,MainWindow::ctNation);<br \/>\n   item-&gt;setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);<br \/>\n   ui-&gt;tableInfo-&gt;setItem(rowNo,MainWindow::colNation,item);<br \/>\n\/\/\u662f\u5426\u515a\u5458<br \/>\n   item&#061;new  QTableWidgetItem(&#034;\u515a\u5458&#034;,MainWindow::ctPartyM);<br \/>\n   item-&gt;setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);<br \/>\n   if (isPM)<br \/>\n      item-&gt;setCheckState(Qt::Checked);<br \/>\n   else<br \/>\n      item-&gt;setCheckState(Qt::Unchecked);<br \/>\n   item-&gt;setBackgroundColor(Qt::yellow);<br \/>\n   ui-&gt;tableInfo-&gt;setItem(rowNo,MainWindow::colPartyM,item);<br \/>\n\/\/\u5206\u6570<br \/>\n   str.setNum(score);<br \/>\n   item&#061;new  QTableWidgetItem(str,MainWindow::ctScore);<br \/>\n   item-&gt;setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);<br \/>\n   ui-&gt;tableInfo-&gt;setItem(rowNo,MainWindow::colScore,item);<br \/>\n}<\/p>\n<p>\u8be5\u8868\u683c\u7684\u6bcf\u4e00\u884c\u67096\u5217&#xff0c;\u4e3a\u6bcf\u4e00\u4e2a\u5355\u5143\u683c\u90fd\u521b\u5efa\u4e00\u4e2aQTableWidgetItem\u7c7b\u578b\u7684\u53d8\u91cfitem&#xff0c;\u5e76\u505a\u76f8\u5e94\u7684\u8bbe\u7f6e\u3002<\/p>\n<p>\u521b\u5efaQTableWidgetItem\u4f7f\u7528\u7684\u6784\u9020\u51fd\u6570\u7684\u539f\u578b\u4e3a&#xff1a;<\/p>\n<p>QTableWidgetItem::QTableWidgetItem(const QString &amp;text, int type &#061; Type)<\/p>\n<p>\u5176\u4e2d&#xff0c;\u7b2c\u4e00\u4e2a\u53c2\u6570\u4f5c\u4e3a\u5355\u5143\u683c\u7684\u663e\u793a\u6587\u5b57&#xff0c;\u7b2c\u4e8c\u4e2a\u53c2\u6570\u4f5c\u4e3a\u8282\u70b9\u7684\u7c7b\u578b\u3002<\/p>\n<p>\u4f8b\u5982\u521b\u5efa\u201c\u59d3\u540d\u201d\u5355\u5143\u683c\u5bf9\u8c61\u65f6\u7684\u8bed\u53e5\u662f&#xff1a;<\/p>\n<p>cellItem&#061;new  QtableWidgetItem(Name,MainWindow::ctName);<\/p>\n<p>\u5176\u4e2d&#xff0c;MainWindow::ctName\u662f\u5b9a\u4e49\u7684\u679a\u4e3e\u7c7b\u578bCellType\u7684\u4e00\u4e2a\u5e38\u91cf\u503c\u3002<\/p>\n<p>\u201c\u59d3\u540d\u201d\u5355\u5143\u683c\u8fd8\u8c03\u7528setData()\u51fd\u6570\u8bbe\u7f6e\u4e86\u4e00\u4e2a\u81ea\u5b9a\u4e49\u7684\u6570\u636e&#xff0c;\u5b58\u50a8\u7684\u662f\u5b66\u751fID\u3002<\/p>\n<p>cellItem-&gt;setData(Qt::UserRole,QVariant(StudID));<\/p>\n<p>\u8fd9\u4e2a\u81ea\u5b9a\u4e49\u6570\u636e\u662f\u4e0d\u663e\u793a\u5728\u754c\u9762\u4e0a\u7684&#xff0c;\u4f46\u662f\u4e0e\u5355\u5143\u683c\u76f8\u5173\u8054\u3002<\/p>\n<p>QTableWidgetItem\u6709\u4e00\u4e9b\u51fd\u6570\u5bf9\u5355\u5143\u683c\u8fdb\u884c\u5c5e\u6027\u8bbe\u7f6e&#xff0c;\u5982\u4e0b\u3002<\/p>\n<ul>\n<li>\n<p>setTextAlignment (int alignment)&#xff1a;\u8bbe\u7f6e\u6587\u5b57\u5bf9\u9f50\u65b9\u5f0f\u3002<\/p>\n<\/li>\n<li>\n<p>setBackground(const QBrush &amp;brush)&#xff1a;\u8bbe\u7f6e\u5355\u5143\u683c\u80cc\u666f\u989c\u8272\u3002<\/p>\n<\/li>\n<li>\n<p>setForeground(const QBrush &amp;brush)&#xff1a;\u8bbe\u7f6e\u5355\u5143\u683c\u524d\u666f\u8272\u3002<\/p>\n<\/li>\n<li>\n<p>setIcon(const QIcon &amp;icon)&#xff1a;\u4e3a\u5355\u5143\u683c\u8bbe\u7f6e\u4e00\u4e2a\u663e\u793a\u56fe\u6807\u3002<\/p>\n<\/li>\n<li>\n<p>setFont(const QFont &amp;font)&#xff1a;\u4e3a\u5355\u5143\u683c\u663e\u793a\u6587\u5b57\u8bbe\u7f6e\u5b57\u4f53\u3002<\/p>\n<\/li>\n<li>\n<p>setCheckState(Qt::CheckState state)&#xff1a;\u8bbe\u7f6e\u5355\u5143\u683c\u52fe\u9009\u72b6\u6001&#xff0c;\u5355\u5143\u683c\u91cc\u51fa\u73b0\u4e00\u4e2aQCheckBox\u7ec4\u4ef6\u3002<\/p>\n<\/li>\n<li>\n<p>setFlags(Qt::ItemFlags flags)&#xff1a;\u8bbe\u7f6e\u5355\u5143\u683c\u7684\u4e00\u4e9b\u5c5e\u6027\u6807\u8bb0\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u8bbe\u7f6e\u597ditem\u7684\u5404\u79cd\u5c5e\u6027\u4e4b\u540e&#xff0c;\u7528QTableWidget\u7684setItem\u51fd\u6570\u5c06item\u8bbe\u7f6e\u4e3a\u5355\u5143\u683c\u7684\u9879&#xff0c;\u4f8b\u5982&#xff1a;<\/p>\n<p>ui-&gt;tableInfo-&gt;setItem(rowNo,MainWindow::colName,item);<\/p>\n<p>\u5176\u4e2d&#xff0c;MainWindow::colName\u662f\u5b9a\u4e49\u7684\u679a\u4e3e\u7c7b\u578bFieldColNum\u7684\u4e00\u4e2a\u5e38\u91cf\u503c\u3002<\/p>\n<p>\u8fd9\u6837\u521d\u59cb\u5316\u8bbe\u7f6e\u540e&#xff0c;\u5c31\u53ef\u4ee5\u5f97\u5230\u5982\u539f\u4e66\u7684\u56fe4-18\u6240\u793a\u7684\u8fd0\u884c\u65f6\u7684\u8868\u683c\u5185\u5bb9\u3002\u8868\u683c\u91cc\u5e76\u6ca1\u6709\u663e\u793a\u5b66\u53f7&#xff0c;\u5b66\u53f7\u662f\u201c\u59d3\u540d\u201d\u5355\u5143\u683c\u7684\u5173\u8054\u6570\u636e\u3002<\/p>\n<h5>3&#xff0e;\u83b7\u5f97\u5f53\u524d\u5355\u5143\u683c\u6570\u636e<\/h5>\n<p>\u5f53\u9f20\u6807\u5728\u8868\u683c\u4e0a\u5355\u51fb\u5355\u5143\u683c\u65f6&#xff0c;\u88ab\u9009\u4e2d\u7684\u5355\u5143\u683c\u662f\u5f53\u524d\u5355\u5143\u683c\u3002\u901a\u8fc7QTableWidget\u7684currentColumn()\u548ccurrentRow()\u53ef\u4ee5\u83b7\u5f97\u5f53\u524d\u5355\u5143\u683c\u7684\u5217\u7f16\u53f7\u548c\u884c\u7f16\u53f7\u3002<\/p>\n<p>\u5f53\u524d\u5355\u5143\u683c\u53d1\u751f\u5207\u6362\u65f6&#xff0c;\u4f1a\u53d1\u5c04currentCellChanged()\u4fe1\u53f7\u548ccurrentItemChanged()\u4fe1\u53f7&#xff0c;\u4e24\u4e2a\u4fe1\u53f7\u90fd\u53ef\u4ee5\u5229\u7528&#xff0c;\u53ea\u662f\u4f20\u9012\u7684\u53c2\u6570\u4e0d\u540c\u3002<\/p>\n<p>\u5bf9currentCellChanged()\u4fe1\u53f7\u7f16\u5199\u69fd\u51fd\u6570&#xff0c;\u7528\u4e8e\u83b7\u53d6\u5f53\u524d\u5355\u5143\u683c\u7684\u6570\u636e&#xff0c;\u4ee5\u53ca\u5f53\u524d\u884c\u7684\u5b66\u751f\u7684\u5b66\u53f7\u4fe1\u606f&#xff0c;\u4ee3\u7801\u5982\u4e0b&#xff1a;<\/p>\n<p>void MainWindow::on_tableInfo_currentCellChanged(int currentRow, int currentColumn, int previousRow, int previousColumn)<br \/>\n{\/\/\u5f53\u524d\u9009\u62e9\u5355\u5143\u683c\u53d1\u751f\u53d8\u5316\u65f6\u7684\u54cd\u5e94<br \/>\n   QTableWidgetItem* item&#061;ui-&gt;tableInfo-&gt;item(currentRow,currentColumn);<br \/>\n   if  (item&#061;&#061;NULL)<br \/>\n      return;<br \/>\n   labCellIndex-&gt;setText(QString::asprintf(&#034;\u5f53\u524d\u5355\u5143\u683c\u5750\u6807&#xff1a;%d \u884c&#xff0c;%d \u5217&#034;,<br \/>\n              currentRow,currentColumn));<br \/>\n   int cellType&#061;item-&gt;type();\/\/\u83b7\u53d6\u5355\u5143\u683c\u7684\u7c7b\u578b<br \/>\n   labCellType-&gt;setText(QString::asprintf(&#034;\u5f53\u524d\u5355\u5143\u683c\u7c7b\u578b&#xff1a;%d&#034;,cellType));<br \/>\n   item&#061;ui-&gt;tableInfo-&gt;item(currentRow,MainWindow::colName); \/\/\u7b2c1\u5217\u7684item<br \/>\n   int ID&#061;item-&gt;data(Qt::UserRole).toInt();\/\/\u8bfb\u53d6\u7528\u6237\u81ea\u5b9a\u4e49\u6570\u636e<br \/>\n   labStudID-&gt;setText(QString::asprintf(&#034;\u5b66\u751fID&#xff1a;%d&#034;,ID));\/\/\u5b66\u751fID<br \/>\n}<\/p>\n<p>\u5728currentCellChanged()\u4fe1\u53f7\u4e2d&#xff0c;\u4f20\u9012\u7684\u53c2\u6570currentRow\u548ccurrentColumn\u8868\u793a\u5f53\u524d\u5355\u5143\u683c\u7684\u884c\u53f7\u548c\u5217\u53f7&#xff0c;\u901a\u8fc7\u8fd9\u4e24\u4e2a\u7f16\u53f7\u53ef\u4ee5\u5f97\u5230\u5355\u5143\u683c\u7684QTableWidgetItem\u5bf9\u8c61item\u3002<\/p>\n<p>\u83b7\u5f97item\u4e4b\u540e&#xff0c;\u901a\u8fc7type()\u51fd\u6570\u5f97\u5230\u5355\u5143\u683c\u7684\u7c7b\u578b\u53c2\u6570&#xff0c;\u8fd9\u4e2a\u7c7b\u578b\u5c31\u662f\u4e3a\u5355\u5143\u683c\u521b\u5efaQTableWidgetItem\u5bf9\u8c61\u65f6\u4f20\u9012\u7684\u7c7b\u578b\u53c2\u6570\u3002<\/p>\n<p>\u518d\u83b7\u53d6\u540c\u4e00\u884c\u7684\u201c\u59d3\u540d\u201d\u5355\u5143\u683c\u7684\u9879&#xff0c;\u7528data()\u51fd\u6570\u63d0\u53d6\u81ea\u5b9a\u4e49\u6570\u636e&#xff0c;\u4e5f\u5c31\u662f\u521b\u5efa\u5355\u5143\u683c\u65f6\u5b58\u50a8\u7684\u5b66\u751fID\u3002<\/p>\n<h5>4&#xff0e;\u63d2\u5165\u3001\u6dfb\u52a0\u3001\u5220\u9664\u884c<\/h5>\n<p>QTableWidget\u5904\u7406\u884c\u64cd\u4f5c\u7684\u51fd\u6570\u5982\u4e0b\u3002<\/p>\n<ul>\n<li>\n<p>insertRow(int row)&#xff1a;\u5728\u884c\u53f7\u4e3arow\u7684\u884c\u524d\u9762\u63d2\u5165\u4e00\u884c&#xff0c;\u5982\u679crow\u7b49\u4e8e\u6216\u5927\u4e8e\u603b\u884c\u6570&#xff0c;\u5219\u5728\u8868\u683c\u6700\u540e\u6dfb\u52a0\u4e00\u884c\u3002insertRow()\u51fd\u6570\u53ea\u662f\u63d2\u5165\u4e00\u4e2a\u7a7a\u884c&#xff0c;\u4e0d\u4f1a\u4e3a\u5355\u5143\u683c\u521b\u5efaQTableWidgetItem\u5bf9\u8c61&#xff0c;\u9700\u8981\u624b\u5de5\u4e3a\u5355\u5143\u683c\u521b\u5efa\u3002<\/p>\n<\/li>\n<li>\n<p>removeRow(int row)&#xff1a;\u5220\u9664\u884c\u53f7\u4e3arow\u7684\u884c\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u4e0b\u9762\u662f\u754c\u9762\u4e0a\u201c\u63d2\u5165\u884c\u201d\u201c\u6dfb\u52a0\u884c\u201d\u201c\u5220\u9664\u5f53\u524d\u884c\u201d\u6309\u94ae\u7684\u54cd\u5e94\u4ee3\u7801\u3002\u5728\u63d2\u5165\u884c\u4e4b\u540e&#xff0c;\u4f1a\u8c03\u7528createItemsARow()\u51fd\u6570&#xff0c;\u4e3a\u65b0\u521b\u5efa\u7684\u7a7a\u884c\u7684\u5404\u5355\u5143\u683c\u6784\u9020QTableWidgetItem\u5bf9\u8c61\u3002<\/p>\n<p>void MainWindow::on_btnInsertRow_clicked()<br \/>\n{ \/\/\u63d2\u5165\u4e00\u884c<br \/>\n   int curRow&#061;ui-&gt;tableInfo-&gt;currentRow();<br \/>\n   ui-&gt;tableInfo-&gt;insertRow(curRow); \/\/\u63d2\u5165\u4e00\u884c&#xff0c;\u4e0d\u4f1a\u81ea\u52a8\u4e3a\u5355\u5143\u683c\u521b\u5efaitem<br \/>\n   createItemsARow(curRow, &#034;\u65b0\u5b66\u751f&#034;, &#034;\u7537&#034;,<br \/>\n        QDate::fromString(&#034;1990-1-1&#034;,&#034;yyyy-M-d&#034;),&#034;\u82d7\u65cf&#034;,true );<br \/>\n}<br \/>\nvoid MainWindow::on_btnAppendRow_clicked()<br \/>\n{ \/\/\u6dfb\u52a0\u4e00\u884c<br \/>\n   int curRow&#061;ui-&gt;tableInfo-&gt;rowCount();<br \/>\n   ui-&gt;tableInfo-&gt;insertRow(curRow);\/\/\u5728\u8868\u683c\u5c3e\u90e8\u6dfb\u52a0\u4e00\u884c<br \/>\n   createItemsARow(curRow, &#034;\u65b0\u751f&#034;, &#034;\u5973&#034;,<br \/>\n        QDate::fromString(&#034;2000-1-1&#034;,&#034;yyyy-M-d&#034;),&#034;\u6ee1\u65cf&#034;,false );<br \/>\n}<br \/>\nvoid MainWindow::on_btnDelCurRow_clicked()<br \/>\n{\/\/\u5220\u9664\u5f53\u524d\u884c\u53ca\u5176items<br \/>\n   int  curRow&#061;ui-&gt;tableInfo-&gt;currentRow();<br \/>\n   ui-&gt;tableInfo-&gt;removeRow(curRow); \/\/\u5220\u9664\u5f53\u524d\u884c\u53ca\u5176items<br \/>\n}<\/p>\n<h5>5&#xff0e;\u81ea\u52a8\u8c03\u6574\u884c\u9ad8\u548c\u5217\u5bbd<\/h5>\n<p>QTableWidget\u6709\u51e0\u4e2a\u51fd\u6570\u81ea\u52a8\u8c03\u6574\u8868\u683c\u7684\u884c\u9ad8\u548c\u5217\u5bbd&#xff0c;\u5206\u522b\u5982\u4e0b\u3002<\/p>\n<ul>\n<li>\n<p>resizeColumnsToContents()&#xff1a;\u81ea\u52a8\u8c03\u6574\u6240\u6709\u5217\u7684\u5bbd\u5ea6&#xff0c;\u4ee5\u9002\u5e94\u5176\u5185\u5bb9\u3002<\/p>\n<\/li>\n<li>\n<p>resizeColumnToContents(int column)&#xff1a;\u81ea\u52a8\u8c03\u6574\u5217\u53f7\u4e3acolumn\u7684\u5217\u7684\u5bbd\u5ea6\u3002<\/p>\n<\/li>\n<li>\n<p>resizeRowsToContents()&#xff1a;\u81ea\u52a8\u8c03\u6574\u6240\u6709\u884c\u7684\u9ad8\u5ea6&#xff0c;\u4ee5\u9002\u5e94\u5176\u5185\u5bb9\u3002<\/p>\n<\/li>\n<li>\n<p>resizeRowToContents(int row)&#xff1a;\u81ea\u52a8\u8c03\u6574\u884c\u53f7\u4e3arow\u7684\u884c\u7684\u9ad8\u5ea6\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u8fd9\u51e0\u4e2a\u51fd\u6570\u5b9e\u9645\u4e0a\u662fQTableWidget\u7684\u7236\u7c7bQTableView\u7684\u51fd\u6570\u3002<\/p>\n<h5>6&#xff0e;\u5176\u4ed6\u5c5e\u6027\u63a7\u5236<\/h5>\n<ul>\n<li>\u8bbe\u7f6e\u8868\u683c\u5185\u5bb9\u662f\u5426\u53ef\u7f16\u8f91<\/li>\n<\/ul>\n<p>QTableWidget\u7684EditTriggers\u5c5e\u6027\u8868\u793a\u662f\u5426\u53ef\u7f16\u8f91&#xff0c;\u4ee5\u53ca\u8fdb\u5165\u7f16\u8f91\u72b6\u6001\u7684\u65b9\u5f0f\u3002\u754c\u9762\u4e0a\u7684\u201c\u8868\u683c\u53ef\u7f16\u8f91\u201d\u590d\u9009\u6846\u7684\u69fd\u51fd\u6570\u4ee3\u7801\u4e3a&#xff1a;<\/p>\n<p>void MainWindow::on_chkBoxTabEditable_clicked(bool checked)<br \/>\n{ \/\/\u8bbe\u7f6e\u7f16\u8f91\u6a21\u5f0f<br \/>\n   if (checked)<br \/>\n      ui-&gt;tableInfo-&gt;setEditTriggers(QAbstractItemView::DoubleClicked | QAbstractItemView::SelectedClicked); \/\/\u53cc\u51fb\u6216\u83b7\u53d6\u7126\u70b9\u540e\u5355\u51fb&#xff0c;\u8fdb\u5165\u7f16\u8f91\u72b6\u6001<br \/>\n   else<br \/>\n      ui-&gt;tableInfo-&gt;setEditTriggers(QAbstractItemView::NoEditTriggers);<br \/>\n}<\/p>\n<ul>\n<li>\u8bbe\u7f6e\u884c\u8868\u5934\u3001\u5217\u8868\u5934\u662f\u5426\u663e\u793a<\/li>\n<\/ul>\n<p>horizontalHeader()\u83b7\u53d6\u884c\u8868\u5934&#xff0c;verticalHeader()\u83b7\u53d6\u5217\u8868\u5934&#xff0c;\u7136\u540e\u53ef\u8bbe\u7f6e\u5176\u53ef\u89c1\u6027\u3002<\/p>\n<p>void MainWindow::on_chkBoxHeaderH_clicked(bool checked)<br \/>\n{\/\/\u662f\u5426\u663e\u793a\u884c\u8868\u5934<br \/>\n   ui-&gt;tableInfo-&gt;horizontalHeader()-&gt;setVisible(checked);<br \/>\n}<br \/>\nvoid MainWindow::on_chkBoxHeaderV_clicked(bool checked)<br \/>\n{\/\/\u662f\u5426\u663e\u793a\u5217\u8868\u5934<br \/>\n   ui-&gt;tableInfo-&gt;verticalHeader()-&gt;setVisible(checked);<br \/>\n}<\/p>\n<ul>\n<li>\u95f4\u9694\u884c\u5e95\u8272<\/li>\n<\/ul>\n<p>setAlternatingRowColors()\u51fd\u6570\u53ef\u4ee5\u8bbe\u7f6e\u8868\u683c\u7684\u884c\u662f\u5426\u7528\u4ea4\u66ff\u5e95\u8272\u663e\u793a&#xff0c;\u82e5\u4e3a\u4ea4\u66ff\u5e95\u8272&#xff0c;\u5219\u95f4\u9694\u7684\u4e00\u884c\u4f1a\u7528\u7070\u8272\u4f5c\u4e3a\u5e95\u8272\u3002\u5177\u4f53\u5e95\u8272\u7684\u8bbe\u7f6e\u9700\u8981\u7528styleSheet&#xff0c;\u572816.2\u8282\u6709\u4ecb\u7ecd\u3002<\/p>\n<p>void MainWindow::on_chkBoxRowColor_clicked(bool checked)<br \/>\n{<br \/>\n   ui-&gt;tableInfo-&gt;setAlternatingRowColors(checked);<br \/>\n}<\/p>\n<ul>\n<li>\u9009\u62e9\u6a21\u5f0f<\/li>\n<\/ul>\n<p>setSelectionBehavior()\u51fd\u6570\u53ef\u4ee5\u8bbe\u7f6e\u9009\u62e9\u65b9\u5f0f\u4e3a\u5355\u5143\u683c\u9009\u62e9&#xff0c;\u8fd8\u662f\u884c\u9009\u62e9\u3002<\/p>\n<p>void MainWindow::on_rBtnSelectItem_clicked()<br \/>\n{\/\/\u9009\u62e9\u884c\u4e3a&#xff1a;\u5355\u5143\u683c\u9009\u62e9<br \/>\n   ui-&gt;tableInfo-&gt;setSelectionBehavior(QAbstractItemView::SelectItems);<br \/>\n}<br \/>\nvoid MainWindow::on_rBtnSelectRow_clicked()<br \/>\n{\/\/\u9009\u62e9\u884c\u4e3a&#xff1a;\u884c\u9009\u62e9<br \/>\n   ui-&gt;tableInfo-&gt;setSelectionBehavior(QAbstractItemView::SelectRows);<br \/>\n}<\/p>\n<h5>7&#xff0e;\u904d\u5386\u8868\u683c\u8bfb\u53d6\u6570\u636e<\/h5>\n<p>\u201c\u8bfb\u53d6\u8868\u683c\u5185\u5bb9\u5230\u6587\u672c\u201d\u6309\u94ae\u6f14\u793a\u4e86\u5c06\u8868\u683c\u6570\u636e\u533a\u7684\u5185\u5bb9\u5168\u90e8\u8bfb\u51fa\u7684\u65b9\u6cd5&#xff0c;\u5b83\u5c06\u6bcf\u4e2a\u5355\u5143\u683c\u7684\u6587\u5b57\u8bfb\u51fa&#xff0c;\u540c\u4e00\u884c\u7684\u5355\u5143\u683c\u7684\u6587\u5b57\u7528\u7a7a\u683c\u5206\u9694\u5f00&#xff0c;\u4f5c\u4e3a\u6587\u672c\u7684\u4e00\u884c&#xff0c;\u7136\u540e\u5c06\u8fd9\u884c\u6587\u5b57\u4f5c\u4e3a\u6587\u672c\u7f16\u8f91\u5668\u7684\u4e00\u884c\u5185\u5bb9&#xff0c;\u4ee3\u7801\u5982\u4e0b&#xff1a;<\/p>\n<p>void MainWindow::on_btnReadToEdit_clicked()<br \/>\n{\/\/\u5c06\u6240\u6709\u5355\u5143\u683c\u7684\u5185\u5bb9\u63d0\u53d6\u5b57\u7b26\u4e32&#xff0c;\u663e\u793a\u5728PlainTextEdit\u7ec4\u4ef6\u91cc<br \/>\n   QString  str;<br \/>\n   QtableWidgetItem  *cellItem;<br \/>\n   ui-&gt;textEdit-&gt;clear();<br \/>\n   for (int i&#061;0;i&lt;ui-&gt;tableInfo-&gt;rowCount();i&#043;&#043;)<br \/>\n   {<br \/>\n     str&#061;QString::asprintf(&#034;\u7b2c %d \u884c&#xff1a; &#034;,i&#043;1);<br \/>\n     for (int j&#061;0;j&lt;ui-&gt;tableInfo-&gt;columnCount()-1;j&#043;&#043;)<br \/>\n     {<br \/>\n         cellItem&#061;ui-&gt;tableInfo-&gt;item(i,j); \/\/\u83b7\u53d6\u5355\u5143\u683c\u7684item<br \/>\n         str&#061;str&#043;cellItem-&gt;text()&#043;&#034;   &#034;; \/\/\u5b57\u7b26\u4e32\u8fde\u63a5<br \/>\n      }<br \/>\n     cellItem&#061;ui-&gt;tableInfo-&gt;item(i,colNoPartyM);  \/\/\u6700\u540e\u4e00\u5217<br \/>\n     if (cellItem-&gt;checkState()&#061;&#061;Qt::Checked)<br \/>\n        str&#061;str&#043;&#034;\u515a\u5458&#034;;<br \/>\n     else<br \/>\n        str&#061;str&#043;&#034;\u7fa4\u4f17&#034;;<br \/>\n     ui-&gt;textEdit-&gt;appendPlainText(str);<br \/>\n   }<br \/>\n}<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u7b2c4\u7ae0\u3000\u5e38\u7528\u754c\u9762\u8bbe\u8ba1\u7ec4\u4ef6<br \/>\n\u7b2c2\u7ae0\u5df2\u7ecf\u4ecb\u7ecd\u4e86\u8bbe\u8ba1GUI\u5e94\u7528\u7a0b\u5e8f\u7684\u57fa\u672c\u539f\u7406\u548c\u65b9\u6cd5&#xff0c;\u5728\u638c\u63e1\u4e86\u7528Qt Creator\u8bbe\u8ba1\u5e94\u7528\u7a0b\u5e8f\u7684\u57fa\u672c\u65b9\u6cd5\u4e4b\u540e&#xff0c;\u8981\u5e94\u7528Qt\u7f16\u5199\u5404\u79cd\u5e94\u7528\u7a0b\u5e8f&#xff0c;\u91cd\u8981\u7684\u5c31\u662f\u719f\u7ec3\u638c\u63e1Qt\u7c7b\u5e93\u91cc\u5404\u79cd\u7528\u4e8e\u754c\u9762\u8bbe\u8ba1\u6216\u5176\u4ed6\u529f\u80fd\u7684\u7c7b\u7684\u4f7f\u7528\u3002<br \/>\nQt\u7c7b\u5e93\u4e3a\u5e94\u7528\u7a0b\u5e8f\u8bbe\u8ba1\u63d0\u4f9b\u4e86\u5927\u91cf\u7684\u7c7b&#xff0c;\u672c\u7ae0\u4e3b\u8981\u4ecb\u7ecd\u8bbe\u8ba1GUI\u5e94\u7528\u7a0b\u5e8f\u5e38\u7528\u7684\u5404\u79cd\u754c\u9762\u7ec4\u4ef6\u7684\u4f7f\u7528&#xff0c;\u8fd9\u4e9b\u662f\u8bbe\u8ba1GUI\u5e94\u7528\u7a0b\u5e8f\u7684\u57fa\u7840\u3002<br \/>\n4.1\u3000\u5b57\u7b26\u4e32\u4e0e\u8f93\u5165\u8f93\u51fa<br \/>\n4.1.1\u5b57\u7b26\u4e32\u4e0e\u6570\u503c\u4e4b<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[10580,218,305],"topic":[],"class_list":["post-106320","post","type-post","status-publish","format-standard","hentry","category-server","tag-qt5","tag-qt","tag-305"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u3010Qt\u3011\u300aQt 5.9 C++\u5f00\u53d1\u6307\u5357\u300b\u7b14\u8bb0-Chapter4-\u5e38\u7528\u754c\u9762\u8bbe\u8ba1\u7ec4\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\/106320.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u3010Qt\u3011\u300aQt 5.9 C++\u5f00\u53d1\u6307\u5357\u300b\u7b14\u8bb0-Chapter4-\u5e38\u7528\u754c\u9762\u8bbe\u8ba1\u7ec4\u4ef6 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u7b2c4\u7ae0\u3000\u5e38\u7528\u754c\u9762\u8bbe\u8ba1\u7ec4\u4ef6 \u7b2c2\u7ae0\u5df2\u7ecf\u4ecb\u7ecd\u4e86\u8bbe\u8ba1GUI\u5e94\u7528\u7a0b\u5e8f\u7684\u57fa\u672c\u539f\u7406\u548c\u65b9\u6cd5&#xff0c;\u5728\u638c\u63e1\u4e86\u7528Qt Creator\u8bbe\u8ba1\u5e94\u7528\u7a0b\u5e8f\u7684\u57fa\u672c\u65b9\u6cd5\u4e4b\u540e&#xff0c;\u8981\u5e94\u7528Qt\u7f16\u5199\u5404\u79cd\u5e94\u7528\u7a0b\u5e8f&#xff0c;\u91cd\u8981\u7684\u5c31\u662f\u719f\u7ec3\u638c\u63e1Qt\u7c7b\u5e93\u91cc\u5404\u79cd\u7528\u4e8e\u754c\u9762\u8bbe\u8ba1\u6216\u5176\u4ed6\u529f\u80fd\u7684\u7c7b\u7684\u4f7f\u7528\u3002 Qt\u7c7b\u5e93\u4e3a\u5e94\u7528\u7a0b\u5e8f\u8bbe\u8ba1\u63d0\u4f9b\u4e86\u5927\u91cf\u7684\u7c7b&#xff0c;\u672c\u7ae0\u4e3b\u8981\u4ecb\u7ecd\u8bbe\u8ba1GUI\u5e94\u7528\u7a0b\u5e8f\u5e38\u7528\u7684\u5404\u79cd\u754c\u9762\u7ec4\u4ef6\u7684\u4f7f\u7528&#xff0c;\u8fd9\u4e9b\u662f\u8bbe\u8ba1GUI\u5e94\u7528\u7a0b\u5e8f\u7684\u57fa\u7840\u3002 4.1\u3000\u5b57\u7b26\u4e32\u4e0e\u8f93\u5165\u8f93\u51fa 4.1.1\u5b57\u7b26\u4e32\u4e0e\u6570\u503c\u4e4b\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/106320.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-09-16T22:56:30+00:00\" \/>\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=\"36 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/106320.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/106320.html\",\"name\":\"\u3010Qt\u3011\u300aQt 5.9 C++\u5f00\u53d1\u6307\u5357\u300b\u7b14\u8bb0-Chapter4-\u5e38\u7528\u754c\u9762\u8bbe\u8ba1\u7ec4\u4ef6 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-09-16T22:56:30+00:00\",\"dateModified\":\"2026-09-16T22:56:30+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/106320.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/106320.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/106320.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u3010Qt\u3011\u300aQt 5.9 C++\u5f00\u53d1\u6307\u5357\u300b\u7b14\u8bb0-Chapter4-\u5e38\u7528\u754c\u9762\u8bbe\u8ba1\u7ec4\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":"\u3010Qt\u3011\u300aQt 5.9 C++\u5f00\u53d1\u6307\u5357\u300b\u7b14\u8bb0-Chapter4-\u5e38\u7528\u754c\u9762\u8bbe\u8ba1\u7ec4\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\/106320.html","og_locale":"zh_CN","og_type":"article","og_title":"\u3010Qt\u3011\u300aQt 5.9 C++\u5f00\u53d1\u6307\u5357\u300b\u7b14\u8bb0-Chapter4-\u5e38\u7528\u754c\u9762\u8bbe\u8ba1\u7ec4\u4ef6 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u7b2c4\u7ae0\u3000\u5e38\u7528\u754c\u9762\u8bbe\u8ba1\u7ec4\u4ef6 \u7b2c2\u7ae0\u5df2\u7ecf\u4ecb\u7ecd\u4e86\u8bbe\u8ba1GUI\u5e94\u7528\u7a0b\u5e8f\u7684\u57fa\u672c\u539f\u7406\u548c\u65b9\u6cd5&#xff0c;\u5728\u638c\u63e1\u4e86\u7528Qt Creator\u8bbe\u8ba1\u5e94\u7528\u7a0b\u5e8f\u7684\u57fa\u672c\u65b9\u6cd5\u4e4b\u540e&#xff0c;\u8981\u5e94\u7528Qt\u7f16\u5199\u5404\u79cd\u5e94\u7528\u7a0b\u5e8f&#xff0c;\u91cd\u8981\u7684\u5c31\u662f\u719f\u7ec3\u638c\u63e1Qt\u7c7b\u5e93\u91cc\u5404\u79cd\u7528\u4e8e\u754c\u9762\u8bbe\u8ba1\u6216\u5176\u4ed6\u529f\u80fd\u7684\u7c7b\u7684\u4f7f\u7528\u3002 Qt\u7c7b\u5e93\u4e3a\u5e94\u7528\u7a0b\u5e8f\u8bbe\u8ba1\u63d0\u4f9b\u4e86\u5927\u91cf\u7684\u7c7b&#xff0c;\u672c\u7ae0\u4e3b\u8981\u4ecb\u7ecd\u8bbe\u8ba1GUI\u5e94\u7528\u7a0b\u5e8f\u5e38\u7528\u7684\u5404\u79cd\u754c\u9762\u7ec4\u4ef6\u7684\u4f7f\u7528&#xff0c;\u8fd9\u4e9b\u662f\u8bbe\u8ba1GUI\u5e94\u7528\u7a0b\u5e8f\u7684\u57fa\u7840\u3002 4.1\u3000\u5b57\u7b26\u4e32\u4e0e\u8f93\u5165\u8f93\u51fa 4.1.1\u5b57\u7b26\u4e32\u4e0e\u6570\u503c\u4e4b","og_url":"https:\/\/www.wsisp.com\/helps\/106320.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-09-16T22:56:30+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"36 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/106320.html","url":"https:\/\/www.wsisp.com\/helps\/106320.html","name":"\u3010Qt\u3011\u300aQt 5.9 C++\u5f00\u53d1\u6307\u5357\u300b\u7b14\u8bb0-Chapter4-\u5e38\u7528\u754c\u9762\u8bbe\u8ba1\u7ec4\u4ef6 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-09-16T22:56:30+00:00","dateModified":"2026-09-16T22:56:30+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/106320.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/106320.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/106320.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u3010Qt\u3011\u300aQt 5.9 C++\u5f00\u53d1\u6307\u5357\u300b\u7b14\u8bb0-Chapter4-\u5e38\u7528\u754c\u9762\u8bbe\u8ba1\u7ec4\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\/106320","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=106320"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/106320\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=106320"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=106320"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=106320"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=106320"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}