Qt World Summit: Register Today!

QTableWidget not highlighted using QLabel to display image

  • 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);
            QPixmap pixmap = pix.scaled(cellWidth-20,cellHeight-20,Qt::KeepAspectRatio, Qt::SmoothTransformation);
            QLabel *lblTest = new QLabel;

    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.


  • Lifetime Qt Champion


    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.

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

  • Lifetime Qt Champion

    Look for the "Star Delegate" example

Log in to reply