Results 1 to 6 of 6

Thread: QGraphicsView.Rect is always 640x480

  1. #1
    Join Date
    Oct 2009
    Posts
    27
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QGraphicsView.Rect is always 640x480

    Here the source codes :

    setting scene with view :

    Qt Code:
    1. void View::setVisualModel(QGraphicsScene * model)
    2. {
    3. qDebug () << this->visualClustersView->rect();
    4. qDebug () << this->visualClustersView->sceneRect();
    5. this->visualClustersView->setScene(model);
    6. this->visualClustersView->setSceneRect(this->visualClustersView->rect);
    7. qDebug () << this->visualClustersView->rect();
    8. qDebug () << this->visualClustersView->sceneRect();
    9. }
    To copy to clipboard, switch view to plain text mode 
    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 :

    Qt Code:
    1. void Model::calculateNewVisualResult(QStandardItemModel *model)
    2. {
    3. graphicsItems.clear();
    4. this->visualResultModel->clear();
    5. static QFont font("Times",9);
    6. static QFontMetrics fn (font);
    7. static int x = 0;
    8. int y= 0;
    9. static int yGrow = fn.height() -2;
    10. static int maxSize =0;
    11. this->graphicsItems.push_back(this->visualResultModel->addText(model->horizontalHeaderItem(0)->text(),font));
    12. graphicsItems[0]->setPos(x,y);
    13. maxSize = fn.width(graphicsItems.at(0)->toPlainText());
    14. for(int i=1;i<model->rowCount();++i)
    15. {
    16. graphicsItems.push_back(visualResultModel->addText(model->horizontalHeaderItem(i)->text(),font));
    17. graphicsItems[i]->setPos(x,y+yGrow);
    18. y=graphicsItems.at(i)->pos().y();
    19. if (maxSize < fn.width(graphicsItems.at(i)->toPlainText()))
    20. maxSize = fn.width(graphicsItems.at(i)->toPlainText());
    21. }
    22. emit this->visualModelCalculated(maxSize);
    23. }
    To copy to clipboard, switch view to plain text mode 

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

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QGraphicsView.Rect is always 640x480

    What do you mean by "fixed view size"? You realize there is a viewport inside the view, right?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Oct 2009
    Posts
    27
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsView.Rect is always 640x480

    Quote Originally Posted by wysota View Post
    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?

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QGraphicsView.Rect is always 640x480

    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Oct 2009
    Posts
    27
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsView.Rect is always 640x480

    Quote Originally Posted by wysota View Post
    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

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QGraphicsView.Rect is always 640x480

    Quote Originally Posted by Andrewshkovskii View Post
    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. The following user says thank you to wysota for this useful post:

    Andrewshkovskii (19th October 2009)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.