How to add image to row in TableView



  • Hi,
    I'm sorry if this is a repeated question which had been posted up before but i can't seem to find any thread that could help answer my question.

    I have a table which I will display when the form is clicked but when a user clicks Add Row to add, a 'New" image will be added next to the row in the table, if user tries to delete the row, a "scissors" image will be displayed next to the row selected to be deleted.

    !http://i59.tinypic.com/2cpyoba.png()!
    !http://i57.tinypic.com/35bgrvn.png()!

    My tableview code is as simple as below:
    @
    multigrp = new QStandardItemModel(0,1,this);
    ui->tableView->setModel(multigrp);
    ui->tableView->setEditTriggers(QAbstractItemView::NoEditTriggers);
    multigrp->setHorizontalHeaderItem(0, new QStandardItem(QString(tr("Talkgroup Alias"))));
    ui->tableView->horizontalHeader()->resizeSection(0,180);
    ui->tableView->setSortingEnabled(true);
    @

    Does anyone know how to add an image next to the row as shown in the pictures?

    Thank you.



  • You are trying to display the image in the tableview. You need to implement custom delegate for displaying the image. Set the custom delegate for your first column. Just look at how to write a custom delegate. It should help you.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.