Results 1 to 4 of 4

Thread: Resizing QGraphicsView inside a QGridLayout

  1. #1
    Join Date
    Aug 2010
    Posts
    4
    Thanks
    2

    Default Resizing QGraphicsView inside a QGridLayout

    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.

    Qt Code:
    1. qTrackGrid::qTrackGrid(qDocumentView *parent)
    2. : QWidget(parent),
    3. count(0)
    4. {
    5. grid = new QGridLayout(this);
    6. setLayout(grid);
    7. }
    8.  
    9. qTrackGrid::~qTrackGrid()
    10. {
    11. // delete everything
    12. for(int cc = 0; cc < count; cc++)
    13. delete views[cc];
    14. delete grid;
    15. }
    16.  
    17. void qTrackGrid::addTrackView(vwd_SV SV)
    18. {
    19. // add a new qTrackView to the next available position in the grid
    20. // hear we are enforcing that the column width be a maximum of 2
    21. int cRow = grid->rowCount();
    22. int cCol = grid->columnCount();
    23. int row = count / 2;
    24. int col = count % 2;
    25. qTrackView* tv = new qTrackView(this, SV);
    26. tv->setVisible(true);
    27. grid->addWidget(tv->viewport(), row, col);
    28. views.append(tv);
    29. qDebug() << grid->cellRect(row, col);
    30. count++;
    31. }
    To copy to clipboard, switch view to plain text mode 

    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.

    Qt Code:
    1. qTrackView::qTrackView(QWidget *parent, vwd_SV iSV)
    2. : QGraphicsView(parent),
    3. SV(iSV),
    4. buff(NULL),
    5. size(0)
    6. {
    7. // create the scene
    8. scene = new QGraphicsScene;
    9. setScene(scene);
    10.  
    11. // update the view
    12. updateView();
    13. }
    14.  
    15. void qTrackView::resizeEvent(QResizeEvent *event)
    16. {
    17. fitInView(scene->sceneRect(), Qt::IgnoreAspectRatio);
    18. }
    To copy to clipboard, switch view to plain text mode 

    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...

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Resizing QGraphicsView inside a QGridLayout

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

  3. The following user says thank you to tbscope for this useful post:

    mckinnon (10th September 2010)

  4. #3
    Join Date
    Aug 2010
    Posts
    4
    Thanks
    2

    Default Re: Resizing QGraphicsView inside a QGridLayout

    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?

  5. #4
    Join Date
    Jan 2006
    Location
    Alingsås, Sweden
    Posts
    437
    Thanks
    3
    Thanked 39 Times in 39 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Resizing QGraphicsView inside a QGridLayout

    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.

  6. The following user says thank you to e8johan for this useful post:

    mckinnon (10th September 2010)

Similar Threads

  1. Resizing QTableView inside a QTabWidget
    By Aslan in forum Newbie
    Replies: 2
    Last Post: 29th May 2010, 14:50
  2. QGraphicsView transformations and resizing
    By rubenvb in forum Qt Programming
    Replies: 2
    Last Post: 15th December 2009, 20:47
  3. resizing widget inside QScrollArea
    By mastupristi in forum Newbie
    Replies: 4
    Last Post: 16th July 2009, 19:29
  4. Resizing in QGraphicsView
    By A.H.M. Mahfuzur Rahman in forum Qt Programming
    Replies: 1
    Last Post: 21st June 2009, 09:39
  5. Resizing a QTreeWidget inside a layout
    By bruccutler in forum Qt Programming
    Replies: 11
    Last Post: 27th March 2007, 15:35

Tags for this Thread

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.