Results 1 to 8 of 8

Thread: Scroll checkboxes in tabWidget

  1. #1
    Join Date
    Jul 2007
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    3

    Default Scroll checkboxes in tabWidget

    I have created with "QT Designer" simple form with tabWidget
    I need to dynamically add checkboxes to tab area:

    in my constructor:

    ======
    ui.setupUi(this);

    ui.tabWidget->QTabWidget::setTabText(0, QString::fromLocal8Bit("Params"));
    ui.tabWidget->QTabWidget::setTabText(1, QString::fromLocal8Bit("SysParams"));



    QCheckBox *mycheckBox[100];

    mycheckBox[0] = new QCheckBox(ui.tab);
    mycheckBox[0]->setObjectName(QString::fromUtf8("mycheckBox[0]"));
    mycheckBox[0]->setGeometry(QRect(30, 30, 331, 18));
    mycheckBox[0]->setText(QApplication::translate("BarkasikForm", "myCheckBox0", 0, QApplication::UnicodeUTF8));
    =======

    I can't understand how to scroll tab area when number of checkboxes > 10 and out of viewable area.

    I found some code:

    =====
    QScrollArea *scrollArea;
    scrollArea = new QScrollArea(ui.tab);
    scrollArea->setBackgroundRole(QPalette:ark);
    scrollArea->setWidget(ui.<?????????>);
    =====


    Help please!

  2. #2
    Join Date
    Mar 2006
    Location
    The Netherlands
    Posts
    300
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11
    Thanks
    9
    Thanked 29 Times in 29 Posts

    Default Re: Scroll checkboxes in tabWidget

    Something like:

    Qt Code:
    1. QScrollArea* scrollArea = new QScrollArea(ui.tab);
    2. QWidget* checkboxes = new QWidget(scrollArea);
    3. scrollArea->setWidget(checkboxes);
    4.  
    5. // ...
    6.  
    7. mycheckBox[0] = new QCheckBox(checkboxes);
    8.  
    9. // ...
    To copy to clipboard, switch view to plain text mode 

    Beware of bugs. This code has not been tested.
    "The strength of a civilization is not measured by its ability to wage wars, but rather by its ability to prevent them." - Gene Roddenberry

  3. #3
    Join Date
    Jul 2007
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    3

    Default Re: Scroll checkboxes in tabWidget


    Checkboxes is not visible.

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

    Default Re: Scroll checkboxes in tabWidget

    Use layouts. And construct the content first, then set it to the scroll area.
    Qt Code:
    1. QScrollArea* scrollArea = new QScrollArea(ui.tab);
    2. QWidget* checkboxes = new QWidget(scrollArea);
    3. QVBoxLayout* layout = new QVBoxLayout(checkboxes);
    4. for (int i = 0; i < 100; ++i)
    5. {
    6. mycheckBox[i] = new QCheckBox(checkboxes);
    7. ...
    8. layout->addWidget(mycheckBox[i]);
    9. }
    10. scrollArea->setWidget(checkboxes); // must be last, "QWidget checkboxes" is resized according to its size hint
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

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

    Amindo (19th July 2007)

  6. #5
    Join Date
    Jul 2007
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    3

    Default Re: Scroll checkboxes in tabWidget

    Thanks. Works fine. But how to set size of scrollable layout to fit tab frame geometry?
    Attached Images Attached Images

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

    Default Re: Scroll checkboxes in tabWidget

    You must apply a layout to the tab page as well. Where do you add the tabs, in code or in designer?

    Edit: Oh, what's "ui.tab"? Presumably "ui.tabWidget" is the tab widget, so is "ui.tab" the first tab page?
    Qt Code:
    1. QScrollArea* scrollArea = new QScrollArea(ui.tab);
    2. QVBoxLayout* pageLayout = new QVBoxLayout(ui.tab);
    3. pageLayout->addWidget(scrollArea);
    4. ...
    To copy to clipboard, switch view to plain text mode 
    Or simply add the scroll area and apply a layout in designer..
    J-P Nurmi

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

    Amindo (19th July 2007)

  9. #7
    Join Date
    Jul 2007
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    3

    Thumbs up Re: Scroll checkboxes in tabWidget

    Thanks fine code!


    For hystory: my working code......

    Qt Code:
    1. ScrollArea* scrollArea = new QScrollArea(ui.tab);
    2. QWidget* checkboxes = new QWidget(scrollArea);
    3. QVBoxLayout* layout = new QVBoxLayout(checkboxes);
    4.  
    5. QVBoxLayout* pageLayout = new QVBoxLayout(ui.tab);
    6. pageLayout->addWidget(scrollArea);
    7.  
    8.  
    9. QCheckBox *mycheckBox[100];
    10.  
    11. for (int i = 0; i < 100; ++i)
    12. {
    13.  
    14. mycheckBox[i] = new QCheckBox(checkboxes);
    15. mycheckBox[i]->setGeometry(QRect(30, 30, 331, 18));
    16. mycheckBox[i]->setText(QApplication::translate("BarkasikForm", "my0", 0, QApplication::UnicodeUTF8));
    17.  
    18. layout->addWidget(mycheckBox[i]);
    19.  
    20. }
    21.  
    22. scrollArea->setWidget(checkboxes);
    To copy to clipboard, switch view to plain text mode 
    Attached Images Attached Images
    Last edited by Amindo; 19th July 2007 at 13:31. Reason: updated contents

  10. #8
    Join Date
    Mar 2006
    Location
    The Netherlands
    Posts
    300
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11
    Thanks
    9
    Thanked 29 Times in 29 Posts

    Default Re: Scroll checkboxes in tabWidget

    Now that the checkboxes are in a layout, you can leave out the setGeometry call.
    "The strength of a civilization is not measured by its ability to wage wars, but rather by its ability to prevent them." - Gene Roddenberry

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

    Amindo (20th July 2007)

Similar Threads

  1. QScrollArea's Scroll Bars
    By ToddAtWSU in forum Qt Programming
    Replies: 5
    Last Post: 19th September 2006, 13:27

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.