[Qt-interest] scrollbar in QGraphicsView

Yifei Li yifli at mtu.edu
Thu Apr 8 04:30:18 CEST 2010


Hi all,

First of all, my question is under what condition a QGraphicsView widget will show horizontal/vertical scroll bar.

I know the default behavior is to show scroll bars as needed, but the code below does not give me scrollbars. However, if I use QGraphicsView instead of my custom QGraphicsView class, scroll bars showed up properly.

// MyView is derived from QGraphicsView and it reimplements resizeEvent. 
// QGraphicsView* view = new QGraphicsView, scroll bars will be displayed
MyView* view = new MyView;                 
QGraphicsScene* scene = new QGraphicsScene;
view->setScene(scene);

QGraphicsWidget* center = new QGraphicsWidget;
QGraphicsGridLayout* layout = new QGraphicsGridLayout;

scene->addItem(center);
center->setLayout(layout);

// the following code starts to add widgets into layout
...
layout->addItem
...

Thanks

Yifei



More information about the Qt-interest-old mailing list