I have created a Frame in QT Designer and promoted it to my custom widget, and so far everything I’ve done with it is completely fine except attempting to call paintEvent();
I have overidden a bunch of mouse functions which all work, and in these mouse functions I want to call paintEvent();
class PaintBox : public QWidget
{
Q_OBJECT
public:
PaintBox(QWidget *parent);
~PaintBox();
void mouseMoveEvent(QMouseEvent *event);
void paintEvent(QPaintEvent *e);
...
...
void PaintBox::mouseMoveEvent( QMouseEvent *event )
{
repaint();
//QPaintEvent * e = 0; //I know this is bad code, but its the only bloody way I can call paintEvent :(
//paintEvent( e);
}
void PaintBox::paintEvent( QPaintEvent *e )
{
QPainter paint(this);
getColour();
paint.setBrush(QColor(_red, _green, _blue));
paint.drawRect(0, 0, width(), height());
}
The mouseMoveEvent() works, but putting repaint() or update() in there NEVER calls paintEvent(). The only way I can seem to call paintEvent is when I resize the window, or I do that aweful workaround I commented out above.
I also never set setUpdatesEnabled() & setVisible(); these are at their defaults.. even if I do make them true in my code, paintEvent is still never called.
Appreciate any help, been googling for hours now and to my knowledge repaint() should just work.
↧