[Qt-interest] NoScrollBar is coming

Ferenc Stelcz ferenc at stelcz.hu
Thu Aug 20 12:53:51 CEST 2009


Sujan Dasmahapatra wrote:
> Dear Friends
> I have some QGraphicsItems in the QGraphicsScene. I am doing some
> translation so that my item is getting out of the view.Some part is not
> visible. I am getting no horizontal scrollbar to see it..How could I set
> this mechanism so that whenever my items is out I should get a scrollbar.
> 
> 
> 
That should be one of those easy-to-find-in-the-docs problems.

Bear in mind: "Note that QGraphicsScene has no visual appearance of its own; 
it only manages the items. You need to create a QGraphicsView widget to 
visualize the scene."

So step up a level and set scrollbars for the QGraphicsView object holding 
your scene.

QGraphicsView inherits 2 of its properties from QAbstractScrollArea:
horizontalScrollBarPolicy : Qt::ScrollBarPolicy
verticalScrollBarPolicy : Qt::ScrollBarPolicy

Qt::ScrollBarPolicy is an enum which has following items:

Qt::ScrollBarAsNeeded	0	QAbstractScrollArea shows a scroll bar when   the 
content is too large to fit and not otherwise. This is the default.

Qt::ScrollBarAlwaysOff	1	QAbstractScrollArea never shows a scroll bar.

Qt::ScrollBarAlwaysOn	2	QAbstractScrollArea always shows a scroll bar.

Setting scrollbar policies for the view occurs through calling:
void setVerticalScrollBarPolicy ( Qt::ScrollBarPolicy )
void setHorizontalScrollBarPolicy ( Qt::ScrollBarPolicy )

But as I'm reading here it states: "The default policy is 
Qt::ScrollBarAsNeeded" for both directions...


--
Ferenc Stelcz
Junior Software Engineer

Banyan Technologies LLC.



More information about the Qt-interest-old mailing list