PDA

View Full Version : Resizing QGraphicsView inside a QGridLayout



mckinnon
8th September 2010, 14:38
Hi,
I am trying to insert a series of qgraphicsviews into the cells of a dynamically expanded qgridlayout.

Here is a bit from the grid class.



qTrackGrid::qTrackGrid(qDocumentView *parent)
: QWidget(parent),
count(0)
{
grid = new QGridLayout(this);
setLayout(grid);
}

qTrackGrid::~qTrackGrid()
{
// delete everything
for(int cc = 0; cc < count; cc++)
delete views[cc];
delete grid;
}

void qTrackGrid::addTrackView(vwd_SV SV)
{
// add a new qTrackView to the next available position in the grid
// hear we are enforcing that the column width be a maximum of 2
int cRow = grid->rowCount();
int cCol = grid->columnCount();
int row = count / 2;
int col = count % 2;
qTrackView* tv = new qTrackView(this, SV);
tv->setVisible(true);
grid->addWidget(tv->viewport(), row, col);
views.append(tv);
qDebug() << grid->cellRect(row, col);
count++;
}


I would like to use something like the following code in the qTrackView class I have inserted into the grid to make sure that the image scales and displays according to the current size of the qTrackGrid widget.



qTrackView::qTrackView(QWidget *parent, vwd_SV iSV)
: QGraphicsView(parent),
SV(iSV),
buff(NULL),
size(0)
{
// create the scene
scene = new QGraphicsScene;
setScene(scene);

// update the view
updateView();
}

void qTrackView::resizeEvent(QResizeEvent *event)
{
fitInView(scene->sceneRect(), Qt::IgnoreAspectRatio);
}


I dont seem to be getting the resizing working as it would if the QGraphicsView object was inserted into the the widget without it being a cell of a QGridLayout.

I am setting up the qTrackView class with a QGraphicsScene as you can see from the constructor.

Its obvious that I am missing something just havent got my head around it yet.

Thanks,
Dave...

tbscope
8th September 2010, 16:28
I dont seem to be getting the resizing working as it would if the QGraphicsView object was inserted into the the widget without it being a cell of a QGridLayout.

I don't understand what you want to say.
Do you mean that the objects in the graphicsview do not get resized if you do not add the view to the grid layout?

mckinnon
9th September 2010, 00:51
No, sorry I am trying to say that the graphicsview objects dont resize properly when they are in the gridlayout.

But they do resize properly when they are not.

Any ideas?

e8johan
9th September 2010, 10:15
I'd play with the size policies of the graphics view (and its neighbours) as well as the minimumSize and maximumSize properties of the graphics view.