Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Call for Presentations - Qt World Summit

    Solved Add Qlabel as item in QTableview

    General and Desktop
    qtableview qstandarditem qlabel qtablewidget
    2
    3
    2646
    Loading More Posts
    • 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
      sayan275 last edited by

      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 Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        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 Reply Quote 1
        • S
          sayan275 @SGaist last edited by sayan275

          @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 Reply Quote 0
          • First post
            Last post