{"id":848,"date":"2024-11-07T16:16:31","date_gmt":"2024-11-07T08:16:31","guid":{"rendered":"https:\/\/fwq.ai\/blog\/848\/"},"modified":"2024-11-07T16:16:31","modified_gmt":"2024-11-07T08:16:31","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:\/\/fwq.ai\/blog\/848\/","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><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1061\" src=\"https:\/\/fwq.ai\/blog\/wp-content\/uploads\/2024\/11\/173002356381888.jpg\" width=\"800\" height=\"320\" srcset=\"https:\/\/fwq.ai\/blog\/wp-content\/uploads\/2024\/11\/173002356381888.jpg 800w, https:\/\/fwq.ai\/blog\/wp-content\/uploads\/2024\/11\/173002356381888-300x120.jpg 300w, https:\/\/fwq.ai\/blog\/wp-content\/uploads\/2024\/11\/173002356381888-768x307.jpg 768w, https:\/\/fwq.ai\/blog\/wp-content\/uploads\/2024\/11\/173002356381888-670x268.jpg 670w\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" title=\"\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\u63d2\u56fe\" alt=\"\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\u63d2\u56fe\" \/><\/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>\u4ee5\u4e0a\u5c31\u662f\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\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Python PyQt5 \u4e2d\u5e38\u89c1\u7684\u4e24\u4e2a\u95ee\u9898 \u5728\u4f7f\u7528 PyQt5 \u8fdb\u884c GUI \u5f00\u53d1\u65f6\uff0c\u4ee5\u4e0b\u4e24\u4e2a\u95ee\u9898\u7ecf\u5e38\u4f1a\u9047\u5230\uff1a \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 \u89e3\u7b54\uff1a \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 \u5728\u4ee3\u7801\u4e2d\u627e\u5230\u76f8\u5e94\u7684 QLabel\u3002 \u8c03\u7528 QLabel.size() \u65b9\u6cd5\u83b7\u53d6\u663e\u793a\u56fe\u50cf\u7684\u5927\u5c0f\u3002 \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 \u89e3\u7b54\uff1a \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 \u4f7f\u7528 QGridLayout \u5e03\u5c40\uff0c\u5c06 QPixmap \u6240\u5728\u7684 QLabel \u653e\u7f6e\u5728\u7f51\u683c\u4e2d\u3002 \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 \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 \u4ee5\u4e0a\u5c31\u662f\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\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-848","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/848","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=848"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/848\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=848"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=848"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=848"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}