日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Qt实现文字滚动、翻动动画

發布時間:2024/5/14 编程问答 42 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Qt实现文字滚动、翻动动画 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Qt實現文字滾動、翻動動畫方式不唯一,這里嘗試了2個手段。

  • 基于動畫類:QPropertyAnimation

  • 使用QLabel的QPainter動態繪制

  • ?

    具體來看:

    ? ? A.使用動畫類QPropertyAnimation:

    具體可以參考blog:https://www.cnblogs.com/lvdongjie/p/4366092.html

    簡單來說,就幾句話:

    QPropertyAnimation在內的一簇類是Qt里用來實現動畫的

    QPropertyAnimation的動畫可以針對所有的QWidget控件進行動態屬性變化

    位置類的變化(geometry):簡單的可以設置起點、終點、大小、運動時間,然后就自動完成動作

    // initm_TopPropertyAnimation = new QPropertyAnimation(this);// bindm_TopPropertyAnimation->setTargetObject(m_TopLabel);m_TopPropertyAnimation->setPropertyName("geometry");// set 動畫的起點、終點、持續時間m_TopPropertyAnimation->setDuration(1000);m_TopPropertyAnimation->setStartValue(QRect(0, 0, width, height));m_TopPropertyAnimation->setEndValue(QRect(0, -height, width, height));// 啟動和結束m_TopPropertyAnimation->start();m_TopPropertyAnimation->stop();

    ?

    ?? B.使用空間的QPainter繪制功能:

    這個思路:是將顯示的內容做動態繪制,應該能實現的是圖片和文字。

    關鍵在于,重寫paintEvent:

    void TextTicker::paintEvent(QPaintEvent *event){// __super::paintEvent(event);QPainter painter(this);painter.drawText(0 - m_curIndex, 30, m_showText);painter.drawText(m_totalWidth - m_curIndex, 30, m_showText);}

    這個paintEvent需要基于一個自定義的計時器來觸發,從而形成連貫動畫

    QTimer *timer = new QTimer(this);connect(timer, &QTimer::timeout, this, &TextTicker::updateIndex);timer->start(60);void TextTicker::updateIndex(){update();m_curIndex++;if (m_curIndex > m_totalWidth){m_curIndex = 0;}}

    ?

    總結

    以上是生活随笔為你收集整理的Qt实现文字滚动、翻动动画的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。