Hi,
I had the following code in qt3 and it worked perfectly (I removed resize and refresh procedures)
whiteboard.h
class Whiteboard
: public QFrame{
Q_OBJECT
public:
Whiteboard
( QWidget *parent
=0,
const char* name
= 0);
~Whiteboard()
protected:
};
class Whiteboard : public QFrame
{
Q_OBJECT
public:
QPoint qt_currMosePos;
QPoint qt_prevMousePos;
QPen *pen;
QPainter * paint;
Whiteboard( QWidget *parent=0, const char* name = 0);
~Whiteboard()
protected:
void mouseMoveEvent(QMouseEvent *);
void mousePressEvent(QMouseEvent *);
};
To copy to clipboard, switch view to plain text mode
whiteboard.cpp
#include "whiteboard.h"
Whiteboard
::Whiteboard( QWidget *parent,
const char* name
) : QFrame(parent,name
){
pen
= new QPen(Qt
::red,
2);
paint->setPen(*pen);
this->setBackgroundMode(Qt::NoBackground);
}
Whiteboard::~Whiteboard()
{
delete paint;
}
{
qt_currMousePos = e->pos();
paint->drawLine(qt_prevMousePos,qt_currMosePos);
qt_prevMousePos = qt_currMousePos;
}
{
if(e->button() == Qt::LeftButton) {
qt_prevMousePos = e->pos();
paint->drawLine(qt_prevMousePos,qt_prevMousePos);
}
}
#include "whiteboard.h"
Whiteboard::Whiteboard( QWidget *parent, const char* name) : QFrame(parent,name)
{
paint = new QPainter(this);
pen = new QPen(Qt::red,2);
paint->setPen(*pen);
this->setBackgroundMode(Qt::NoBackground);
}
Whiteboard::~Whiteboard()
{
delete paint;
}
void Whiteboard::mouseMoveEvent(QMouseEvent *e)
{
qt_currMousePos = e->pos();
paint->drawLine(qt_prevMousePos,qt_currMosePos);
qt_prevMousePos = qt_currMousePos;
}
void Whiteboard::mousePressEvent(QMouseEvent *e)
{
if(e->button() == Qt::LeftButton) {
qt_prevMousePos = e->pos();
paint->drawLine(qt_prevMousePos,qt_prevMousePos);
}
}
To copy to clipboard, switch view to plain text mode
Basically it allows you to plot on the widget with your mouse.
I compiled it under Solaris and Linux.
Now I migrated to qt4. I ran qt3to4 and recompiled it. No problems.
But when I launch the program I cannot paint and I have the following message in the console:
QPainter::begin: Widget painting can only begin as a result of a paintEvent
What has happend? Are there some new limitations in qt4?
I know that migration from qt3 has been discussed since long time ago but I cannot find any mention of this problem.
Thanks for help
Tomek
Bookmarks