PDA

View Full Version : QGraphicsView.Rect is always 640x480



Andrewshkovskii
17th October 2009, 16:31
Here the source codes :

setting scene with view :


void View::setVisualModel(QGraphicsScene * model)
{
qDebug () << this->visualClustersView->rect();
qDebug () << this->visualClustersView->sceneRect();
this->visualClustersView->setScene(model);
this->visualClustersView->setSceneRect(this->visualClustersView->rect);
qDebug () << this->visualClustersView->rect();
qDebug () << this->visualClustersView->sceneRect();
}
output :

QRect(0,0 640x480)
QRectF(0,0 0x0)
QRect(0,0 640x480)
QRectF(0,0 640x480)

but real view size is not 640x480.

Source code , what setting the items on scene :


void Model::calculateNewVisualResult(QStandardItemModel *model)
{
graphicsItems.clear();
this->visualResultModel->clear();
static QFont font("Times",9);
static QFontMetrics fn (font);
static int x = 0;
int y= 0;
static int yGrow = fn.height() -2;
static int maxSize =0;
this->graphicsItems.push_back(this->visualResultModel->addText(model->horizontalHeaderItem(0)->text(),font));
graphicsItems[0]->setPos(x,y);
maxSize = fn.width(graphicsItems.at(0)->toPlainText());
for(int i=1;i<model->rowCount();++i)
{
graphicsItems.push_back(visualResultModel->addText(model->horizontalHeaderItem(i)->text(),font));
graphicsItems[i]->setPos(x,y+yGrow);
y=graphicsItems.at(i)->pos().y();
if (maxSize < fn.width(graphicsItems.at(i)->toPlainText()))
maxSize = fn.width(graphicsItems.at(i)->toPlainText());
}
emit this->visualModelCalculated(maxSize);
}

Becouse of fixed view size, my interface resizing to view size,and this looks ugly.
Where is my problem?

wysota
17th October 2009, 17:53
What do you mean by "fixed view size"? You realize there is a viewport inside the view, right?

Andrewshkovskii
17th October 2009, 18:06
What do you mean by "fixed view size"? You realize there is a viewport inside the view, right?

Not viewport area size,an widget size, i mean..Or QGraphicsView.rect() return the viewport rect?

wysota
17th October 2009, 18:42
No, it returns the size of the widget. Thus if you have a scene of size the same as size of the widget it will obviously not fit in the viewport and scrollbars will appear.

Andrewshkovskii
17th October 2009, 19:27
No, it returns the size of the widget. Thus if you have a scene of size the same as size of the widget it will obviously not fit in the viewport and scrollbars will appear.
Ok, but this dont explain why QGraphicsView widget size is 640x480 instead of real size = 620x230 ? If i do not set the QGraphicsView::setSceneRect(QGraphicsView.rect()), it will be fine,but items will pos() a little left of center QGraphcisView

wysota
17th October 2009, 20:13
Ok, but this dont explain why QGraphicsView widget size is 640x480 instead of real size = 620x230 ?
Why should it have size of 620x230?


If i do not set the QGraphicsView::setSceneRect(QGraphicsView.rect()), it will be fine,but items will pos() a little left of center QGraphcisView

I have completely no idea what you are talking about... Setting the scene to the size of the widget will surely make the scene not fit into the viewport and some of it will be invisible. I guess that's what you observe here but you should also see scrollbars of the view. Did you disable them? If so, reenable them and everything should become clear.