{"id":237730,"date":"2021-01-01T09:34:29","date_gmt":"2021-01-01T01:34:29","guid":{"rendered":"http:\/\/4563.org\/?p=237730"},"modified":"2021-01-02T01:35:10","modified_gmt":"2021-01-01T17:35:10","slug":"%e9%87%8d%e5%86%99-qcombobox%ef%bc%8c%e5%ae%9e%e7%8e%b0%e8%87%aa%e5%ae%9a%e4%b9%89-qfontcombobox%ef%bc%8c%e5%8f%af%e4%bb%a5%e6%b7%bb%e5%8a%a0%e8%87%aa%e5%ae%9a%e4%b9%89%e5%ad%97%e4%bd%93%ef%bc%8c","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=237730","title":{"rendered":"\u91cd\u5199 QComboBox\uff0c\u5b9e\u73b0\u81ea\u5b9a\u4e49 QFontComboBox\uff0c\u53ef\u4ee5\u6dfb\u52a0\u81ea\u5b9a\u4e49\u5b57\u4f53\uff0c\u663e\u793a\u5b57\u4f53\u6837\u5f0f"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  \u91cd\u5199 QComboBox\uff0c\u5b9e\u73b0\u81ea\u5b9a\u4e49 QFontComboBox\uff0c\u53ef\u4ee5\u6dfb\u52a0\u81ea\u5b9a\u4e49\u5b57\u4f53\uff0c\u663e\u793a\u5b57\u4f53\u6837\u5f0f               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : zoule <\/span>  <span><i><\/i> 7<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>\u5728\u5f00\u53d1\u7684\u8fc7\u7a0b\u4e2d\uff0c\u6709\u4e2a\u9700\u6c42\uff0c\u662f\u6dfb\u52a0\u4e00\u4e2a\u5b57\u4f53\u9009\u62e9\u6846\uff0c\u8fd9\u4e2a\u7b80\u5355\uff0c\u6211\u53ef\u4ee5\u76f4\u63a5\u7528\u4e86 QFontComboBox \u89e3\u51b3\uff0c\u4f46\u662f\u6211\u7684\u9700\u6c42\u662f\u5b57\u4f53\u4e0d\u7528\u7cfb\u7edf\u5b57\u4f53\uff0c\u800c\u662f\u7528\u6211\u4eec\u81ea\u5b9a\u4e49\u6dfb\u52a0\u7684\u5b57\u4f53\u5e93\uff0c\u540e\u6765\u6211\u5c1d\u8bd5\u7528 QComboBox \u89e3\u51b3\uff0c\u4f46\u662f\uff0c\u8fd9\u4e2a\u9b3c\u4e1c\u897f\u5374\u4e0d\u80fd\u5355\u72ec\u6539\u53d8\u5355\u72ec item \u7684\u5b57\u4f53\u6837\u5f0f\uff0c\u7b97\u4e86\uff0c\u76f4\u63a5\u81ea\u5df1\u5199\u5427\uff0c\u8bdd\u4e0d\u591a\u8bf4\uff0c\u4e0a\u4ee3\u7801\uff1a<\/p>\n<pre><code> class CFontComboBox : public QComboBox {     Q_OBJECT private:     QListWidget * mFontList; public:     CFontComboBox(QWidget * parent = nullptr);     void addFont(QString famil);     void addFonts(QStringList famils); protected:     void wheelEvent(QWheelEvent ) override; };  .cpp \u6587\u4ef6  CFontComboBox::CFontComboBox(QWidgetparent) :     QComboBox(parent) {     mFontList = new QListWidget(this);     setModel(mFontList-&gt;model());     setView(mFontList);     mFontList-&gt;setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);     setStyleSheet(\"QComboBox{combobox-popup:0;}\");     setMaxVisibleItems(5); } void CFontComboBox::wheelEvent(QWheelEvent * event) { } void CFontComboBox::addFont(QString famil) {     auto item = new QListWidgetItem(famil);     QFont font;     font.setFamily(famil);     item-&gt;setFont(font);     QIcon icon(\":icons\/T.png\");     item-&gt;setIcon(icon);     mFontList-&gt;addItem(item); } void CFontComboBox::addFonts(QStringList famils) {     for (auto famil : famils)     {         addFont(famil);     } } <\/code><\/pre>\n<p>\u5927\u529f\u544a\u6210\uff0c\u8bdd\u4e0d\u591a\u8bf4\uff0c\u4e0a\u56fe\uff1a <img decoding=\"async\" loading=\"lazy\" referrerpolicy=\"no-referrer\" rel=\"noreferrer\" src=\"http:\/\/4563.org\/wp-content\/uploads\/2021\/01\/20210101_5fef5d3c60813.png\" alt=\"\u91cd\u5199 QComboBox\uff0c\u5b9e\u73b0\u81ea\u5b9a\u4e49 QFontComboBox\uff0c\u53ef\u4ee5\u6dfb\u52a0\u81ea\u5b9a\u4e49\u5b57\u4f53\uff0c\u663e\u793a\u5b57\u4f53\u6837\u5f0f\" \/><\/p>\n<p>\u81ea\u5b9a\u4e49\u7684\u662f\u6ca1\u6709\u524d\u9762\u662f\u6ca1\u6709\u90a3\u4e2a\u56fe\u6807\u7684\uff0c\u8fd9\u662f\u6211\u8ba9 UI \u7ed9\u6211\u8bbe\u8ba1\u7684\uff0c\u60f3\u8981\u7684\u53ef\u4ee5\u62ff\u53bb\u7528\uff0c\u8bdd\u4e0d\u591a\u8bf4\uff0c\u4e0a\u56fe\uff1a<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" referrerpolicy=\"no-referrer\" rel=\"noreferrer\" src=\"http:\/\/4563.org\/wp-content\/uploads\/2021\/01\/1240.png\" alt=\"\u91cd\u5199 QComboBox\uff0c\u5b9e\u73b0\u81ea\u5b9a\u4e49 QFontComboBox\uff0c\u53ef\u4ee5\u6dfb\u52a0\u81ea\u5b9a\u4e49\u5b57\u4f53\uff0c\u663e\u793a\u5b57\u4f53\u6837\u5f0f\" \/><\/p>\n<p>\u4e3a\u4e86\u9632\u6b62\u6709\u4eba\u770b\u4e0d\u61c2\uff0c\u6211\u8fd8\u662f\u89e3\u91ca\u4e00\u4e0b\u5427\uff0c\u770b\u61c2\u7684\u76f4\u63a5\u8df3\u8fc7\uff0c setView(),\u662f\u628a\u6211\u4eec\u7684 View \u66ff\u6362\u4e0a\u53bb\uff0c\u7136\u540e\u6211\u4eec\u5728\u5bf9\u6211\u4eec\u7684 View \u8fdb\u884c\u64cd\u4f5c\uff0c<\/p>\n<pre><code>setStyleSheet(\u201cQComboBox{combobox-popup:0;}\u201d); setMaxVisibleItems(5); <\/code><\/pre>\n<p>\u8fd9\u4e09\u53e5\u662f\u4e3a\u4e86\u8bbe\u7f6e\u6eda\u52a8\u6761\u548c\u6700\u5927\u663e\u793a\u4e2a\u6570\uff0c\u4e0d\u9700\u8981\u7684\u53ef\u4ee5\u4e0d\u7528\u8bbe\u7f6e \u6211\u8fd9\u91cc\u91cd\u5199\u4e86 wheelEvent \u65b9\u6cd5\uff0c\u662f\u4e3a\u4e86\u6211\u4e0d\u60f3\u4e0d\u8ba9\u7528\u6237\u901a\u8fc7\u9f20\u6807\u53bb\u6539\u53d8\u5b57\u4f53\uff0c\u4e0d\u9700\u8981\u7684\u53ef\u4ee5\u4e0d\u91cd\u5199\uff0c \u6700\u540e addFont \u548c addFonts \u4e0d\u7528\u89e3\u91ca\u4e86\u5427\uff0c\u76f4\u63a5\u7528\u8fd9\u4e24\u4e2a\u65b9\u6cd5\u53bb\u6dfb\u52a0\u5b57\u4f53\u90fd\u884c\u4e86 \u5982\u679c\u611f\u89c9\u6211\u7684\u5b9e\u4f8b\u53ef\u4ee5\u5e2e\u52a9\u5230\u4f60\uff0c\u8bb0\u5f97\u5173\u6ce8\uff0c\u4ee5\u540e\u4f1a\u7ecf\u5e38\u66f4\u65b0 Qt \u6280\u5de7\u548c\u65b9\u6cd5 \u8bdd\u4e0d\u591a\u8bf4\uff0c\u4e0b\u8bfe<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>3<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"4676275\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : QBugHunter <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u8c01\u544a\u8bc9\u4f60 QComboBox \u4e0d\u80fd\u5355\u72ec\u6539\u53d8\u4e0b\u62c9\u83dc\u5355\u6837\u5f0f\u8868\u7684\uff1f<\/p>\n<p>QComboBox QAbstractItemView::item{min-height:20px}                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4676276\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : QBugHunter <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             QComboBox \u7684\u4e0b\u62c9\u83dc\u5355\uff08\u8f85\u52a9\u63a7\u5236\u5668\uff09\u53eb QAbstractItemView<br \/>![]( https:\/\/jxf2008-1302581379.cos.ap-nanjing.myqcloud.com\/QtNotes\/28-4.png)                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4676277\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : ysc3839 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u8fd9\u4e2a\u56fe\u6807\u52a0\u4e86\u8ddf\u6ca1\u52a0\u4e00\u6837\uff0c\u56e0\u4e3a\u90fd\u662f\u4e00\u6837\u7684\uff0c\u52a0\u4e86\u5bf9\u7528\u6237\u4f7f\u7528\u6ca1\u6709\u5e2e\u52a9\u3002<br \/>\u8981\u662f\u9009\u62e9\u56fe\u6807\u7684\u5217\u8868\uff0c\u52a0\u4e2a\u56fe\u6807\u9884\u89c8\u5c31\u6bd4\u8f83\u597d\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>\u91cd\u5199 QComboBox\uff0c\u5b9e\u73b0\u81ea\u5b9a&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/237730"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=237730"}],"version-history":[{"count":1,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/237730\/revisions"}],"predecessor-version":[{"id":237732,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/237730\/revisions\/237732"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=237730"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=237730"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=237730"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}