Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

I want to take list widget dynamically and take multiple push button inside listwidget dynamically



  • I am taking the list widget dynamically as

     QListWidget *widgetOnTheTop = new QListWidgetWidget(this);
          widgetOnTheTop->setGeometry(100,30,100,105);
          widgetOnTheTop->show();
    

    But i am not able to take button inside the list widget . I will try to use this code

     QVBoxLayout *layout=new QVBoxLayout();
          for (int i = 0; i < 4; ++i){
              for(int j=0;j<4;j++){
                QPushButton *button = new QPushButton();
                button->setText(QString::number(i));
                layout->addWidget(button);
                button->show();
              }
          }
        widgetOnTheTop->setLayout(layout);
    

    But nothing will happen.
    Also I want to know is it possible to add button inside the listwidget dynamically.

    Any help is considerable.
    Thank you in advance



  • @amarism
    You are trying to use setLayout on a whole QListWidget. I imagine that is not the usage. You should be creating QListWidgetItems and then QListWidget::insertItem() to populate it with items.

    That's what a QListWidget is for. It's a combo/list box of items. It wouldn't surprise me if you cannot put buttons in items, I don't know. I don't understand just what you are trying to achieve. It might help if you explained what you are expecting to achieve/it to look like.



  • @JonB I have a comboBox and onclick of combo Box i want to create a dynamic widget were they have multiple buttons.
    This whole work is using for showing the slipt screen of QOpenGLWidget like (1x1,1x2,2x1,4x5..... so on). I am taken the same example from RADint viewer. I am also attaching the image view of what i want to do in my project.

    0_1539237389218_splitsScreen.png

    I want to achieve this type of combo Box .Highlighting the row and column will display the respective screen. as example this image we take highlight 3*4 view my OpenGLWidget is distribute respectively. like

    0_1539237591604_test.png


Log in to reply