Unsolved how to add separate pushbutton for each item in listWidget ?
-
Hi ,
I want to show multiple item in in QT UI and each item has push button.
How to show this ?QT UI
item 1 PushButton1
item 2 PushButton2
item 3 PushButton3
item 4 PushButton4I know from listWidget i can shows the iteam but how to add push button inside it ?
how to add separate pushbutton for each item in listWidget ? -
What is
listWidget
which you refer to? There is no such (built-in) QML component.There are so many ways to do what you ask that I don't know how to answer. Are the items dynamic? Are they loaded from a model? Or is this a static (known in advance) part of the UI?
A very simple answer (but as said - I'm only guessing what you want to achieve...):
ListView { model: 4 delegate: Rectangle { border.width: 1 border.color: "#000000" width: 100 height: 30 Text { text: qsTr("Item %1").arg(index) } PushButton { text: qsTr("PushButton %1").arg(index) onClicked: console.log("Button clicked", index) } } }
-
this is the Qlistwidget item in QT, not in QML
https://doc.qt.io/archives/qt-4.8/qlistwidgetitem.htmlyes this item are dynamic,
this is the sample code but here i want clicked button in place of checkbox.for (int i = 0; i < 14; ++i) { QListWidgetItem *item = new QListWidgetItem; item->setText("app " + QString::number(i) + " version " + QString::number(i)); item->setSelected(false); item->setCheckState(Qt::Unchecked); ui->listWidget->addItem(item); }
-
@TM9412 said in how to add separate pushbutton for each item in listWidget ?:
this is the Qlistwidget item in QT, not in QML
Than, you were in the wrong sub forum, therefore I moved it from QML/Quick to General.
-
@TM9412 said in how to add separate pushbutton for each item in listWidget ?:
this is the Qlistwidget item in QT, not in QML
https://doc.qt.io/archives/qt-4.8/qlistwidgetitem.htmlyes this item are dynamic,
this is the sample code but here i want clicked button in place of checkbox.for (int i = 0; i < 14; ++i) { QListWidgetItem *item = new QListWidgetItem; item->setText("app " + QString::number(i) + " version " + QString::number(i)); item->setSelected(false); item->setCheckState(Qt::Unchecked); ui->listWidget->addItem(item); }
You can switch to QListView and use your own styled delegate: https://doc.qt.io/qt-5/qstyleditemdelegate.html. And example how to do it (with QSpinBox) is here: https://doc.qt.io/qt-5/model-view-programming.html#delegate-classes