class TLwidget : public QWidget{... void timeout();...protected: void paintEvent(QPaintEvent*);...};void TLwidget::timeout(){... update(); qDebug()<<"drawn";}void TLwidget::paintEvent(QPaintEvent*){ QPainter p(this); p.fillRect( geometry(), QBrush(backcolor) ); p.setPen( QPen(forecolor) ); p.setFont(font); p.drawText( xpos, ypos, text );}
C++ (Qt) p.fillRect( geometry(), QBrush(backcolor) );
C++ (Qt)#include "widget.h"#include <QPainter>#include <QTimer> Widget::Widget( QWidget *parent ) : QWidget( parent ), tick( true ), timer( new QTimer( this ) ){ connect( timer, SIGNAL(timeout()), SLOT(timeout()) ); timer->setInterval( 1000 ); timer->setSingleShot( false ); timer->start();} void Widget::timeout(){ tick = !tick; update();} void Widget::paintEvent( QPaintEvent * ){ QPainter p( this ); p.fillRect( rect(), QBrush( tick? Qt::blue : Qt::darkBlue ) ); p.setPen( QPen( Qt::yellow ) ); p.drawText( 20, 20, "Test string" );}