Results 1 to 4 of 4

Thread: why the QSplitter cannot show the width as I specified?

  1. #1
    Join Date
    May 2011
    Location
    North Carolina
    Posts
    23
    Thanks
    10
    Qt products
    Qt4

    Default why the QSplitter cannot show the width as I specified?

    Hi, I have encountered a weird problem:

    Qt Code:
    1. hctrl = new QTextBrowser();////////////////////////////
    2. hctrl->setReadOnly(TRUE);
    3.  
    4. hctrl->setFixedHeight(150);
    5.  
    6. QSplitter* LeftPanel=new QSplitter(Qt::Vertical);
    7. LeftPanel->setFixedWidth(18);
    8. LeftPanel->setFixedHeight(150);
    9.  
    10. QPushButton* quickButton=new QPushButton("@",LeftPanel);
    11. QPushButton* focusButton=new QPushButton("F",LeftPanel);
    12. QPushButton* infoButton=new QPushButton("I",LeftPanel);
    13. QPushButton* zoomButton=new QPushButton("Z",LeftPanel);
    14. QPushButton* firstButton=new QPushButton("H",LeftPanel);
    15. QPushButton* lastButton=new QPushButton("E",LeftPanel);
    16. QPushButton* closeButton=new QPushButton("C",LeftPanel);
    17.  
    18.  
    19. clustercanvas= new QGLWidget;
    20. clustercanvas->setFixedWidth(325);
    21. clustercanvas->setFixedHeight(150);
    22. panel = new QSplitter(Qt::Horizontal);
    23. panel->addWidget(LeftPanel);
    24. panel->addWidget(hctrl);
    25. panel->addWidget(clustercanvas);
    To copy to clipboard, switch view to plain text mode 

    However, the display is like this:


    The width of the left part (marked by red pen) is actually 360 instead of 18.

    Why? How can I keep the width of the left part to be 18?

    Thanks a lot!

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 453 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: why the QSplitter cannot show the width as I specified?

    Qt Code:
    1. ...
    2. panel = new QSplitter(Qt::Horizontal);
    3. panel->addWidget(LeftPanel);
    4. panel->addWidget(hctrl);
    5. panel->addWidget(clustercanvas);
    6.  
    7. int index = panel.indexOf(LeftPanel);
    8. if(index > -1)
    9. {
    10. QList<int> sizes = panel.sizes();
    11. sizes[index] = 18;
    12. panel.setSizes(sizes);
    13. }
    To copy to clipboard, switch view to plain text mode 

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

    superwave (14th July 2011)

  4. #3
    Join Date
    May 2011
    Location
    North Carolina
    Posts
    23
    Thanks
    10
    Qt products
    Qt4

    Default Re: why the QSplitter cannot show the width as I specified?

    Hi, thank you very much, I have tried your method, but the result is the same.


    Added after 25 minutes:


    I followed your idea.

    Since the number o button in the panel is not too many, I just set the width of the buttons directly by setfixedwith(16);

    Thanks again.
    Last edited by superwave; 14th July 2011 at 05:20.

  5. #4
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 453 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: why the QSplitter cannot show the width as I specified?

    you can also set the size for LeftPanel directly

Similar Threads

  1. qsplitter
    By marc2050 in forum Newbie
    Replies: 3
    Last Post: 31st May 2011, 16:06
  2. Replies: 3
    Last Post: 12th July 2010, 13:12
  3. QToolBox width fixed to maximum content width
    By ghorwin in forum Qt Programming
    Replies: 0
    Last Post: 10th July 2009, 09:58
  4. QSplitter
    By weixj2003ld in forum Qt Programming
    Replies: 1
    Last Post: 8th April 2009, 13:46
  5. How to set QTableView width to width of horizontal header?
    By martinb0820 in forum Qt Programming
    Replies: 0
    Last Post: 2nd December 2008, 20:51

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.