53<\/div>\n<\/td>\n
\n\n void<\/code> MainWindow::resizeEvent(QResizeEvent* event)<\/code><\/div>\n{<\/code><\/div>\n <\/code>QSize size = event->size();<\/code><\/div>\n<\/div>\n <\/code>float<\/code> scaleX = size.width() \/ 1920.0f;<\/code>\/\/\u539f\u59cb\u5206\u8fa8\u7387<\/code><\/div>\n <\/code>float<\/code> scaleY = size.height() \/ 1080.0f;<\/code><\/div>\n <\/code>float<\/code> scale = std::min(scaleX, scaleY);<\/code>\/\/\u4e0d\u662f\u7b49\u6bd4\u7f29\u653e\u65f6\uff0c\u9009\u62e9\u6700\u5c0f\u7684\u7f29\u653e\u6bd4\uff0c\u53ef\u4ee5\u901a\u8fc7\u81ea\u52a8\u5e03\u5c40\u8c03\u6574\u7a97\u53e3\u4f4d\u7f6e<\/code><\/div>\n<\/div>\n <\/code>const<\/code> QObjectList& list = <\/code>this<\/code>->children();<\/code>\/\/\u679a\u4e3e\u5b50\u7a97\u53e3\uff0c\u5e76\u8bbe\u7f6e\u5927\u5c0f<\/code><\/div>\n <\/code>foreach(QObject* obj, list) {<\/code><\/div>\n <\/code>if<\/code> (obj->isWidgetType()) {<\/code><\/div>\n <\/code>QWidget* child = (QWidget*)obj;<\/code><\/div>\n <\/code>if<\/code> (std::<\/code>abs<\/code>(scale - _lastScale) > 0.03) {<\/code>\/\/\u5f53\u7f29\u653e\u6bd4\u4f8b\u8d85\u8fc7\u9608\u503c\u65f6\u624d\u8fdb\u884c\uff0c\u56e0\u4e3a\u7a97\u53e3\u5bbd\u9ad8\u662f\u6574\u6570\uff0c\u9891\u7e41\u7f29\u653e\u4f1a\u4f7f\u7a97\u53e3\u53d8\u5f62<\/code><\/div>\n <\/code>scaleChildWidget(child, scale \/ _lastScale);<\/code><\/div>\n <\/code>}<\/code><\/div>\n <\/code>}<\/code><\/div>\n <\/code>}<\/code><\/div>\n <\/code><\/div>\n <\/code>if<\/code> (std::<\/code>abs<\/code>(scale - _lastScale) > 0.03) {<\/code><\/div>\n <\/code>_lastScale = scale;<\/code><\/div>\n <\/code>}<\/code><\/div>\n}<\/code><\/div>\n<\/div>\n void<\/code> MainWindow::scaleChildWidget(QWidget* widget, <\/code>float<\/code> scale)<\/code><\/div>\n{<\/code><\/div>\n <\/code>const<\/code> QObjectList& list = widget->children();<\/code><\/div>\n <\/code>foreach(QObject* obj, list) {<\/code><\/div>\n <\/code>if<\/code> (obj->isWidgetType()) {<\/code><\/div>\n <\/code>QWidget* child = (QWidget*)obj;<\/code><\/div>\n<\/div>\n <\/code>if<\/code> (scale < 1) {<\/code><\/div>\n <\/code>scaleChildWidget(child, scale);<\/code>\/\/\u5904\u7406\u6240\u6709\u5b50\u7a97\u53e3<\/code><\/div>\n <\/code>}<\/code><\/div>\n<\/div>\n <\/code>QSize max = child->maximumSize();<\/code><\/div>\n <\/code>QSize min = child->minimumSize();<\/code><\/div>\n <\/code>if<\/code> (max.width() < 65536) {<\/code>\/\/\u5b50\u7a97\u53e3\u9700\u8981\u8bbe\u7f6e\u521d\u59cb\u503c<\/code><\/div>\n <\/code>child->setMaximumSize(max * scale);<\/code><\/div>\n <\/code>}<\/code><\/div>\n <\/code>if<\/code> (min.width() > 0) {<\/code><\/div>\n <\/code>child->setMinimumSize(min * scale);<\/code><\/div>\n <\/code>}<\/code><\/div>\n<\/div>\n <\/code>QFont font = child->font();<\/code>\/\/\u7f29\u653e\u5b57\u4f53<\/code><\/div>\n <\/code>font.setPointSizeF(font.pointSizeF() * scale);<\/code><\/div>\n <\/code>child->setFont(font);<\/code><\/div>\n<\/div>\n <\/code>if<\/code> (scale > 1) {<\/code><\/div>\n <\/code>scaleChildWidget(child, scale);<\/code><\/div>\n <\/code>}<\/code><\/div>\n <\/code>}<\/code><\/div>\n <\/code>}<\/code><\/div>\n}<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"\u901a\u8fc7\u4fee\u6539\u5b50\u7a97\u53e3\u5927\u5c0f\u53ca\u5b57\u53f7\uff0c\u9002\u5e94\u4efb\u610f\u5206\u8fa8\u7387\u3002 \n1.\u65b9\u6cd5\u63cf\u8ff0 \n \uff081\uff09\u4f7f\u7528setMaximumSize\u3001setMinimumSize\u51fd\u6570\u4fee\u6539\u5b50\u7a97\u53e3\u5927\u5c0f\uff0c\u4f7f\u5176\u8ddf\u968f\u4e3b\u7a97\u53e3\u53d8\u5316\uff1b \n\uff082\uff09\u5bbd\u3001\u9ad8\u7f29\u653e\u6bd4\u4f8b\u4e0d\u540c\u65f6\uff0c\u901a\u8fc7qt\u7684\u81ea\u52a8\u5e03\u5c40\u529f\u80fd\uff0c\u8c03\u6574\u5b50\u7a97\u53e3\u7684\u4f4d\u7f6e\uff1b \n\uff083\uff09\u901a\u8fc7setPointSizeF\u51fd\u6570\u63a7\u5236\u5b57\u4f53\u53d8\u5316\u3002<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19],"tags":[20,22,21],"_links":{"self":[{"href":"https:\/\/blog.simbot.net\/wp-json\/wp\/v2\/posts\/77"}],"collection":[{"href":"https:\/\/blog.simbot.net\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.simbot.net\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.simbot.net\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.simbot.net\/wp-json\/wp\/v2\/comments?post=77"}],"version-history":[{"count":8,"href":"https:\/\/blog.simbot.net\/wp-json\/wp\/v2\/posts\/77\/revisions"}],"predecessor-version":[{"id":118,"href":"https:\/\/blog.simbot.net\/wp-json\/wp\/v2\/posts\/77\/revisions\/118"}],"wp:attachment":[{"href":"https:\/\/blog.simbot.net\/wp-json\/wp\/v2\/media?parent=77"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.simbot.net\/wp-json\/wp\/v2\/categories?post=77"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.simbot.net\/wp-json\/wp\/v2\/tags?post=77"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}} |