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. QLabel Addition to layout
Qt 6.11 is out! See what's new in the release blog

QLabel Addition to layout

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 1.4k Views 2 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.
  • J Offline
    J Offline
    jss193
    wrote on last edited by
    #1

    Hello everybody,

    I have created a table where if I add an item it creates a row in table and a new qlabel such as:

    void MainWindow::on_pushButton_clicked()
    {
        model->insertRows(0,1);
    
    
        QSpacerItem *item = new QSpacerItem(1,1,QSizePolicy::Expanding,QSizePolicy::Fixed);
        ui->horizontalLayout_2->addSpacerItem(item);
        for(int i =0;i<1;i++){
            QLabel *label1 = new QLabel("NOTE");
            ui->horizontalLayout_2->insertWidget(i,label1);
    
        }
    
    }
    

    But I want to know 2 things:

    1. how can I have access to second qlabel added, I mean, what is its name? label1, label2....to get acces to any of them

    2. When I add too many qlabels they supperpose each other, how do I readapt its size?

    Thanks!

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      A plain layout cannot scroll. so if labels have no minimum size set. then at some point, they will be compressed.
      You can use a QScrollArea for a widget that can scroll the Labels.

      However, why do you not use something like QListWidget that is a scroll list of Texts, ready to be edited if you want.

      1 Reply Last reply
      2
      • J Offline
        J Offline
        jss193
        wrote on last edited by
        #3

        @mrjj said in QLabel Addition to layout:

        QScrollArea

        Thanks, I tried but do not know how to add new qlabels by pressing button
        ui->scrollArea->setWidgetResizable(true);
        ui->scrollArea->setWidget(label1);

        mrjjM 1 Reply Last reply
        0
        • J jss193

          @mrjj said in QLabel Addition to layout:

          QScrollArea

          Thanks, I tried but do not know how to add new qlabels by pressing button
          ui->scrollArea->setWidgetResizable(true);
          ui->scrollArea->setWidget(label1);

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @jss193
          Hi
          you apply layout to ScollArea and add the Labels to the layout.

          J 1 Reply Last reply
          2
          • mrjjM mrjj

            @jss193
            Hi
            you apply layout to ScollArea and add the Labels to the layout.

            J Offline
            J Offline
            jss193
            wrote on last edited by
            #5

            @mrjj how do I apply it, I have never seen it before...

            Thanks

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Hi,

              Did you saw the documentation of QScrollArea and its example ?

              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
              1

              • Login

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