I'm new to Qt so its probably me, but..
I've created a trivial subclass of QScrollbar -
{
Q_OBJECT
public:
ScrollBar
( Qt
::Orientation orientation,
QWidget * parent
= 0 );
protected:
};
ScrollBar
::ScrollBar ( Qt
::Orientation orientation,
QWidget * parent
){
}
{
int x, y, w, h;
this->rect().getRect(&x,&y,&w,&h);
p.
setPen(QPen(Qt
::red,
1));
p.drawLine(x,y,x+w,y+h);
}
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);
}
To copy to clipboard, switch view to plain text mode
when created by -
scrollBar = new ScrollBar(orientation); // works for QScrollBar
scrollBar = new ScrollBar(orientation); // works for QScrollBar
To copy to clipboard, switch view to plain text mode
a vertical scrollbar is drawn regardless of orientation.
Following by -
scrollBar->setOrientation(orientation); // not required for QScrollbar
scrollBar->setOrientation(orientation); // not required for QScrollbar
To copy to clipboard, switch view to plain text mode
provides a fix, but it wasn't needed when using the ancestor class.
Where am I going wrong?
Bookmarks