I made a program with Qt3, it collects a continues datastream from the comport and
paints several curves on the screen (almost realtime like an osciloscope). I accomplished
this by painting directly on the widget without double buffering. Disadvantage was that
the screen wasn't refreshed when another window was placed on the screen. The big
advantage was that the programn was fast and didn't use much memory, this program
was able to run on older computers.
I rewrote this program for Qt4 and then the problems started, in Qt4 it's not possible
anymore to paint on a widget outside a paintevent (except for Linux/X11).
So I used another approach, I created a QPixmap (1200x800), do all the painting
on the pixmap and then add the pixmap to a QLabel 50 times a second. This approach
works only on fast computers (P4 2.6GHz), on older computers (P2 450MHz) this program
was unusable.
So, now I'm trying to rewrite the program again using the QPaintEvent.
The problem here is that I don't want to update the whole mainwindow but only the
painting area (1200x800) 50 times a second. That's why I created a widget that
inherits QWidget. I use this widget in my QMainwindow. Now I'm able to paint
during using the QPaintEvent but there is another problem. To paint usefull curves,
I need the data of almost all the variables and widgets from the parent (the
QMainwindow) but in the paintingwidget I can't access them. How can I accomplish this?
painterwidget.h
#ifndef UI_PAINWIDGET_H
#define UI_PAINTERWIDGET_H
#include <QWidget>
#include <QtGui>
class PainterWidget
: public QWidget{
Q_OBJECT
public:
PainterWidget
(QWidget *parent
= 0);
protected:
};
#endif
#ifndef UI_PAINWIDGET_H
#define UI_PAINTERWIDGET_H
#include <QWidget>
#include <QtGui>
class PainterWidget : public QWidget
{
Q_OBJECT
public:
PainterWidget(QWidget *parent = 0);
protected:
void paintEvent(QPaintEvent *event);
};
#endif
To copy to clipboard, switch view to plain text mode
painterwidget.cpp
#include "painterwidget.h"
{
setFixedSize(1200, 800);
setAttribute(Qt::WA_OpaquePaintEvent);
}
{
painter.setPen(Qt::red);
painter.drawLine etc. etc.
here comes all the stuf to paint the curves
}
#include "painterwidget.h"
PainterWidget::PainterWidget(QWidget *parent) : QWidget(parent)
{
setFixedSize(1200, 800);
setAttribute(Qt::WA_OpaquePaintEvent);
}
void PainterWidget::paintEvent(QPaintEvent *)
{
QPainter painter(this);
painter.setPen(Qt::red);
painter.drawLine etc. etc.
here comes all the stuf to paint the curves
}
To copy to clipboard, switch view to plain text mode
Bookmarks