// myMI.h
#include <QWidget>
class MarqueeImage
: public QWidget{
Q_OBJECT
public:
protected slots:
private:
QImage top_img;
// top part of the image minus 10 lines QImage bot_img;
// bottom 10 lines QImage *full_img;
// temporary image int myheight; // height of image
int mywidth; // width of image
int line_shift; // bottom 10 lines
};
// myMI.cpp
#include “myMI.hâ€
#include <QPainter>
#include <QTimer>
MarqueeImage
::MarqueeImage(QWidget *parent
){
mywidth = 200; //bitmap width
myheight = 300; //bitmap height
line_shift = 10; //number of lines being moved from bottom to top
full_img->load(“mybmp.bmpâ€);
connect(timer, SIGNAL(timeout()), this, SLOT(update()));
timer->start(500);
}
{
top_img = full_img->copy(0, 0, mywidth-1, myheight-shift-1);
bot_img = full_img->copy(0, myheight-line_shift-1, mywidth-1, shift);
painter.drawImage(0, 0, bot_img);
painter.drawImage(0, shift, top_img);
// This is where it doesn’t work
paint_all.drawImage(0, 0, bot_img);
paint_all.drawImage(0, shift, top_img);
}
// main.cpp
#include <QApplication>
#include “myMI.hâ€
int main(int argc, char *argv[])
{
Qapplication app(argc, argv);
MarqueeImage myMI;
myMI.show();
return app.exec();
}
// myMI.h
#include <QWidget>
class MarqueeImage : public QWidget
{
Q_OBJECT
public:
MarqueeImage(QWidget *parent = 0);
protected slots:
void paintEvent(QPaintEvent *event);
private:
QImage top_img; // top part of the image minus 10 lines
QImage bot_img; // bottom 10 lines
QImage *full_img; // temporary image
int myheight; // height of image
int mywidth; // width of image
int line_shift; // bottom 10 lines
};
// myMI.cpp
#include “myMI.hâ€
#include <QPainter>
#include <QTimer>
MarqueeImage::MarqueeImage(QWidget *parent)
: QWidget(parent)
{
mywidth = 200; //bitmap width
myheight = 300; //bitmap height
line_shift = 10; //number of lines being moved from bottom to top
full_img = new QImage();
full_img->load(“mybmp.bmpâ€);
QTimer *timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(update()));
timer->start(500);
}
void MarqueeImage::paintEvent(QPaintEvent *)
{
QPainter painter(this);
top_img = full_img->copy(0, 0, mywidth-1, myheight-shift-1);
bot_img = full_img->copy(0, myheight-line_shift-1, mywidth-1, shift);
painter.drawImage(0, 0, bot_img);
painter.drawImage(0, shift, top_img);
// This is where it doesn’t work
QPainter paint_all(full_img);
paint_all.drawImage(0, 0, bot_img);
paint_all.drawImage(0, shift, top_img);
}
// main.cpp
#include <QApplication>
#include “myMI.hâ€
int main(int argc, char *argv[])
{
Qapplication app(argc, argv);
MarqueeImage myMI;
myMI.show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks