{"id":204246,"date":"2025-05-29T12:59:34","date_gmt":"2025-05-29T04:59:34","guid":{"rendered":"https:\/\/server.hk\/cnblog\/204246\/"},"modified":"2025-05-29T12:59:34","modified_gmt":"2025-05-29T04:59:34","slug":"%e4%bd%bf%e7%94%a8-pyqt5-%e5%bc%80%e5%8f%91-gui-%e6%97%b6%ef%bc%8c%e5%a6%82%e4%bd%95%e8%8e%b7%e5%8f%96-qlabel-%e4%b8%ad%e8%87%aa%e9%80%82%e5%ba%94%e5%9b%be%e7%89%87%e7%9a%84%e5%ae%9e%e9%99%85%e6%98%be","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/204246\/","title":{"rendered":"\u4f7f\u7528 PyQt5 \u5f00\u53d1 GUI \u65f6\uff0c\u5982\u4f55\u83b7\u53d6 QLabel \u4e2d\u81ea\u9002\u5e94\u56fe\u7247\u7684\u5b9e\u9645\u663e\u793a\u5927\u5c0f\u548c\u5750\u6807\uff1f\u5982\u4f55\u8ba9 QPixmap \u663e\u793a\u7684\u56fe\u7247\u81ea\u9002\u5e94\u5927\u5c0f\u5e76\u52a8\u6001\u6700\u5927\u5316\uff1f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>\u4f7f\u7528 PyQt5 \u5f00\u53d1 GUI \u65f6\uff0c\u5982\u4f55\u83b7\u53d6 QLabel \u4e2d\u81ea\u9002\u5e94\u56fe\u7247\u7684\u5b9e\u9645\u663e\u793a\u5927\u5c0f\u548c\u5750\u6807\uff1f\u5982\u4f55\u8ba9 QPixmap \u663e\u793a\u7684\u56fe\u7247\u81ea\u9002\u5e94\u5927\u5c0f\u5e76\u52a8\u6001\u6700\u5927\u5316\uff1f<\/h1>\n<p>\u4e0d\u77e5\u9053\u5927\u5bb6\u662f\u5426\u719f\u6089\uff1f\u4eca\u5929\u6211\u5c06\u7ed9\u5927\u5bb6\u4ecb\u7ecd<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300a\u4f7f\u7528 PyQt5 \u5f00\u53d1 GUI \u65f6\uff0c\u5982\u4f55\u83b7\u53d6 QLabel \u4e2d\u81ea\u9002\u5e94\u56fe\u7247\u7684\u5b9e\u9645\u663e\u793a\u5927\u5c0f\u548c\u5750\u6807\uff1f\u5982\u4f55\u8ba9 QPixmap \u663e\u793a\u7684\u56fe\u7247\u81ea\u9002\u5e94\u5927\u5c0f\u5e76\u52a8\u6001\u6700\u5927\u5316\uff1f\u300b<\/span>\uff0c\u8fd9\u7bc7\u6587\u7ae0\u4e3b\u8981\u4f1a\u8bb2\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5982\u679c\u4f60\u5728\u770b\u5b8c\u672c\u7bc7\u6587\u7ae0\u540e\uff0c\u6709\u66f4\u597d\u7684\u5efa\u8bae\u6216\u8005\u53d1\u73b0\u54ea\u91cc\u6709\u95ee\u9898\uff0c\u5e0c\u671b\u5927\u5bb6\u90fd\u80fd\u79ef\u6781\u8bc4\u8bba\u6307\u51fa\uff0c\u8c22\u8c22\uff01\u5e0c\u671b\u6211\u4eec\u80fd\u4e00\u8d77\u52a0\u6cb9\u8fdb\u6b65\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241102\/1730516975672597ef3bf46.jpg\" class=\"aligncenter\"><\/p>\n<p><strong>Python PyQt5 \u4e2d\u5e38\u89c1\u7684\u4e24\u4e2a\u95ee\u9898<\/strong><\/p>\n<p>\u5728\u4f7f\u7528 PyQt5 \u8fdb\u884c GUI \u5f00\u53d1\u65f6\uff0c\u4ee5\u4e0b\u4e24\u4e2a\u95ee\u9898\u7ecf\u5e38\u4f1a\u9047\u5230\uff1a<\/p>\n<p><strong>\u5982\u4f55\u83b7\u53d6 PyQt5 \u4e2d QLabel \u4e2d\u81ea\u9002\u5e94\u5927\u5c0f\u56fe\u7247\u7684\u5b9e\u9645\u663e\u793a\u5927\u5c0f\u548c\u5750\u6807\uff1f<\/strong><\/p>\n<p><strong>\u89e3\u7b54\uff1a<\/strong><\/p>\n<p>\u4e3a QLabel \u8bbe\u7f6e\u4e86 setScaledContents() \u4ee5\u81ea\u9002\u5e94\u56fe\u50cf\u5927\u5c0f\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u6b65\u9aa4\u83b7\u53d6\u56fe\u50cf\u7684\u5b9e\u9645\u663e\u793a\u5927\u5c0f\u548c\u5750\u6807\uff1a<\/p>\n<ul>\n<li>\u5728\u4ee3\u7801\u4e2d\u627e\u5230\u76f8\u5e94\u7684 QLabel\u3002<\/li>\n<li>\u8c03\u7528 QLabel.size() \u65b9\u6cd5\u83b7\u53d6\u663e\u793a\u56fe\u50cf\u7684\u5927\u5c0f\u3002<\/li>\n<\/ul>\n<p><strong>\u5982\u4f55\u8ba9\u76f4\u63a5\u4f7f\u7528 QPixmap \u663e\u793a\u7684\u56fe\u7247\u81ea\u9002\u5e94\u5927\u5c0f\u5e76\u52a8\u6001\u6700\u5927\u5316\uff1f<\/strong><\/p>\n<p><strong>\u89e3\u7b54\uff1a<\/strong><\/p>\n<p>\u4f7f\u7528 QPixmap \u76f4\u63a5\u663e\u793a\u56fe\u50cf\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528 QGridLayout \u5e03\u5c40\u6765\u8c03\u6574\u56fe\u7247\u7684\u5927\u5c0f\u5e76\u5b9e\u73b0\u52a8\u6001\u6700\u5927\u5316\uff1a<\/p>\n<ul>\n<li>\u4f7f\u7528 QGridLayout \u5e03\u5c40\uff0c\u5c06 QPixmap \u6240\u5728\u7684 QLabel \u653e\u7f6e\u5728\u7f51\u683c\u4e2d\u3002<\/li>\n<li>\u8bbe\u7f6e QLabel \u5728\u7f51\u683c\u4e2d\u7684\u6700\u5927\u62c9\u4f38\u56e0\u5b50\uff0c\u4ee5\u5141\u8bb8\u5176\u52a8\u6001\u8c03\u6574\u5927\u5c0f\u3002<\/li>\n<li>\u8c03\u6574 QGridLayout \u7684\u884c\u548c\u5217\u5927\u5c0f\u7b56\u7565\uff0c\u4f7f\u5176\u6839\u636e\u53ef\u7528\u7a7a\u95f4\u8fdb\u884c\u6700\u5927\u5316\u3002<\/li>\n<\/ul>\n<p>\u672c\u7bc7\u5173\u4e8e\u300a\u4f7f\u7528 PyQt5 \u5f00\u53d1 GUI \u65f6\uff0c\u5982\u4f55\u83b7\u53d6 QLabel \u4e2d\u81ea\u9002\u5e94\u56fe\u7247\u7684\u5b9e\u9645\u663e\u793a\u5927\u5c0f\u548c\u5750\u6807\uff1f\u5982\u4f55\u8ba9 QPixmap \u663e\u793a\u7684\u56fe\u7247\u81ea\u9002\u5e94\u5927\u5c0f\u5e76\u52a8\u6001\u6700\u5927\u5316\uff1f\u300b\u7684\u4ecb\u7ecd\u5c31\u5230\u6b64\u7ed3\u675f\u5566\uff0c\u4f46\u662f\u5b66\u65e0\u6b62\u5883\uff0c\u60f3\u8981\u4e86\u89e3\u5b66\u4e60\u66f4\u591a\u5173\u4e8e\u6587\u7ae0\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u8bf7\u5173\u6ce8\u516c\u4f17\u53f7\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4f7f\u7528 PyQt5 \u5f00\u53d1 GUI &#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4925],"tags":[],"class_list":["post-204246","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/204246","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=204246"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/204246\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=204246"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=204246"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=204246"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}