#include #include class dlg : public QDialog { public: dlg() ; static QProgressBar * pb ; } ; class rainbow_widget : public QWidget { public: rainbow_widget( QWidget * p ) : QWidget(p) {} protected: virtual void paintEvent( QPaintEvent * /*ev*/ ) { QPainter p( this ) ; p.fillRect( 0, 0, 80, 20, QBrush( Qt::darkGreen ) ) ; QBrush colors[4] = { QBrush( Qt::black ) , QBrush( Qt::cyan ) , QBrush( Qt::red ) , QBrush( Qt::magenta ) } ; for( int i = 0; i < 4 ; ++ i ) { int const thickness = 5 ; int y = i * thickness ; p.fillRect( 0, y, 80, thickness, colors[i] ) ; dlg::pb->setValue( i + 1 ) ; } } } ; dlg::dlg() { resize( 100, 100 ) ; pb = new QProgressBar( this ) ; pb->setGeometry( 10, 50, 80, 20 ) ; pb->setTextVisible( false ) ; pb->setRange( 0, 4 ) ; rainbow_widget * rw = new rainbow_widget( this ) ; rw->setGeometry( 10, 10, 80, 20 ) ; } QProgressBar * dlg::pb = 0 ; int main(int argc, char *argv[]) { QApplication app(argc, argv); dlg d ; d.exec() ; return 0 ; }