Results 1 to 4 of 4

Thread: qgraphicsview and qsplitter sizing problem

  1. #1
    Join Date
    Oct 2009
    Posts
    26
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default qgraphicsview and qsplitter sizing problem

    I make a program with a center view and a QStackedwidget on the left that keeps properties. The stacked widget contains for now 4-5 widgets designed in qt designer.
    I recently added a new page in the stacked widget that contains some qwidgets and a QGraphicsView:
    picGVinstacked.png
    As you can see the top QGraphicsView works and resizes fine inside qt designer.
    When I add the above qwidget to the left properties stackedwidget though, my qgraphicsview resizes awfully and gives me the below pic:
    picQWidgetInApp.jpg
    The QGraphicsView gets too big vertically destroying the size of my main window and extents outside the screen.

    I read some posts about qgraphicsview behaviour inside a qsplitter, and the need to manipulate stretch factor when the scene of the qgraphicsview changes, but I could not understand how to do it.

    Any ideas how to solve this issue? Notice that if I remove the splitters then all the layouting is fine. But I liked the notion to let the user resize with a splitter the view/properties ratio.

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: qgraphicsview and qsplitter sizing problem

    Are you using a layout on the stack widget page that contains the splitter? Show the code where you create this page. It looks to me as though you haven't put the widget that contains the splitter into a layout, and as a result, the view is expanding vertically to whatever size you have set for the graphics view.

  3. #3
    Join Date
    Oct 2009
    Posts
    26
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: qgraphicsview and qsplitter sizing problem

    My main app window has a central QWidget consisting of a QGraphicsView and a QStackedWidget:
    Qt Code:
    1. m_view= new saView(this);
    2. m_stack=new QStackedWidget();
    3. m_stack->setSizePolicy(QSizePolicy::Minimum,QSizePolicy::MinimumExpanding);
    4. m_stack->setMinimumWidth(256);
    5. ....
    6. initWidgets();//this is the place where m_widgets[] holds the pointers of the new properties widgets
    7. for(i=0;i<5;i++) {m_stack->addWidget(m_widgets[i]);};
    8. QGridLayout *layout = new QGridLayout;//here I tried QHBoxLayout or QVBoxLayout but nothing....
    9. QSplitter *splitter=new QSplitter(this);
    10. splitter->setChildrenCollapsible(false);
    11. splitter->addWidget(m_view);
    12. splitter->addWidget(m_stack);
    13. layout->addWidget(splitter);
    14. setLayout(layout);
    15. ....
    To copy to clipboard, switch view to plain text mode 

    The initWidgets() function :
    Qt Code:
    1. void saGui::initWidgets()
    2. {
    3. //qDebug()<<"saGui::initWidgets";
    4. int i;
    5. //the 0 index is the empty properties window
    6. m_widgets[0]=new QWidget();
    7.  
    8. //1 index is SteelNodeProperties window
    9. saWidgetSteelNodeProperties* w=new saWidgetSteelNodeProperties(this);
    10. m_widgets[1]=w;
    11. ...
    12. ...
    13.  
    14. // 2 index is ConcretePolygonProperties window
    15. saWidgetConcretePolygonProperties* w2=new saWidgetConcretePolygonProperties(this);
    16. m_widgets[2]=w2;
    17. ...
    18.  
    19. // 3 index is SteelLineProperties window
    20. saWidgetSteelLineProperties* w3=new saWidgetSteelLineProperties(this);
    21. m_widgets[3]=w3;
    22. ....
    23.  
    24. //4 index is the QWidget that contains the QGraphicsView that gets resized wrongfully
    25. saWidgetMaterialProperties* w4=new saWidgetMaterialProperties(&m_materials,this);
    26. m_widgets[4]=w4;//adding w4 to m_widgets produces the wrong size.
    27.  
    28. };
    To copy to clipboard, switch view to plain text mode 

    The QWidget is made inside Qt Designer. It has a QVBoxLayout, containing a QSplitter of a QGraphicsView, and a QStackedWidget , and a VerticalSpacer .
    The file of the QWidget is here: WidgetMaterialProperties.ui.zip.

    Notice that if I don't do :
    Qt Code:
    1. scene->setSceneRect(....);
    To copy to clipboard, switch view to plain text mode 
    in my code , and just use the QGraphicsView/Scene adding items. the QGraphicsView starts with those sizes:
    picQGinsize1.png
    ,that looks right but it is not. Because QGraphicsView has small height. And the vertical splitter between them cannot be moved. But If I put some items inside QGraphicsScene that are outsize active view the QGraphicsView starts to grows its size, growing also the mainApp window size and moving the window contents out of the screen .
    Last edited by hayzel; 3rd February 2015 at 09:45.

  4. #4
    Join Date
    Oct 2009
    Posts
    26
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: qgraphicsview and qsplitter sizing problem

    Found out a solution. I don't know why though. The problem is fixed by trial and error.
    Firstly on the central view/properties splitter, I used QSizePolicy::Ignored :
    Qt Code:
    1. m_view= new saView(this);
    2. m_stack=new QStackedWidget();
    3. m_stack->setSizePolicy(QSizePolicy::Preferred,QSizePolicy::Ignored);
    4. m_stack->setMinimumWidth(256);
    5. ....
    6. initWidgets();//this is the place where m_widgets[] holds the pointers of the new properties widgets
    7. for(i=0;i<5;i++) {m_stack->addWidget(m_widgets[i]);};
    8. QGridLayout *layout = new QGridLayout;//here I tried QHBoxLayout or QVBoxLayout but nothing....
    9. QSplitter *splitter=new QSplitter(this);
    10. splitter->setChildrenCollapsible(false);
    11. splitter->addWidget(m_view);
    12. splitter->addWidget(m_stack);
    13. QList<int> sizes;sizes<<600<<100;
    14. splitter->setSizes(sizes);
    15. layout->addWidget(splitter);
    16. setLayout(layout);
    17. ....
    To copy to clipboard, switch view to plain text mode 
    The first Ignored flag keeps the m_stack (properties) widget inside the main window, and does not resize it outside the screen.
    The setSizes forces the properties widget to its minimum size.

    As for the vertical splitter inside the view, I used also inside qt designer for the QGraphicsView (top of the vertical splitter) the Ignored flag, to make it resizeble.
    And set the ratio of view/other properties with :
    Qt Code:
    1. ui.splitter->setStretchFactor(0,1);
    2. ui.splitter->setStretchFactor(1,3);
    To copy to clipboard, switch view to plain text mode 
    inside the constructor of the widget page.

    PS. I cannot find how to change the thread name to SOLVED ,

Similar Threads

  1. Replies: 4
    Last Post: 3rd February 2015, 18:19
  2. QGraphicsView Horizontal Stretch in a QSplitter
    By bassPenguin in forum Qt Programming
    Replies: 4
    Last Post: 12th April 2012, 07:05
  3. strange QGraphicsView sizing behavior
    By tpf80 in forum Qt Programming
    Replies: 3
    Last Post: 1st February 2009, 21:04
  4. Pushbutton sizing problem on Mac OS
    By will49 in forum Qt Programming
    Replies: 5
    Last Post: 3rd October 2007, 22:26
  5. Sizing problem
    By Levon Nikoghosyan in forum Qt Programming
    Replies: 7
    Last Post: 2nd April 2007, 18:31

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.