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 to populate Spinboxes on scroll area
Forum Updated to NodeBB v4.3 + New Features

How to populate Spinboxes on scroll area

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 3 Posters 501 Views
  • 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.
  • S Offline
    S Offline
    summit
    wrote on last edited by summit
    #1

    This is my code where i am trying to populate spin boxes in the scroll area but the window shows without the scroll area and the spinboxes.

    void ShowCommands::showWindow()
    {
    	QWidget *wdg = new QWidget;
    	QVBoxLayout m_layout{ wdg };
    	QScrollArea m_area;
    	QWidget m_contents;
    	QVBoxLayout m_contentsLayout{ &m_contents };
    	QSpinBox m_spinBoxes[10];
    	m_layout.addWidget(&m_area);
    	m_area.setWidget(&m_contents);
    	for (auto & spinbox : m_spinBoxes)
    		m_contentsLayout.addWidget(&spinbox);
    	
    	m_contentsLayout.setSizeConstraint(QLayout::SetMinimumSize);
    	wdg->setWindowTitle("Commands");
    	wdg->show();
    }
    
    jsulmJ 1 Reply Last reply
    0
    • S summit

      This is my code where i am trying to populate spin boxes in the scroll area but the window shows without the scroll area and the spinboxes.

      void ShowCommands::showWindow()
      {
      	QWidget *wdg = new QWidget;
      	QVBoxLayout m_layout{ wdg };
      	QScrollArea m_area;
      	QWidget m_contents;
      	QVBoxLayout m_contentsLayout{ &m_contents };
      	QSpinBox m_spinBoxes[10];
      	m_layout.addWidget(&m_area);
      	m_area.setWidget(&m_contents);
      	for (auto & spinbox : m_spinBoxes)
      		m_contentsLayout.addWidget(&spinbox);
      	
      	m_contentsLayout.setSizeConstraint(QLayout::SetMinimumSize);
      	wdg->setWindowTitle("Commands");
      	wdg->show();
      }
      
      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @summit said in How to populate Spinboxes on scroll area:

      QSpinBox m_spinBoxes[10];

      This is local arrray which is destroyed together with all spin boxes as soon as showWindow() finishes...
      Also QVBoxLayout m_layout{ wdg }; QScrollArea m_area; QWidget m_contents; are local stack variables...

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      S 1 Reply Last reply
      2
      • S Offline
        S Offline
        summit
        wrote on last edited by
        #3
        This post is deleted!
        1 Reply Last reply
        0
        • jsulmJ jsulm

          @summit said in How to populate Spinboxes on scroll area:

          QSpinBox m_spinBoxes[10];

          This is local arrray which is destroyed together with all spin boxes as soon as showWindow() finishes...
          Also QVBoxLayout m_layout{ wdg }; QScrollArea m_area; QWidget m_contents; are local stack variables...

          S Offline
          S Offline
          summit
          wrote on last edited by summit
          #4

          @jsulm i have changed my code but still spinboxes are missing from the window.

          QWidget *wdg = new QWidget;
          	QVBoxLayout *m_layout = new QVBoxLayout;
          	QScrollArea *m_area = new QScrollArea;
          	QWidget *m_contents = new QWidget;
          	QVBoxLayout *m_contentsLayout = new QVBoxLayout;
          	m_contentsLayout->setParent(m_contents);
          	m_layout->addWidget(m_area);
          	m_area->setWidget(m_contents);
          	for (auto & spinbox : m_spinBoxes)  // m_spinBoxes is class varibles QSpinBox m_spinBoxes[10]
          		m_contentsLayout->addWidget(&spinbox);
          
          	m_contentsLayout->setSizeConstraint(QLayout::SetMinimumSize);
          	wdg->setLayout(m_layout);
          	wdg->setWindowTitle("Commands");
          	wdg->show();
          
          JonBJ jsulmJ 2 Replies Last reply
          0
          • S summit

            @jsulm i have changed my code but still spinboxes are missing from the window.

            QWidget *wdg = new QWidget;
            	QVBoxLayout *m_layout = new QVBoxLayout;
            	QScrollArea *m_area = new QScrollArea;
            	QWidget *m_contents = new QWidget;
            	QVBoxLayout *m_contentsLayout = new QVBoxLayout;
            	m_contentsLayout->setParent(m_contents);
            	m_layout->addWidget(m_area);
            	m_area->setWidget(m_contents);
            	for (auto & spinbox : m_spinBoxes)  // m_spinBoxes is class varibles QSpinBox m_spinBoxes[10]
            		m_contentsLayout->addWidget(&spinbox);
            
            	m_contentsLayout->setSizeConstraint(QLayout::SetMinimumSize);
            	wdg->setLayout(m_layout);
            	wdg->setWindowTitle("Commands");
            	wdg->show();
            
            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by JonB
            #5

            @summit said in How to populate Spinboxes on scroll area:

            m_contentsLayout->setParent(m_contents);

            I'm not sure this is good enough. Where did you get the inspiration to do it this way? The usual is m_contents->setLayout(m_contentsLayout)?

            1 Reply Last reply
            2
            • S summit

              @jsulm i have changed my code but still spinboxes are missing from the window.

              QWidget *wdg = new QWidget;
              	QVBoxLayout *m_layout = new QVBoxLayout;
              	QScrollArea *m_area = new QScrollArea;
              	QWidget *m_contents = new QWidget;
              	QVBoxLayout *m_contentsLayout = new QVBoxLayout;
              	m_contentsLayout->setParent(m_contents);
              	m_layout->addWidget(m_area);
              	m_area->setWidget(m_contents);
              	for (auto & spinbox : m_spinBoxes)  // m_spinBoxes is class varibles QSpinBox m_spinBoxes[10]
              		m_contentsLayout->addWidget(&spinbox);
              
              	m_contentsLayout->setSizeConstraint(QLayout::SetMinimumSize);
              	wdg->setLayout(m_layout);
              	wdg->setWindowTitle("Commands");
              	wdg->show();
              
              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by jsulm
              #6

              @summit With your current code you'll get a warning at runtime, check that.
              This works:

              QWidget *wdg = new QWidget;
              QVBoxLayout *m_layout = new QVBoxLayout;
              QScrollArea *m_area = new QScrollArea;
              QWidget *m_contents = new QWidget;
              QVBoxLayout *m_contentsLayout = new QVBoxLayout;
              m_contents->setLayout(m_contentsLayout);
              m_layout->addWidget(m_area);
              m_area->setWidget(m_contents);
              for (auto & spinbox : m_spinBoxes)  // m_spinBoxes is class varibles QSpinBox m_spinBoxes[10]
                  m_contentsLayout->addWidget(&spinbox);
              
              m_contentsLayout->setSizeConstraint(QLayout::SetMinimumSize);
              wdg->setLayout(m_layout);
              wdg->setWindowTitle("Commands");
              wdg->show();
              

              But since wdg is not parented it will be shown in its own window...

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              S 1 Reply Last reply
              3
              • jsulmJ jsulm

                @summit With your current code you'll get a warning at runtime, check that.
                This works:

                QWidget *wdg = new QWidget;
                QVBoxLayout *m_layout = new QVBoxLayout;
                QScrollArea *m_area = new QScrollArea;
                QWidget *m_contents = new QWidget;
                QVBoxLayout *m_contentsLayout = new QVBoxLayout;
                m_contents->setLayout(m_contentsLayout);
                m_layout->addWidget(m_area);
                m_area->setWidget(m_contents);
                for (auto & spinbox : m_spinBoxes)  // m_spinBoxes is class varibles QSpinBox m_spinBoxes[10]
                    m_contentsLayout->addWidget(&spinbox);
                
                m_contentsLayout->setSizeConstraint(QLayout::SetMinimumSize);
                wdg->setLayout(m_layout);
                wdg->setWindowTitle("Commands");
                wdg->show();
                

                But since wdg is not parented it will be shown in its own window...

                S Offline
                S Offline
                summit
                wrote on last edited by
                #7

                @jsulm Thank you very much this works.

                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