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. Add Qlabel as item in QTableview
Forum Updated to NodeBB v4.3 + New Features

Add Qlabel as item in QTableview

Scheduled Pinned Locked Moved Solved General and Desktop
qtableviewqstandarditemqlabelqtablewidget
3 Posts 2 Posters 3.9k Views 2 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
    sayan275
    wrote on 22 May 2019, 18:01 last edited by
    #1

    How to add a qlabel(with qpixmap in it) in QTableview as each cell item?
    so that the ouput looks like the image.
    0_1558546881299_bb01d902-250e-49dc-a58f-9e547fa5e7bb-image.png

    I tried with

    1. Qtablewidget and QTableitemwidget with seticon on item, but that makes the image as icon..ie a small one in the left with a available text space on the right.
    QTableWidget* signImageTable = new QTableWidget();
    QPixmap iconPixmap;
    iconPixmap.load("No_Passing.png");
    QTableWidgetItem* imageLabel = new QTableWidgetItem();
    imageLabel->setIcon(QIcon(iconPixmap));
    signImageTable->setItem(rowCounter, colCounter++, imageLabel);
    

    0_1558547548336_907a612d-2b52-41dd-9016-385ad44b12cc-image.png

    1. I tried with QTableView and setIcon on each item, which had the same output
    QTableView* m_pTableWidget = new QTableView(this);
    QStandardItem* item = new QStandardItem();
    item->setIcon(QIcon(pixmap));
    standardItemmodel->setItem(rowCounter, colCounter++, item);
    m_pTableWidget->setModel(model);
    

    So, maybe set icon makes it shrink. QLabel with setPixamp set on it and adding them as qstandardItem in the tableview's model will look as expected.

    I need the tableview as, the selected image name is required.

    Please suggest how to add qlabel as item in QTableView!

    Regards,
    Sayan

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 22 May 2019, 19:23 last edited by
      #2

      Hi,

      3rd option: implement a custom QStyledItemDelegate to draw the image the way you want it.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      S 1 Reply Last reply 23 May 2019, 02:36
      1
      • S SGaist
        22 May 2019, 19:23

        Hi,

        3rd option: implement a custom QStyledItemDelegate to draw the image the way you want it.

        S Offline
        S Offline
        sayan275
        wrote on 23 May 2019, 02:36 last edited by sayan275
        #3

        @SGaist said in Add Qlabel as item in QTableview:

        QStyledItemDelegate

        Ok..I'll try with that.
        from google search maybe this kind of output it will give, which maybe as our requirement.
        0_1558578799369_da2ccc76-385d-40ee-954a-79cbbe227dc3-image.png

        Else, I have some lengthy approach..implement custom label with mousepressevent handled which emits the object name and add these custom labels, 20 in HLayout and add hlayouts in a vlayout...

        Thanks!

        1 Reply Last reply
        0

        3/3

        23 May 2019, 02:36

        • Login

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