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 dynamically insert a custom widget into a scroll area
Forum Updated to NodeBB v4.3 + New Features

How to dynamically insert a custom widget into a scroll area

Scheduled Pinned Locked Moved General and Desktop
10 Posts 3 Posters 5.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.
  • A Offline
    A Offline
    astodolski
    wrote on 15 Feb 2014, 03:07 last edited by
    #1

    I have a custom widget, built in designer, made up of a row of label, progress bar, check box. In the main form, I have a scroll area, also created in the designer. I want to know how to effectively dynamically add the custom widget as as rows in the scroll area.

    MainWindow.cpp
    @
    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include "ui_Controls.h"

    MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
    {
    ui->setupUi(this);
    }

    MainWindow::~MainWindow()
    {
    delete ui;
    }

    void MainWindow::on_actionE_xit_triggered()
    {
    QApplication::quit();
    }

    void MainWindow::on_actionFile_triggered()
    {
    int i = ui->verticalLayout->count();

    ctls = new Controls();

    QHBoxLayout* hblayout = new QHBoxLayout();

    hblayout->addWidget(ctls);

    QWidget* window = new QWidget;
    window->setLayout(hblayout);
    window->show();

    ui->verticalLayout->addWidget(window);

    }
    @

    The Main Window grows downward rather than a vertical scroll bar appearing.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 15 Feb 2014, 21:28 last edited by
      #2

      Hi,

      You need to set a widget on the QScrollArea containing a QVBoxLayout. Then add your newly created widget with to that layout.

      Hope it helps

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • A Offline
        A Offline
        astodolski
        wrote on 18 Feb 2014, 12:36 last edited by
        #3

        [quote author="SGaist" date="1392499717"]Hi,

        You need to set a widget on the QScrollArea containing a QVBoxLayout. Then add your newly created widget with to that layout.

        Hope it helps[/quote]

        I changed the approach as to how to display the widget and instead use a QListWidget. The thread is "here":http://qt-project.org/forums/viewthread/38539/. Still doesn't work

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 18 Feb 2014, 20:42 last edited by
          #4

          It's not exactly the same concept then

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • A Offline
            A Offline
            astodolski
            wrote on 18 Feb 2014, 21:02 last edited by
            #5

            No less troubling though. Can you offer assistance?

            1 Reply Last reply
            0
            • D Offline
              D Offline
              DBoosalis
              wrote on 18 Feb 2014, 21:23 last edited by
              #6

              I think QListWidget is rather limited. I would say use QListView if you are going to endup with lots of items in your scroll area and are prepared write your own paint delegate.

              It really can't get any easier then using a VerticalGridLayout and using its addWidget() method

              1 Reply Last reply
              0
              • A Offline
                A Offline
                astodolski
                wrote on 18 Feb 2014, 21:40 last edited by
                #7

                [quote author="DBoosalis" date="1392758583"]I think QListWidget is rather limited. I would say use QListView if you are going to endup with lots of items in your scroll area and are prepared write your own paint delegate.

                It really can't get any easier then using a VerticalGridLayout and using its addWidget() method

                [/quote]

                Got an example? I only know of QGridLayout

                1 Reply Last reply
                0
                • D Offline
                  D Offline
                  DBoosalis
                  wrote on 18 Feb 2014, 22:11 last edited by
                  #8

                  Documentation is a good place to start.

                  1 Reply Last reply
                  0
                  • A Offline
                    A Offline
                    astodolski
                    wrote on 19 Feb 2014, 03:55 last edited by
                    #9

                    [quote author="DBoosalis" date="1392761494"]Documentation is a good place to start. [/quote]

                    I can't find any documentation on VerticalGridLayout. That's why I asked for an example. I wanted to see an example how it can't get any easier. BTW VerticalGridLayout is part of Java.

                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on 19 Feb 2014, 07:59 last edited by
                      #10

                      There's no vertical grid layout, you have "QVBoxLayout":http://qt-project.org/doc/qt-5/qvboxlayout.html to layout things vertically. You still can use a QGridLayout if you want, you just need to add rows

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      0

                      1/10

                      15 Feb 2014, 03:07

                      • Login

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