{"id":377,"date":"2025-12-19T12:26:07","date_gmt":"2025-12-19T04:26:07","guid":{"rendered":"https:\/\/whaledream.xyz\/?p=377"},"modified":"2025-12-19T21:34:31","modified_gmt":"2025-12-19T13:34:31","slug":"qt%e8%87%aa%e5%ae%9a%e4%b9%89%e6%8e%a7%e4%bb%b6-%e6%b6%88%e6%81%af%e5%bc%b9%e7%aa%97","status":"publish","type":"post","link":"https:\/\/whaledream.xyz\/index.php\/2025\/12\/19\/qt%e8%87%aa%e5%ae%9a%e4%b9%89%e6%8e%a7%e4%bb%b6-%e6%b6%88%e6%81%af%e5%bc%b9%e7%aa%97\/","title":{"rendered":"Qt\u81ea\u5b9a\u4e49\u63a7\u4ef6-\u6d88\u606f\u5f39\u7a97"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u5728\u8f6f\u4ef6\u4f7f\u7528\u8fc7\u7a0b\u4e2d\uff0c\u7ecf\u5e38\u9700\u8981\u5bf9\u4e00\u4e9b\u9192\u76ee\u7684\u65e5\u5fd7\u8fdb\u884c\u5f39\u7a97\u63d0\u793a\uff0c\u5c24\u5176\u662f\u5bf9\u4e8e\u9519\u8bef\u548c\u8b66\u544a\u7ea7\u522b\u7684\u65e5\u5fd7\uff0c\u9700\u8981\u8fdb\u884c\u7279\u6b8a\u63d0\u793a\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e3a\u4ec0\u4e48\u4e0d\u5168\u90e8\u4f7f\u7528QMessage\u8fdb\u884c\u5f39\u7a97\u663e\u793a\u5462\uff1f<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u679c\u51fa\u73b0\u5927\u91cf\u7684\u65e5\u5fd7\u9700\u8981\u63d0\u793a\uff0c\u90a3\u4e48QMessage\u4f1a\u5168\u90e8\u5806\u53e0\u5728\u7a97\u53e3\uff0c\u51fa\u73b0\u4e3b\u7a0b\u5e8f\u963b\u585e\u3002QMessage\u8981\u6c42\u7528\u6237\u5fc5\u987b\u70b9\u51fb\u786e\u8ba4\u6309\u94ae\u6216\u5728\u5176\u4ed6QPushButton\u5b9e\u73b0\u7684\u6309\u94ae\u540e\u624d\u53ef\u7ee7\u7eed\u4e0b\u53bb\u3002\u4e00\u822cQMessage\u8bbe\u7f6e\u4e3a\u6a21\u6001\uff0c\u4f46\u4e5f\u53ef\u8bbe\u7f6e\u4e3a\u975e\u6a21\u6001\u3002\u867d\u7136\u8bbe\u7f6e\u4e3a\u975e\u6a21\u6001\u540e\u4e0d\u4f1a\u51fa\u73b0\u4e3b\u7a0b\u5e8f\u963b\u585e\u95ee\u9898\uff0c\u4f46\u8fd8\u662f\u4f1a\u5806\u53e0\u5f39\u7a97\uff0c\u4e14\u6ca1\u6709\u786e\u8ba4\u6309\u94ae\u7684QMessage\u7f3a\u5931\u4e86\u5176\u672c\u8eab\u7684\u610f\u4e49\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img fetchpriority=\"high\" decoding=\"async\"  src=\"https:\/\/whaledream.xyz\/wp-content\/themes\/lolimeow\/assets\/images\/loading.gif\" data-src=\"https:\/\/whaledream.xyz\/wp-content\/uploads\/2025\/12\/pop-3.gif\" class=\"lazy\" loading=\"lazy\" alt=\"\" class=\"wp-image-413\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u4f55\u8bbe\u8ba1\u4e00\u4e2a\u4fbf\u6377\u7684\u6d88\u606f\u5f39\u7a97\uff1f<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6838\u5fc3\u5c31\u662f\u5c06\u65e5\u5fd7\u6d88\u606f\u653e\u7f6e\u4e8e\u4e00\u4e2a\u961f\u5217\u4e2d\uff0c\u4e0d\u65ad\u5c06\u65e5\u5fd7\u51fa\u961f\u5217\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6d88\u606f\u4e2d\u8bbe\u7f6eQPropertyAnimation\u52a8\u753b\u3002\u52a8\u753b\u5185\u5bb9\u4e3a\u6d88\u606f\u7f13\u6162\u4e0a\u79fb\uff0c\u6d88\u606f\u4f1a\u5728\u52a8\u753b\u7ed3\u675f\u540e\u81ea\u52a8\u91ca\u653e\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>void MessageItem::AppearAnimation()\n{\n    QPropertyAnimation *animation = new QPropertyAnimation(this, \"geometry\");\n    animation-&gt;setDuration(20);\n    animation-&gt;setStartValue(\n        QRect(pos().x(), pos().y() - nMessageItemMargin, width_, height_));\n    animation-&gt;setEndValue(QRect(pos().x(), pos().y(), width_, height_));\n    animation-&gt;start(QAbstractAnimation::DeletionPolicy::DeleteWhenStopped);\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u6d88\u606f\u7ed3\u675f\u65f6\u589e\u52a0\u900f\u660e\u6548\u679c\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>void MessageItem::DisappearAnimation()\n{\n    QGraphicsOpacityEffect *pOpacity = new QGraphicsOpacityEffect(this);\n    pOpacity-&gt;setOpacity(1);\n    setGraphicsEffect(pOpacity);\n\n    QPropertyAnimation *pOpacityAnimation2 =\n        new QPropertyAnimation(pOpacity, \"opacity\");\n    pOpacityAnimation2-&gt;setDuration(500);\n    pOpacityAnimation2-&gt;setStartValue(1);\n    pOpacityAnimation2-&gt;setEndValue(0);\n\n    pOpacityAnimation2-&gt;start(\n        QAbstractAnimation::DeletionPolicy::DeleteWhenStopped);\n\n    connect(pOpacityAnimation2, &amp;QPropertyAnimation::finished, this, &#91;&amp;]() {\n        emit itemRemoved(this);\n        deleteLater();\n    });\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u6d88\u606f\u5165\u961f\u5217<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>void Message::Push(MessageType type, QString content)\n{\n    std::unique_lock&lt;std::mutex&gt; lck(mtx_);\n    int height = 0;\n    for_each(messages_.begin(), messages_.end(),\n             &#91;&amp;height](MessageItem *pTp) mutable {\n                 height += (nMessageItemMargin + pTp-&gt;height());\n             });\n    MessageItem *pItem =\n        new MessageItem(qobject_cast&lt;QWidget *&gt;(parent()), type, content);\n    connect(pItem, &amp;MessageItem::itemReadyRemoved, this,\n            &amp;Message::adjustItemPos);\n    connect(pItem, &amp;MessageItem::itemRemoved, this, &amp;Message::removeItem);\n    pItem-&gt;SetDuration(duration_);\n    height += nMessageItemMargin;\n    pItem-&gt;move(QPoint((width_ - pItem-&gt;width()) \/ 2, height));\n    messages_.emplace_back(pItem);\n    pItem-&gt;Show();\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u6d88\u606f\u9500\u6bc1<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>void Message::removeItem(MessageItem *pItem)\n{\n    std::unique_lock&lt;std::mutex&gt; lck(mtx_);\n    for (auto itr = messages_.begin(); itr != messages_.end();) {\n        if (*itr == pItem) {\n            messages_.erase(itr);\n            break;\n        } else\n            ++itr;\n    }\n    int height = nMessageItemMargin;\n    for_each(messages_.begin(), messages_.end(), &#91;&amp;](MessageItem *item) {\n        QPropertyAnimation *pAnimation1 =\n            new QPropertyAnimation(item, \"geometry\", this);\n        pAnimation1-&gt;setDuration(300);\n        pAnimation1-&gt;setStartValue(QRect(item-&gt;pos().x(), item-&gt;pos().y(),\n                                         item-&gt;width(), item-&gt;height()));\n        pAnimation1-&gt;setEndValue(\n            QRect(item-&gt;pos().x(), height, item-&gt;width(), item-&gt;height()));\n\n        pAnimation1-&gt;start(\n            QAbstractAnimation::DeletionPolicy::DeleteWhenStopped);\n        height += (nMessageItemMargin + item-&gt;height());\n    });\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/gitcode.com\/qq_43542491\/notification_popup.git\" data-type=\"link\" data-id=\"https:\/\/gitcode.com\/qq_43542491\/notification_popup.git\">\u4f20\u9001\u95e8<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u8f6f\u4ef6\u4f7f\u7528\u8fc7\u7a0b\u4e2d\uff0c\u7ecf\u5e38\u9700\u8981\u5bf9\u4e00\u4e9b\u9192\u76ee\u7684\u65e5\u5fd7\u8fdb\u884c\u5f39\u7a97\u63d0\u793a\uff0c\u5c24\u5176\u662f\u5bf9\u4e8e\u9519\u8bef\u548c\u8b66\u544a\u7ea7\u522b\u7684\u65e5\u5fd7\uff0c\u9700\u8981\u8fdb\u884c\u7279\u6b8a\u63d0\u793a\u3002 \u4e3a\u4ec0\u4e48\u4e0d\u5168\u90e8\u4f7f\u7528QMessage\u8fdb\u884c\u5f39\u7a97\u663e\u793a\u5462\uff1f \u5982\u679c\u51fa\u73b0\u5927\u91cf\u7684\u65e5\u5fd7\u9700\u8981\u63d0\u793a\uff0c\u90a3\u4e48QMessage\u4f1a\u5168\u90e8\u5806\u53e0\u5728\u7a97\u53e3\uff0c\u51fa\u73b0\u4e3b\u7a0b\u5e8f\u963b\u585e\u3002QMessage\u8981\u6c42\u7528\u6237\u5fc5\u987b\u70b9\u51fb\u786e\u8ba4\u6309\u94ae\u6216\u5728\u5176\u4ed6QPushButton\u5b9e\u73b0\u7684\u6309\u94ae\u540e\u624d\u53ef\u7ee7\u7eed\u4e0b\u53bb\u3002\u4e00\u822cQMessage\u8bbe\u7f6e\u4e3a\u6a21\u6001\uff0c\u4f46\u4e5f\u53ef\u8bbe\u7f6e\u4e3a\u975e\u6a21\u6001\u3002\u867d\u7136\u8bbe\u7f6e\u4e3a\u975e [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":415,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[5,4],"tags":[33],"class_list":["post-377","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-c","category-qt","tag-qt"],"jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"https:\/\/whaledream.xyz\/wp-content\/uploads\/2025\/12\/Screenshot-from-2025-12-19-11-50-08.png","_links":{"self":[{"href":"https:\/\/whaledream.xyz\/index.php\/wp-json\/wp\/v2\/posts\/377","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/whaledream.xyz\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/whaledream.xyz\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/whaledream.xyz\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/whaledream.xyz\/index.php\/wp-json\/wp\/v2\/comments?post=377"}],"version-history":[{"count":0,"href":"https:\/\/whaledream.xyz\/index.php\/wp-json\/wp\/v2\/posts\/377\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/whaledream.xyz\/index.php\/wp-json\/wp\/v2\/media\/415"}],"wp:attachment":[{"href":"https:\/\/whaledream.xyz\/index.php\/wp-json\/wp\/v2\/media?parent=377"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/whaledream.xyz\/index.php\/wp-json\/wp\/v2\/categories?post=377"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/whaledream.xyz\/index.php\/wp-json\/wp\/v2\/tags?post=377"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}