PDA

View Full Version : QPaintEvent on button click?



vishal.chauhan
5th June 2007, 08:11
Hi All,

I m using Qt 4.1.5 on my Mac.
I have a paintEvent which is called itself when I create the object of the class having paintEvent().

Now I want to call the paintEvent on a Button click which is in another class because I m filling the color in the rect on paintevnt and I want to see it column by column.

But if it is called in the constructor then the whole rect are fill when screen comes up so I want this to be done on button click.

If any body knows then plz help me.

thanks.

patrik08
5th June 2007, 08:44
You can subclass a QLabel and append the clik event how you like.





void FullEdit::PaintDirtyStatus( bool e )
{
QString textd = "nulltext overwrite";
QPixmap pix(140,22); ///// take from label
if (e) {
pix.fill(QColor("crimson")); /* red */
textd = tr("Upload Pending.");
} else {
pix.fill(QColor("lime")); /* green */
textd = tr("Not Upload.");
}
QPainter painter(&pix);

QColor textColor = QColor(255,255,255);
QPen pen;
pen.setStyle( Qt::SolidLine );
pen.setColor(textColor);
QFont f( "arial", 8, QFont::Bold );
painter.setFont( f );
painter.setPen( pen);
QFontMetrics fm = painter.fontMetrics();
int largo = fm.width(textd);
painter.drawText(QPointF((pix.width() / 2) - (largo / 2),15),textd);
dirtystartus->setPixmap(pix); /* label */

}