I want to take list widget dynamically and take multiple push button inside listwidget dynamically
-
wrote on 10 Oct 2018, 09:48 last edited by amarism 10 Oct 2018, 09:58
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 -
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 advancewrote on 10 Oct 2018, 17:25 last edited by JonB 10 Oct 2018, 17:26@amarism
You are trying to usesetLayout
on a wholeQListWidget
. I imagine that is not the usage. You should be creatingQListWidgetItem
s and thenQListWidget::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. -
@amarism
You are trying to usesetLayout
on a wholeQListWidget
. I imagine that is not the usage. You should be creatingQListWidgetItem
s and thenQListWidget::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.wrote on 11 Oct 2018, 06:00 last edited by@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.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
1/3