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. Addition QCheckBoxes to QScrollArea
Forum Updated to NodeBB v4.3 + New Features

Addition QCheckBoxes to QScrollArea

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 290 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.
  • Evgeny SiberiaE Offline
    Evgeny SiberiaE Offline
    Evgeny Siberia
    wrote on last edited by Evgeny Siberia
    #1

    Hi. How correctly to do this?

    QWidget materialContainer;
    QVBoxLayout *materialLay = new QVBoxLayout(this);
    materialContainer.setLayout(materialLay);
    ui->_materialScrollArea->setWidget(&materialContainer);
    foreach(NodePtr ptr, _materialModel->allItems())
    {
        Material *entity = ptr.data()->item().value<Material*>();
        QCheckBox *chBox = new QCheckBox(entity->name());
        materialLay->addWidget(chBox);
    }
    

    Where did I go wrong? I need for each entity QCheckBox.

    if you see mistakes in English tell me about it

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Evgeny-Siberia said in Addition QCheckBoxes to QScrollArea:

      QVBoxLayout *materialLay = new QVBoxLayout(this);
      materialContainer.setLayout(materialLay);

      This is wrong. The ctor of QVBoxLayout already sets the layout to the given parent which you don't want to.

      QVBoxLayout *materialLay = new QVBoxLayout(&materialContainer)

      Apart from this - how long do you think does materialContainer live?

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      Pl45m4P Evgeny SiberiaE 2 Replies Last reply
      4
      • Christian EhrlicherC Christian Ehrlicher

        @Evgeny-Siberia said in Addition QCheckBoxes to QScrollArea:

        QVBoxLayout *materialLay = new QVBoxLayout(this);
        materialContainer.setLayout(materialLay);

        This is wrong. The ctor of QVBoxLayout already sets the layout to the given parent which you don't want to.

        QVBoxLayout *materialLay = new QVBoxLayout(&materialContainer)

        Apart from this - how long do you think does materialContainer live?

        Pl45m4P Offline
        Pl45m4P Offline
        Pl45m4
        wrote on last edited by Pl45m4
        #3

        @Christian-Ehrlicher said in Addition QCheckBoxes to QScrollArea:

        The ctor of QVBoxLayout already sets the layout to the given parent which you don't want to.

        IIRC, setLayout re-"parents" the layout, so that after this line the materialContainer - QWidget is the new parent of materialLayout.
        ((this) is still not necessary and can be removed).

        @Evgeny-Siberia

        Change QWidget materialContainer to

        QWidget* materialContainer = new QWidget;
        

        then remove the & in setWidget and it should work (cant tell if the rest is ok).


        If debugging is the process of removing software bugs, then programming must be the process of putting them in.

        ~E. W. Dijkstra

        1 Reply Last reply
        1
        • Christian EhrlicherC Christian Ehrlicher

          @Evgeny-Siberia said in Addition QCheckBoxes to QScrollArea:

          QVBoxLayout *materialLay = new QVBoxLayout(this);
          materialContainer.setLayout(materialLay);

          This is wrong. The ctor of QVBoxLayout already sets the layout to the given parent which you don't want to.

          QVBoxLayout *materialLay = new QVBoxLayout(&materialContainer)

          Apart from this - how long do you think does materialContainer live?

          Evgeny SiberiaE Offline
          Evgeny SiberiaE Offline
          Evgeny Siberia
          wrote on last edited by Evgeny Siberia
          #4

          @Christian-Ehrlicher

          Apart from this - how long do you think does materialContainer live?

          kid error

          IIRC, setLayout re-"parents" the layout

          you are right

          Thank you all!

          if you see mistakes in English tell me about it

          1 Reply Last reply
          1

          • Login

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