Results 1 to 2 of 2

Thread: Resizing QGraphicsScene to fit entire contents of QGraphicsScene

  1. #1
    Join Date
    Sep 2012
    Posts
    5
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Resizing QGraphicsScene to fit entire contents of QGraphicsScene

    Hi,

    I have a program which parses through a .txt file containing photo pathnames and then adds them as QGraphicsPixmapItems to a QGraphicsScene. This works correctly but I am unable to get the QGraphicsView to resize to the size of the pixmap so that the whole image is visible.

    To do this, I have created a class TrainingDataWindow which subclasses QMainWindow. The class contains a function selectImageSource() that correctly obtains the first pixmap from the .txt file and adds it to the QGraphicsScene. In this function, I have tried multiple ways of calling QGraphicsView::resize(....) in order to make the whole image visible. These methods include:

    1.
    Qt Code:
    1. view_image->resize(imgScene.itemsBoundingRect().width(),imgScene.itemsBoundingRect().height());
    To copy to clipboard, switch view to plain text mode 

    2.
    Qt Code:
    1. QSize imgSize = img.size();
    2. view_image->resize(imgSize);
    To copy to clipboard, switch view to plain text mode 

    where view_image is of type QGraphicsView and img is of type QPixmap. Neither of these (or others) have done anything (literally).

    Any ideas on how to fix this? If i do need to reimplement resizeEvent() for the TrainingDataWindow class how would this be affected since I designed the program with Qt Designer?

    Thanks,
    Max

  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: Resizing QGraphicsScene to fit entire contents of QGraphicsScene

    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.


Similar Threads

  1. Replies: 2
    Last Post: 12th August 2011, 22:50
  2. QTableView resizing to contents.
    By chris_helloworld in forum Qt Programming
    Replies: 2
    Last Post: 24th November 2010, 13:43
  3. QGraphicsScene Scrollbar resizing
    By ikeurb in forum Qt Programming
    Replies: 5
    Last Post: 14th July 2009, 15:33
  4. in QGraphicsScene matrix of other QGraphicsScene
    By Noxxik in forum Qt Programming
    Replies: 5
    Last Post: 15th February 2009, 17:27
  5. QToolBox Resizing to contents??
    By kerwim in forum Qt Programming
    Replies: 1
    Last Post: 30th June 2008, 08:28

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.