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);
        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


  • Lifetime Qt Champion

    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.



  • 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
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.