PDA

View Full Version : Horizontal scrollbar problem



blaylockr
21st July 2008, 15:06
Hi,

I am trying to place a horizontal scrollbar in the bottom of a widget. The widget in question is one of (3) panes in a splitter window.

The first problem I discovered was that the scrollbar is too long for the width of the window by 62 units.

This code is in the constructor of my widget class.

mpScrollbar = new QScrollBar ( Qt::Horizontal, this );
mpScrollbar->setGeometry ( 0, height() + 20, width() - 62, 20 );


The second problem is that when I resize the window, the scrollbar does not resize with it.

I tried overriding the widget's resizeEvent but when I do, the scrollbar is NEVER drawn.


void MyWidget::resizeEvent ( QResizeEvent * event )
{
mpScrollbar->setGeometry ( 0, height() + 20, width() - 62, 20 );
mpScrollbar->update();
}

jpn
21st July 2008, 15:36
How about QScrollArea? Or at least use layouts (http://doc.trolltech.com/4.4/layout.html) if you want to handle a QScrollBar by hand... :)

blaylockr
21st July 2008, 17:38
Thanks for the suggestion. I finally got it to work using your suggestion.

At first, it put the scrollbar in the middle of the widget with this code:


mpScrollbar = new QScrollBar ( Qt::Horizontal, this );
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(mpScrollbar);

Then I added arguments to the addWidget function:

layout->addWidget(mpScrollbar,0,Qt::AlignBottom);


Still wasn't quite right. Had margins around it, so I added the following line:

layout->setMargin(0);