0

I have created model by using QListView and QAbstractListModel. Into that model i want to add, for example, 10 buttons and 10 checkboxes, and then display it using QListView.

How can i do it?

Velklish
  • 1
  • 1
  • Qt's model/view framework is not very well suited for what you want to do, it might be simpler for you to use standard widgets instead. If you absolutely want to go forward with model/view nevertheless, check this answer - https://stackoverflow.com/a/11778012/1217285. It gives a good overview of how you can go about what you want to do. – Dmitry Jun 25 '19 at 07:17

1 Answers1

0

You don't need a model to achieve this, you can use a QListWidget and add the widgets like this:

for (int i = 0; i < 10; ++i)
{
    ui->listWidget->setItemWidget(new QListWidgetItem(ui->listWidget), 
            new QPushButton("Button " + QString::number(i + 1), ui->listWidget));
    ui->listWidget->setItemWidget(new QListWidgetItem(ui->listWidget), 
            new QCheckBox("Checkbox " + QString::number(i + 1), ui->listWidget));
}

The result on KDE Desktop looks like this, if the QListWidget is in a Gridlayout:

enter image description here

Rick Pat
  • 789
  • 5
  • 14