[Qt-interest] QGraphicsView improper widget size before resizeEvent
franki
franki at franki.eu.org
Thu May 6 14:50:44 CEST 2010
Hi,
I have QGraphicsView that displays QPixmap object, and I have problem with
resizeEvent.
First resize causes huge change in size of QGraphicsView, the widget size
(according to rect() function) changes much more with first resize, than it
should be regarding the mouse move.
Thus, when I use fitInView() function (with pixmap_item as argument) in
resizeEvent it gives wrong size at first time, until I resize main window
with mouse. When I do that rect() function from QGraphicsView shows this
widget size to be about 180 pixel wider (and higher) than before resizing
regardless how small the resize was. Why this happens?
Here is the code from constructor:
MainPages::MainPages(QWidget *parent): QStackedWidget(parent)
{
mp.setupUi(this);
mp.gridLayout->setContentsMargins(0,0,0,0);
floor1_scn = new QGraphicsScene( mp.floor1_g_view );
mp.floor1_g_view->setScene( floor1_scn );
floor1_png=QPixmap("images/floor1.png");
floor1_item=floor1_scn->addPixmap(floor1_png);
}
void MainPages::resizeEvent(QResizeEvent * event) {
qDebug() << mp.floor1_g_view->rect();
qDebug() << floor1_scn->sceneRect();
qDebug() << floor1_item->boundingRect();
mp.floor1_g_view->fitInView(floor1_item,Qt::KeepAspectRatio);
}
So at first time, when I run this, debug shows (before resizing):
QRect(0,0 622x462)
QRectF(-0.5,-0.5 617x463)
QRectF(-0.5,-0.5 617x463)
then after really small mouse move it shows:
QRect(0,0 784x560)
QRectF(-0.5,-0.5 617x463)
QRectF(-0.5,-0.5 617x463)
So, the size of QGraphicsView widget changes to much. It has the effect of
dramatically changing QPixmap object during first resize event, or setting it
to be to small before the resizeEvent, if you prefer.
The widgets are quite nested, could this be the reason?
Hierarchy is like this:
QMainWindow->QFrame->QStackedWidget->QTabWidget->QGgrapvicsView
and layouts between them have marigin set to zero, with
setContentsMargins(0,0,0,0)
greetings
Marek
More information about the Qt-interest-old
mailing list