DuncanG
24th July 2008, 18:24
I'm new to Qt so its probably me, but..
I've created a trivial subclass of QScrollbar -
class ScrollBar : public QScrollBar
{
Q_OBJECT
public:
ScrollBar ( Qt::Orientation orientation, QWidget * parent = 0 );
protected:
void paintEvent(QPaintEvent* event);
};
ScrollBar::ScrollBar ( Qt::Orientation orientation, QWidget * parent )
{
QScrollBar::QScrollBar (orientation, parent);
}
void ScrollBar:: paintEvent(QPaintEvent * event)
{
int x, y, w, h;
this->rect().getRect(&x,&y,&w,&h);
QScrollBar:: paintEvent(event);
QPainter p(this);
p.setPen(QPen(Qt::red,1));
p.drawLine(x,y,x+w,y+h);
}
when created by -
scrollBar = new ScrollBar(orientation); // works for QScrollBar
a vertical scrollbar is drawn regardless of orientation.
Following by -
scrollBar->setOrientation(orientation); // not required for QScrollbar
provides a fix, but it wasn't needed when using the ancestor class.
Where am I going wrong?
I've created a trivial subclass of QScrollbar -
class ScrollBar : public QScrollBar
{
Q_OBJECT
public:
ScrollBar ( Qt::Orientation orientation, QWidget * parent = 0 );
protected:
void paintEvent(QPaintEvent* event);
};
ScrollBar::ScrollBar ( Qt::Orientation orientation, QWidget * parent )
{
QScrollBar::QScrollBar (orientation, parent);
}
void ScrollBar:: paintEvent(QPaintEvent * event)
{
int x, y, w, h;
this->rect().getRect(&x,&y,&w,&h);
QScrollBar:: paintEvent(event);
QPainter p(this);
p.setPen(QPen(Qt::red,1));
p.drawLine(x,y,x+w,y+h);
}
when created by -
scrollBar = new ScrollBar(orientation); // works for QScrollBar
a vertical scrollbar is drawn regardless of orientation.
Following by -
scrollBar->setOrientation(orientation); // not required for QScrollbar
provides a fix, but it wasn't needed when using the ancestor class.
Where am I going wrong?