Custom QListView
-
Hi,
I would like to implement "this kind of interface":https://www.dropbox.com/s/rxy29mysyft2dfb/customListView.png:
Each item in the list view would have 3 QString and 1 button that would emit a different signal (based on his device id)I am looking for the easiest and most robust way to do this in QT.
I was thinking of a QListView instead of a QTableView because the information is better presented in a QListView. Is this kind of setup possible ? Is there some example that resemble this one? I haven't found much online. I have experience in QTableView but not much in QListView. I don't even know how to show 3 strings next to each other like on the picture using a QStandardItemModel itemThank you!
code so far :
@ model_hr = new QStandardItemModel(this);
ui->listView_hr->setModel(model_hr);
QStandardItem *item;
item = new QStandardItem();
item->setData( "Device", Qt::DisplayRole );
item->setEditable( false );
model_hr->appendRow( item );@ -
Hi,
You should have a look at the QStyledItemDelegate to start. There is e.g. the star delegate example in the documentation that shows how to make a completely custom delegate.
Hope it helps
-
Hi SGaist thanks for your message,
I understand the example but not sure it would be possible to have a button on each row with a different signal attached to it, I would have to have a slot that receive maybe int that represent the row in the model?
@SLOT(clicked(int)) @
so I know which one was clicked, or make the button name different when I add them to the grid but after in the slot i'm not sure I can retrieve the button namei.e:
@connect(button_row1, SIGNAL(clicked(), this, SLOT(clicked())
connect(button_row2, SIGNAL(clicked(), this, SLOT(clicked())void clicked() {
if (event comes from row1)
qDebug() << "row1"
else if (event comes from row2)
qDebug() << "row2"
...
}@Merci
-
You could use QSignalMapper