Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QTableWidget not highlighted using QLabel to display image
Qt 6.12 LTS is out! See what's new in the release blog

QTableWidget not highlighted using QLabel to display image

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 1.6k 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.
  • H Offline
    H Offline
    haris123
    wrote on last edited by
    #1

    I need to display images in Qtable widget, I have using QLabel for it, below is my code.

        QString imgPath ="image.jpg";
        QPixmap pix(imgPath);
        if(!pix.isNull()){
            QPixmap pixmap = pix.scaled(cellWidth-20,cellHeight-20,Qt::KeepAspectRatio, Qt::SmoothTransformation);
            QLabel *lblTest = new QLabel;
            lblTest->setPixmap(pixmap);
            lblTest->setAlignment(Qt::AlignCenter);
            ui->tableWidget->setCellWidget(row,col,lblTest);
    
        }
    

    My problem is the cell with images is not highlighted when I click on it. Where as empty cell get highlighted when I click on it.

    What can be the issue, any help will be appreciated.

    Thanks
    Haris

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      That's normal, the widget comes over your cell. If you want to retain the functionality of the cell, you should create your own QStyledItemDelegate to show the image.

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

      1 Reply Last reply
      0
      • H Offline
        H Offline
        haris123
        wrote on last edited by haris123
        #3

        Hi Thanks for the response, do you have any reference which will be help me to implement using QStyledItemDelegate. Basically what I need is display images in table view, I have QStringList with image path, and if possible with highlighting I need to get the image path upon clicking a cell. Do you have any idea?

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Look for the "Star Delegate" example

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

          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
          • Unsolved