Results 1 to 5 of 5

Thread: [QGraphicsView] Size stretch

  1. #1
    Join Date
    Apr 2011
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default [QGraphicsView] Size stretch

    Hi all,

    I'm having troubles stretching QGraphicsViews automatically when the size of my window adjusts.

    This is the code I have at the moment.
    Qt Code:
    1. self.leftview = QtGui.QGraphicsView()
    2. self.rightview = QtGui.QGraphicsView()
    3.  
    4. self.leftview.setFixedSize(550,600)
    5. self.rightview.setFixedSize(550,600)
    6.  
    7. leftrect = QtCore.QRectF(self.leftview.rect())
    8. rightrect = QtCore.QRectF(self.rightview.rect())
    9. leftrect.adjust(1,1,-1,-1)
    10. rightrect.adjust(1,1,-1,-1)
    11.  
    12. self.leftscene = TEMDrawer.DiagramScene(leftrect)
    13. self.rightscene = TEMDrawer.DiagramScene(rightrect)
    14.  
    15. self.leftview.setScene(self.leftscene)
    16. self.rightview.setScene(self.rightscene)
    To copy to clipboard, switch view to plain text mode 

    The constructor of the DiagramScene calls the setSceneRect with the given parameter.
    No GUI-related stuff other than that happens in the DiagramScene class.

    Removing the setFixedSize() method calls do not enable automatic stretching of the QGraphicsView or QGraphicsScene.

    Is there a way to automatically stretch a QGraphicsScene or QGraphicsView to fit the space the layout uses?

    Thanks in advance!

    PS: I had a look at the proposed threads #1#2#3, but they did not offer a solution for my problem...

  2. #2
    Join Date
    Dec 2010
    Location
    Russia
    Posts
    83
    Thanks
    1
    Thanked 12 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: [QGraphicsView] Size stretch

    Do you use a layout for your graphics view ?

    I mean ,your widget's constructor might look like this:

    Qt Code:
    1. self.MyGraphicsScene = QtGui.QGraphicsScene( self );
    2.  
    3. # add items to the scene
    4.  
    5. self.MyGraphicsView = QtGui.QGraphicsView( self.MyGraphicsScene );
    6.  
    7.  
    8. self.MainLayout = QtGui.QHBoxLayout( self );
    9.  
    10. self.MainLayout .addWidget( self.MyGraphicsView );
    To copy to clipboard, switch view to plain text mode 

    Now your graphics view will be resized as the parent's size changes.

  3. #3
    Join Date
    Apr 2011
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: [QGraphicsView] Size stretch

    Dear Alex, thanks for your reply.

    I do add the views to a layout. The code in the first post is followed by:

    Qt Code:
    1. self.rightlayout.addWidget(self.qlist)
    2. self.rightlayout.addWidget(self.qinfow)
    3. self.qcheckbox = QtGui.QCheckBox("Hide convergences")
    4. self.rightlayout.addWidget(self.qcheckbox)
    5. self.connect(self.qcheckbox, QtCore.SIGNAL('stateChanged(int)'), self.reflexInfo.convergences_toggled)
    6. self.mainlayout.addWidget(self.splitterwidget,5)
    7. self.mainlayout.addLayout(self.rightlayout)
    8. self.setLayout(self.mainlayout)
    To copy to clipboard, switch view to plain text mode 

    Do you happen to know what I am doing wrong?
    Last edited by bspitz; 28th April 2011 at 11:49. Reason: formatting

  4. #4
    Join Date
    Dec 2010
    Location
    Russia
    Posts
    83
    Thanks
    1
    Thanked 12 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: [QGraphicsView] Size stretch

    Can you share a code ?

  5. #5
    Join Date
    Apr 2011
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: [QGraphicsView] Size stretch

    This is the drawing code:

    Qt Code:
    1. def __init__(self,usrlist,tsklist,conc_tasklist,parent=None):
    2. super(TEMReflexionWidget,self).__init__(parent)
    3.  
    4. self.mainlayout = QtGui.QHBoxLayout()
    5. self.leftlayout = QtGui.QVBoxLayout()
    6. self.innerlayout = QtGui.QHBoxLayout()
    7. self.rightlayout = QtGui.QVBoxLayout()
    8.  
    9. self.leftview = QtGui.QGraphicsView()
    10. self.rightview = QtGui.QGraphicsView()
    11.  
    12. self.leftview.setFixedSize(550,600)
    13. self.rightview.setFixedSize(550,600)
    14.  
    15. self.leftview.setFrameStyle(QtGui.QFrame.NoFrame)
    16. self.rightview.setFrameStyle(QtGui.QFrame.NoFrame)
    17. self.leftview.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
    18. self.leftview.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
    19. self.rightview.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
    20. self.rightview.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
    21.  
    22. leftrect = QtCore.QRectF(self.leftview.rect())
    23. rightrect = QtCore.QRectF(self.rightview.rect())
    24. leftrect.adjust(1,1,-1,-1)
    25. rightrect.adjust(1,1,-1,-1)
    26.  
    27. self.leftscene = TEMDrawer.DiagramScene(leftrect)
    28. self.rightscene = TEMDrawer.DiagramScene(rightrect)
    29.  
    30. self.leftview.setScene(self.leftscene)
    31. self.rightview.setScene(self.rightscene)
    32. self.qcheckbox = QtGui.QCheckBox("Hide convergences")
    33. self.reflexInfo = QReflexionReportWidget()
    34. self.qlist = QTaskList(self.reflexInfo,self.conceptual_tasklist,self.impltasklist,self.leftscene,self.rightscene,self,self.qcheckbox)
    35. self.qinfow = TEMDrawer.TEMInfoWidget()
    36.  
    37. self.innerlayout.addWidget(self.leftview)
    38. self.innerlayout.addWidget(self.rightview)
    39.  
    40. self.testwidget = QtGui.QWidget()
    41. self.testwidget.setLayout(self.innerlayout)
    42. self.splitterwidget = QtGui.QSplitter(0)
    43. self.splitterwidget.addWidget(self.testwidget)
    44. self.splitterwidget.addWidget(self.reflexInfo)
    45.  
    46. self.rightlayout.addWidget(self.qlist)
    47. self.qline = QtGui.QLineEdit()
    48. self.rightlayout.addWidget(QtGui.QLabel("Filter:"))
    49. self.rightlayout.addWidget(self.qline)
    50. self.rightlayout.addWidget(self.qinfow)
    51.  
    52. self.rightlayout.addWidget(self.qcheckbox)
    53. self.connect(self.qcheckbox, QtCore.SIGNAL('stateChanged(int)'), self.reflexInfo.convergences_toggled)
    54. self.connect(self.qline, QtCore.SIGNAL('textChanged(QString)'), self.qlist.filter_items)
    55. #self.leftlayout.addLayout(self.innerlayout)
    56. self.mainlayout.addWidget(self.splitterwidget,5)
    57. #self.mainlayout.addLayout(self.leftlayout)
    58. self.mainlayout.addLayout(self.rightlayout)
    59. self.setLayout(self.mainlayout)
    60.  
    61. self.draw_lanes(self.userlist,self.leftscene,0)
    62. self.draw_lanes(self.userlist,self.rightscene,1)
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. QGraphicsView and QWebView size question
    By MarkoSan in forum Qt Programming
    Replies: 0
    Last Post: 24th April 2009, 01:25
  2. How to increase size of QGraphicsView Dynamically
    By Kingofhearts_sri in forum Qt Programming
    Replies: 1
    Last Post: 23rd January 2009, 08:54
  3. Problem determining size of QGraphicsView
    By Bocki in forum Qt Programming
    Replies: 3
    Last Post: 17th February 2008, 14:54
  4. Setting the scene size in QGraphicsView
    By Valheru in forum Newbie
    Replies: 5
    Last Post: 11th November 2007, 15:03
  5. Size of QGraphicsView
    By IsleWitch in forum Newbie
    Replies: 10
    Last Post: 10th October 2007, 12:09

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.