PDA

View Full Version : Repaint Event



Seema Rao
25th April 2006, 14:25
Hi all,

I have a problem with respect to paint event, I have a class ToolButton derived from QToolButton, here is its paintEvent implementation. Even though I set the instance of ToolButton as, setGeometry(10,10,60,60), I get very less reading for width and height in the paint Event, am I doing anything wrong here??

void ToolButton::paintEvent(QPaintEvent *e)
{
int co_x = (int)x() - (width() / 2);
int co_y = (int)y() - (height() / 2);

QPainter painter(this);
QPixmap mypix;
mypix.load(":images/f1u7.png");
mypix=mypix.scaled (width(),height(),Qt::IgnoreAspectRatio);
cout<<co_x<<","<<co_y<<","<<width()<<","<<height()<<endl;
painter.drawPixmap(co_x,co_y,width(),height(), mypix);
}

Thanks in advance,
Seema Rao

wysota
25th April 2006, 14:53
Can you show the class declaration and constructor? BTW. It doesn't make much sense to inherit QToolButton if you don't use its paintEvent. Maybe you should inherit QAbstractButton instead?

Seema Rao
25th April 2006, 15:06
#include <QToolButton>

class ToolButton: public QToolButton
{

public:
ToolButton(QWidget *parent=0);
private:

QString str1;

protected:
void paintEvent(QPaintEvent *e);
};
//here is the constructor

ToolButton::ToolButton(QWidget *parent): QToolButton(parent){}

wysota
25th April 2006, 19:50
And what's wrong exactly? And why can't you use QToolButton and its setIcon() method instead of subclassing?