PDA

View Full Version : Embedded widgets size



Indalo
16th November 2009, 15:36
Hello!

If I place widgets in QGraphicsView, they don't fits its size:


// Add table in the scene
QGraphicsGridLayout *grid = new QGraphicsGridLayout();
grid->addItem(scene->addWidget(tableWidget), 0, 0);

QGraphicsProxyWidget* form = new QGraphicsProxyWidget;
form->setLayout(grid);
form->setCacheMode(QGraphicsItem::ItemCoordinateCache);

scene->addItem(form);

In the example above there is table in the scene, and if scene will be set to QGraphicsView, the table doesn't fit size according to the size of QGraphicsView.

That's the point. ^) Does anybody come across with such a problem?

Thanks.

aamer4yu
17th November 2009, 04:19
Try if QGraphicsItem::ensureVisible helps you

Indalo
17th November 2009, 08:04
Unfortunately, it has no effect. Either I call it with QRect or passing my QWidgetItem (which is QGraphicsProxyWidget containig QGraphicsGridLayout and QWidgetTable).

I always get:

http://pic.ipicture.ru/uploads/091117/F6bd1jl572.png

wysota
17th November 2009, 09:44
In the example above there is table in the scene, and if scene will be set to QGraphicsView, the table doesn't fit size according to the size of QGraphicsView.

Why would it? The item won't adjust to the size of the scene (or the view) by itself. You have to reimplement the views resizeEvent(), resize the scene and modify geometry of the item containing the layout.

Indalo
17th November 2009, 10:12
wysota, thanks. Could you explain a little bit more exactly? As I got, firstly I have to reimplement QGraphicsView::resizeEvent(). There I would change size of the scene to the new size of QGraphicsView. And then...? I need to call setGeometry to every item in the scene? But how could I calculate new sizes of item? By "hand" or what?