Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How can I add dynamic checkboxes to scrollareaWidget?
Forum Updated to NodeBB v4.3 + New Features

How can I add dynamic checkboxes to scrollareaWidget?

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 4.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    I-sty
    wrote on last edited by
    #1

    Hi,

    I would to add many checkboxes to a scroll area.

    I wrote this script, but don't work.

    @QCheckBox *dynamicCheckBox = new QCheckBox();
    long YSpacer = -25;
    for (int count = 0; count < QVSideList->size(); ++count)
    {
    YSpacer += 26;
    dynamicCheckBox->setObjectName ("dynamicCheckBox" + QString(count));
    dynamicCheckBox->setCheckable (true);
    dynamicCheckBox->setChecked (true);
    int TextWidth = QVSideList->at (count).File.size ();
    dynamicCheckBox->setGeometry (10, YSpacer, TextWidth, 17);
    dynamicCheckBox->setText (QVSideList->at (count).File);
    //layout ()->addWidget (dynamicCheckBox);
    ui->FolderSync::scrollAreaWidgetContents->layout ()->addWidget (dynamicCheckBox);
    }@

    Sorry, for my bad English. My first language is Hungarian.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mlong
      wrote on last edited by
      #2

      You only have one QCheckBox you're working with. (One call to new QCheckBox() )

      In your for loop, you're just fiddling around with that same widget instance over and over.

      If you want multiple check boxes, you'll have to call new for each one inside of your loop.

      Software Engineer
      My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

      1 Reply Last reply
      0
      • I Offline
        I Offline
        I-sty
        wrote on last edited by
        #3

        @long YSpacer = -25;
        for (int count = 0; count < QVSideList->size(); ++count)
        {
        YSpacer += 26;
        QCheckBox *dynamicCheckBox = new QCheckBox();
        dynamicCheckBox->setObjectName ("dynamicCheckBox" + QString(count));
        dynamicCheckBox->setCheckable (true);
        dynamicCheckBox->setChecked (true);
        int TextWidth = QVSideList->at (count).File.size ();
        dynamicCheckBox->setGeometry (10, YSpacer, TextWidth, 17);
        dynamicCheckBox->setText (QVSideList->at (count).File);
        //layout ()->addWidget (dynamicCheckBox);
        ui->FolderSync::scrollAreaWidgetContents->layout ()->addWidget (dynamicCheckBox); //this line
        }
        }@

        Everything is okay, but I get segmentation fault on the last line.

        Sorry, for my bad English. My first language is Hungarian.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved