Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to add image to row in TableView
Forum Updated to NodeBB v4.3 + New Features

How to add image to row in TableView

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 1.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sharon_obl82
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      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.

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved