Qt+C++ realizes the light strip animation movement position transformation and moves the marquee picture carousel

 Featured program examples

Qt+C++ realizes the light strip animation movement position transformation and moves the marquee picture carousel

If you need to install the operating environment or remote debugging, see the personal QQ business card at the bottom of the article, and professional and technical personnel will assist remotely!

foreword

This blog writes code for <<Qt+C++ Realizes Light Strip Animation Motion Position Change, Moving Marquee Picture Carousel>>, the code is neat, regular and easy to read. The first choice for learning and application recommendation.


Article directory

1. Required tool software

2. Use steps

        1. Import library

        2. Code implementation

        3. Running results

3. Online assistance

1. Required tool software

1. VS, Qt

2. C++

2. Use steps

1. Import library

#include "MainWindow.h"

#include<iostream>
#include <QDebug>
#include <QFile>
#include <QTimer>
#include<QImage>
#include<QPixmap>
#include<QTransform>
#include<QPropertyAnimation>
#include<QGraphicsPixmapItem>
#include<QGraphicsScene>
#include <QtConcurrent/QtConcurrent>
#include <QPainter>

2. Code implementation

code show as below:

class MarqueeWidget : public QWidget {
public:
    MarqueeWidget(QWidget *parent = nullptr) : QWidget(parent) {
        setFixedSize(400, 100);
        
        label = new QLabel(this);
        label->setGeometry(0, 0, width(), height());
        
        timer = new QTimer(this);
        connect(timer, &QTimer::timeout, this, &MarqueeWidget::updateMarquee);
        
        marqueeText = "This is a marquee text.";
        marqueeIndex = 0;
        
        startMarquee();
    }
    
    void startMarquee() {
        if (!timer->isActive()) {
            timer->start(100); // 设置滚动速度,单位为毫秒
        }
    }
    
    void stopMarquee() {
        if (timer->isActive()) {
            timer->stop();
        }
    }
    
    void updateMarquee() {
        const int textLength = marqueeText.length();
        const int visibleLength = width() / fontMetrics().averageCharWidth();
        
        if (textLength <= visibleLength) {
            label->setText(marqueeText);
            return;
        }
        
        QString displayText = marqueeText.mid(marqueeIndex) + marqueeText.left(marqueeIndex);
        label->setText(displayText);
        
        marqueeIndex++;
        if (marqueeIndex >= textLength) {
            marqueeIndex = 0;
        }
    }
    
private:
    QLabel *label;
    QTimer *timer;
    QString marqueeText;
    int marqueeIndex;
};

3. Running results

 

 

3. Online assistance:

If you need to install the operating environment or remote debugging, see the personal QQ business card at the bottom of the article, and professional and technical personnel will assist remotely!
1) Remote installation and operation environment, code debugging
2) Qt, C++, Python entry guide
3) Interface beautification
4) Software production

Current article link: Python+Qt desktop and webpage human customer service communication tool_alicema1111's blog-CSDN blog

Blogger recommended article: python face recognition statistics qt form - CSDN Blog

Blogger recommended article: Python Yolov5 flame smoke recognition source code sharing - CSDN blog

                         Python OpenCV recognizes the number of people entering and exiting the pedestrian entrance - python recognizes the number of people - CSDN Blog

Personal blog homepage: alicema1111's blog_CSDN blog-Python, C++, bloggers in the field of web pages

Click here for all the blogger's articles : alicema1111's blog_CSDN blog-Python, C++, bloggers in the field of web pages

Guess you like

Origin blog.csdn.net/alicema1111/article/details/132139363