Results 1 to 10 of 10

Thread: problem with QSplitter

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    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

  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

    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.

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

    tangtao_xp (27th June 2013)

  4. #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
    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
  •  
Qt is a trademark of The Qt Company.