QT里滚动字幕怎么做?

dior_jadore 2010-12-01 09:58:35
请问,QT里滚动字幕怎么做?就是从一个文本文件中读出字符串,然后显示出来,不过要不停的滚动显示。
...全文
1904 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
hsmobei 2012-07-02
  • 打赏
  • 举报
回复
楼上的会报错 label变量没有声明。
west__wind 2010-12-01
  • 打赏
  • 举报
回复
QML的话 可以这么做

import Qt 4.7

Rectangle {
id: screen

property int pixelSize: screen.height * 1.25
property color textColor: "lightsteelblue"
property string text: "Hello world! "

width: 640; height: 320
color: "steelblue"

Row {
y: -screen.height / 4.5

NumberAnimation on x { from: 0; to: -text.width; duration: 6000; loops: Animation.Infinite }
Text { id: text; font.pixelSize: screen.pixelSize; color: screen.textColor; text: screen.text }
Text { font.pixelSize: screen.pixelSize; color: screen.textColor; text: screen.text }
Text { font.pixelSize: screen.pixelSize; color: screen.textColor; text: screen.text }
}
}
gemfield 2010-12-01
  • 打赏
  • 举报
回复
重新实现paintevent,使用drawText方法
dior_jadore 2010-12-01
  • 打赏
  • 举报
回复
弄一个文本框 不停的循环位移

这个怎么做?另外,怎么控制循环移位?
白马驾虹霓 2010-12-01
  • 打赏
  • 举报
回复
最简单的方法就是弄一个文本框 不停的循环位移。。其他的不会
newstarthere 2010-12-01
  • 打赏
  • 举报
回复
我也不知道怎么做,帮你顶一下
jasonslaex 2010-12-01
  • 打赏
  • 举报
回复
#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QTimer>
#include <string>
namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
Q_OBJECT

public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
protected slots:
void TimeOut();

private:
QTimer *timer;
std::string temp_str;
int pos;
Ui::MainWindow *ui;
};


#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent):
QMainWindow(parent),ui(new Ui::MainWindow)
{
ui->setupUi(this);
timer=new QTimer(this);
QObject::connect(timer,SIGNAL(timeout()),this,SLOT(TimeOut()));

timer->start(500);
temp_str="hello,world,this is scroll text!!";
pos=0;
}

void MainWindow::TimeOut()
{
if(pos>temp_str.length())
pos=0;
ui->label->setText(temp_str.substr(pos).c_str());
pos++;
}

MainWindow::~MainWindow()
{
delete ui;
}

jasonslaex 2010-12-01
  • 打赏
  • 举报
回复
在QTIME里面把一个qstring的子字符串赋值给qtextedit就行了,一段一段复制。不就是滚动效果了吗
wyfwx 2010-12-01
  • 打赏
  • 举报
回复
animation

16,203

社区成员

发帖
与我相关
我的任务
社区描述
Qt 是一个跨平台应用程序框架。通过使用 Qt,您可以一次性开发应用程序和用户界面,然后将其部署到多个桌面和嵌入式操作系统,而无需重复编写源代码。
社区管理员
  • Qt
  • 亭台六七座
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧