QLabel Addition to layout

  • 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()
        QSpacerItem *item = new QSpacerItem(1,1,QSizePolicy::Expanding,QSizePolicy::Fixed);
        for(int i =0;i<1;i++){
            QLabel *label1 = new QLabel("NOTE");

    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?


  • Lifetime Qt Champion

    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.

  • @mrjj said in QLabel Addition to layout:


    Thanks, I tried but do not know how to add new qlabels by pressing button

  • Lifetime Qt Champion

    you apply layout to ScollArea and add the Labels to the layout.

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


  • Lifetime Qt Champion


    Did you saw the documentation of QScrollArea and its example ?

Log in to reply