Results 1 to 10 of 10

Thread: problem with QSplitter

  1. #1
    Join Date
    Apr 2013
    Posts
    24
    Thanks
    4
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default problem with QSplitter

    Hi, all

    In my situation, I have several QFrames in the QSplitter (QFrame can be added or deleted dynamically by user). When resizing the QFrame by mouse on the QSplitter, in default, for example (only considering the horizontal orientation):

    ------- in default -------
    before resizing

    parent window width: 200
    QFrame A width: 100
    QFrame B width: 100

    after resize:

    parent window width: 200
    QFrame A width: 150
    QFrame B width: 50
    ------------------------

    and I want when resize the QFrame, the parent window will grow or shrink with its child QFrame.

    -------- I want ---------
    before resizing

    parent window width: 200
    QFrame A width: 100
    QFrame B width: 100

    after resize:

    parent window width: 250 (grow with its child)
    QFrame A width: 150
    QFrame B width: 100 (keep its size)
    -------------------------

    So, any ideas?


    Thank you in advance!


    Tang Tao

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: problem with QSplitter

    What is stopping you from resizing the parent window?

  3. #3
    Join Date
    Apr 2013
    Posts
    24
    Thanks
    4
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: problem with QSplitter

    Quote Originally Posted by ChrisW67 View Post
    What is stopping you from resizing the parent window?
    sorry for my unclear explanation.

    Actually, "resizing" mentioned above means that dragging the splitter handle and changing its children's width by mouse.


    In defalut action of Qsplitter, dragging the splitter handle, one child widget will grow, the other neighbor child widget will shrink, and parent window will keep its width unchanged.

    I want, when dragging the handle, one child widget will grow, but the neighbor widget will keep its width, parent window will increase width.

    what i want.jpg



    Thank you for your reply.


    Tang Tao

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: problem with QSplitter

    QSplitter divides the available space (in the container it is in) between the widgets either side of it. It's not capable of changing the size of the outer container. If the user wants a larger window nothing stops them resizing the parent window; this is the standard and expected GUI behaviour.

    If you want to code this unusual behaviour yourself then connect to the splitterMoved() signal and programmatically resize the container. Use the splitter stretch factors to ensure all the extra space is placed in the growing widget.

  5. The following user says thank you to ChrisW67 for this useful post:

    tangtao_xp (25th June 2013)

  6. #5
    Join Date
    Apr 2013
    Posts
    24
    Thanks
    4
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: problem with QSplitter

    Thanks, ChrisW67

    I'll try it. I will post the new problem if I meet trouble with this idea.


    Tang Tao

  7. #6
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: problem with QSplitter

    I will not be surprised if resizing the window causes the splitterMoved() signal to fire again in a nasty loop.

  8. #7
    Join Date
    Apr 2013
    Posts
    24
    Thanks
    4
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: problem with QSplitter

    Quote Originally Posted by ChrisW67 View Post
    I will not be surprised if resizing the window causes the splitterMoved() signal to fire again in a nasty loop.
    Hi, ChrisW67

    I am glad to hear your far-seeing advice. Why does it cause a nasty loop?

    Meanwhile, I'm working on how to get the deltaSize (how far the mouse dragging, or check the image below), which is used for resizing the parent window.

    deltaSize.jpg


    Tang Tao

  9. #8
    Join Date
    Apr 2013
    Posts
    24
    Thanks
    4
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: problem with QSplitter

    Hi, all

    I still have problem with the QSplitter. As described below, I try to get the deltaSize, pls refer to the code below:

    Qt Code:
    1. // in Widget.cpp
    2. Widget::Widget(QWidget *parent)
    3. {
    4. layout = new QHBoxLayout(this);
    5. mySplitter = new MySplitter(this);
    6.  
    7. frame1 = new QFrame();
    8. frame2 = new QFrame();
    9.  
    10. mySplitter->addWidget(frame1);
    11. mySplitter->addWidget(frame2);
    12.  
    13. layout->addWidget(mySplitter);
    14. this->setLayout(layout);
    15.  
    16. this->resize(200, 200);
    17.  
    18. // always returns (0, 0), I don't know why.
    19. qDebug() << mySplitter->sizes();
    20. }
    21.  
    22. // in MySplitter.cpp
    23. MySplitter::MySplitter(Qt::Orientation ori, QWidget *parent):
    24. QSplitter(ori, parent)
    25. {
    26. if (this->parentWidget() == NULL)
    27. return;
    28.  
    29. this->setOpaqueResize(false);
    30. this->setChildrenCollapsible(false);
    31.  
    32. qDebug() << mySplitter->sizes();
    33. originalSizes = this->sizes();
    34.  
    35. connect(this, SIGNAL(splitterMoved(int,int)), this, SLOT(keepSizeMove(int,int)));
    36. }
    37.  
    38. void MySplitter::keepSizeMove(int pos, int index)
    39. {
    40. if (this->parentWidget() == NULL)
    41. return;
    42.  
    43. QList<int> newSizes = this->sizes();
    44. int originalSize = originalSizes.at(index - 1);
    45. int newSize = newSize.at(index - 1);
    46. int deltaSize = newSize - originalSize;
    47.  
    48. int width = this->parentWidget()->width();
    49. int height = this->parentWidget()->height();
    50.  
    51. ... ...
    52.  
    53. if (this->orientation() == Qt::Horizontal)
    54. {
    55. this->parentWidget()->resize(width + deltaSize, height);
    56. }
    57. else
    58. {
    59. this->parentWidget()->resize(width, height + deltaSize);
    60. }
    61.  
    62. this->parentWidget()->repaint();
    63. }
    To copy to clipboard, switch view to plain text mode 


    my problem is : "originalSizes" always get (0, 0).

    I try to use "setSizes()" and "originalSizes" will get value but a wrong value.(setSizes() fails)

    Qt Code:
    1. // in Widget.cpp
    2. Widget::Widget(QWidget *parent)
    3. {
    4. ... ...
    5.  
    6. this->resize(200, 200);
    7.  
    8. QList<int>sizes;
    9. sizes << 100 << 100;
    10. mySplitter->setSizes(sizes);
    11.  
    12. // returns (20, 21), setSizes() fails!
    13. qDebug() << mySplitter->sizes();
    14. }
    To copy to clipboard, switch view to plain text mode 

    I googled and found that none had solved yet. (refer to http://www.qtcentre.org/archive/index.php/t-26520.html)

    Need help!


    Thank you in advance!


    Tang Tao

  10. #9
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: problem with QSplitter

    You are constructing your MySplitter instance at line 5 of your first listing. At this point in time it has no widgets to split but you are assuming it does. Until you have added widgets to the splitter and the widget containing the splitter is shown there are no sizes.

  11. The following user says thank you to ChrisW67 for this useful post:

    tangtao_xp (27th June 2013)

  12. #10
    Join Date
    Apr 2013
    Posts
    24
    Thanks
    4
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: problem with QSplitter

    Quote Originally Posted by ChrisW67 View Post
    You are constructing your MySplitter instance at line 5 of your first listing. At this point in time it has no widgets to split but you are assuming it does. Until you have added widgets to the splitter and the widget containing the splitter is shown there are no sizes.
    Thank you, ChrisW67! It works! I should call sizes() until the parent widget is shown.

    Now, I think I could go on with my work.



    Tang Tao

Similar Threads

  1. Problem with QSplitter
    By kistmaximum in forum Qt Programming
    Replies: 2
    Last Post: 10th June 2012, 01:28
  2. qsplitter
    By marc2050 in forum Newbie
    Replies: 3
    Last Post: 31st May 2011, 16:06
  3. Bug in QSplitter with Qt4.5.1
    By araglin in forum Qt Programming
    Replies: 1
    Last Post: 28th April 2009, 07:45
  4. QSplitter
    By weixj2003ld in forum Qt Programming
    Replies: 1
    Last Post: 8th April 2009, 13:46
  5. QSplitter
    By Solarity in forum Newbie
    Replies: 2
    Last Post: 10th February 2006, 17:05

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.