Results 1 to 8 of 8

Thread: scrollBar in tabWidgets

  1. #1
    Join Date
    Aug 2007
    Posts
    275
    Thanks
    28
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default scrollBar in tabWidgets

    i put a GroupBox inside my tabWidget and added lots of widgets in my groupBox, now how can i enable the scrollBar in my groupBox so that it i can view all my widgets.

    or is there any other container that has a scrollBar that can be enable.

    baray98

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: scrollBar in tabWidgets

    Sounds like you have this kind of structure:
    [html]
    QGroupBox
    |-ChildWidget1
    |-ChildWidget2
    |- ...
    [/html]

    Make it like this:
    [html]
    QGroupBox
    |-QScrollArea
    |-ChildWidget1
    |-ChildWidget2
    |-...
    [/html]
    J-P Nurmi

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

    baray98 (17th September 2007)

  4. #3
    Join Date
    Aug 2007
    Posts
    275
    Thanks
    28
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: scrollBar in tabWidgets

    i still can not make it to scroll here my code below

    (this is at the constructor and this class inherits QGroupBox)
    Qt Code:
    1. frame = new QFrame (this);
    2. scroll = new QScrollArea(this);
    3. scroll->setWidget(frame);
    4.  
    5. mainLayout = new QVBoxLayout(this);
    6. frame->setLayout(mainLayout);
    7. mainLayout->addStretch();
    8.  
    9. QVBoxLayout * topLayout = new QVBoxLayout (this);
    10. topLayout->addWidget(frame);
    11.  
    12. setLayout(topLayout);
    To copy to clipboard, switch view to plain text mode 

    i have a method called addInfo below

    Qt Code:
    1. void FrameInfo::addInfo(QString infoName, double val)
    2. {
    3. QHBoxLayout* infoLayout = new QHBoxLayout(this);
    4.  
    5. QLabel* lblValue = new QLabel (infoName,this);
    6. infoLayout->addWidget(lblValue);
    7.  
    8.  
    9. QString txtValue = QString("%1").arg(val, 2, 'f', 3);;
    10.  
    11. QLineEdit* leValue = new QLineEdit (txtValue,this);
    12. leValue->setReadOnly ( true );
    13. leValue->setAlignment(Qt::AlignRight);
    14. infoLayout->addWidget(leValue);
    15.  
    16. infoLayout->addStretch();
    17.  
    18. mainLayout->insertLayout(mainLayout->count()-1,infoLayout);
    19.  
    20. }
    To copy to clipboard, switch view to plain text mode 

    its all a mess please help

    baray98

  5. #4
    Join Date
    Aug 2007
    Posts
    275
    Thanks
    28
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: scrollBar in tabWidgets

    my full cocstructor looks like this
    Qt Code:
    1. FrameInfo::FrameInfo(QWidget* parent )
    2. :QGroupBox(parent)
    3. {
    4. //ctor
    5. frame = new QFrame (this);
    6. scroll = new QScrollArea(this);
    7. scroll->setWidget(frame);
    8.  
    9. mainLayout = new QVBoxLayout(this);
    10. frame->setLayout(mainLayout);
    11. mainLayout->addStretch();
    12.  
    13. QVBoxLayout * topLayout = new QVBoxLayout (this);
    14. topLayout->addWidget(frame);
    15.  
    16. setLayout(topLayout);
    17. }
    To copy to clipboard, switch view to plain text mode 

  6. #5
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: scrollBar in tabWidgets

    I am afraid the first code snippet you posted makes no freakin' sense .

    General QScrollArea usage: all widgets that you want to be contained by then scroll area have to be contained by a top level(container) widget. This container has to be added to the scroll area.

    So, here's an example. You can add this to your custom group box constructor:
    Qt Code:
    1. QVBoxLayout *topLayout = new QVBoxLayout(this);
    2. QScrollArea* scrollArea = new QScrollArea(this);
    3. topLayout->addWidget(scrollArea);
    4. setLayout(topLayout);
    5.  
    6. //Now, for the group box
    7. QWidget* holder = new QWidget(scrollArea);
    8. mainLayout = new QVBoxLayout(holder);
    9. holder->setLayout(mainLayout);
    10. scrollArea->setWidget(holder);
    To copy to clipboard, switch view to plain text mode 


    Now you can add widgets to holder widget, just like you did in the second code snippet, with the exception that you must not pass 'this' as parent for the new widgets, but the holder widget.

  7. The following user says thank you to marcel for this useful post:

    baray98 (17th September 2007)

  8. #6
    Join Date
    Aug 2007
    Posts
    275
    Thanks
    28
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: scrollBar in tabWidgets

    marcel, thanks for the quick reply .. but when i changed my code below all i see i a big widget inside my groupBox. I did not see any of my text edits and labels and there was no scroll bar either.

    Qt Code:
    1. FrameInfo::FrameInfo(QWidget* parent )
    2. :QGroupBox(parent)
    3. {
    4. //ctor
    5.  
    6. QVBoxLayout *topLayout = new QVBoxLayout(this);
    7. QScrollArea* scrollArea = new QScrollArea(this);
    8. topLayout->addWidget(scrollArea);
    9. setLayout(topLayout);
    10.  
    11. //Now, for the group box
    12. holder = new QWidget(scrollArea);
    13. mainLayout = new QVBoxLayout(holder);
    14. holder->setLayout(mainLayout);
    15. mainLayout->addStretch();
    16.  
    17. scrollArea->setWidget(holder);
    18. }
    19.  
    20. FrameInfo::~FrameInfo()
    21. {
    22. //dtor
    23. }
    24.  
    25. void FrameInfo::addInfo(QString infoName, double val)
    26. {
    27. QHBoxLayout* infoLayout = new QHBoxLayout(holder);
    28.  
    29. QLabel* lblValue = new QLabel (infoName,holder);
    30. infoLayout->addWidget(lblValue);
    31.  
    32.  
    33. QString txtValue = QString("%1").arg(val, 2, 'f', 3);
    34.  
    35. QLineEdit* leValue = new QLineEdit (txtValue,holder);
    36. leValue->setReadOnly ( true );
    37. leValue->setAlignment(Qt::AlignRight);
    38. infoLayout->addWidget(leValue);
    39.  
    40. infoLayout->addStretch();
    41. mainLayout->insertLayout(mainLayout->count()-1,infoLayout);
    42.  
    43. }
    To copy to clipboard, switch view to plain text mode 

    this really confusing me

    baray98

  9. #7
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: scrollBar in tabWidgets

    Try this:
    Qt Code:
    1. void FrameInfo::addInfo(QString infoName, double val)
    2. {
    3. QHBoxLayout* infoLayout = new QHBoxLayout; // (holder); <-- remove parent, holder already has a layout installed (produces warning)
    4. ...
    5. holder->adjustSize(); // <-- add this as last statement of addInfo()
    6. }
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  10. The following user says thank you to jpn for this useful post:

    baray98 (17th September 2007)

  11. #8
    Join Date
    Aug 2007
    Posts
    275
    Thanks
    28
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: scrollBar in tabWidgets

    thanks!!! a lot it work now

Similar Threads

  1. Scrollbar in QTreeWidget
    By sabeesh in forum Qt Programming
    Replies: 3
    Last Post: 23rd August 2007, 09:48
  2. GraphicsView/GraphicsScene: scrollbar policy Qt::ScrollBarAsNeeded
    By Pieter from Belgium in forum Qt Programming
    Replies: 4
    Last Post: 21st March 2007, 13:15
  3. about scrollbar style
    By qtopiahooo in forum Qt Programming
    Replies: 1
    Last Post: 25th January 2007, 13:34
  4. how to scroll tablewidget from outside placed scrollbar
    By chemstar in forum Qt Programming
    Replies: 5
    Last Post: 1st June 2006, 14:42
  5. QTableView number of rows and scrollbar issue
    By jnk5y in forum Qt Programming
    Replies: 3
    Last Post: 1st March 2006, 06:55

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.