Qt Forum

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

    Get image from QTableWidgetItem

    General and Desktop
    2
    7
    1708
    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
      sashapont last edited by

      I set table widget item
      QTableWidgetItem *thumbnail = new QTableWidgetItem;
      //
      thumbnail->setData(Qt::DecorationRole, ( QPixmap( url.path() ) ).scaled(144, 168));
      ui->tableWidget->setItem(row, 1, thumbnail);

      How I can get image from this cell?

      1 Reply Last reply Reply Quote 0
      • hskoglund
        hskoglund last edited by hskoglund

        Hi, you mean the image is not visible? Maybe try instead:

        QTableWidgetItem *thumbnail = new QTableWidgetItem( QIcon( QPixmap( url.path() ) .scaled(144, 168)),"");
        //
        ui->tableWidget->setItem(row, 1, thumbnail);
        1 Reply Last reply Reply Quote 1
        • S
          sashapont last edited by

          No it is visible and i want to get it and save to file

          1 Reply Last reply Reply Quote 0
          • hskoglund
            hskoglund last edited by

            Ok I see, guessing but it should be something like:
            QPixmap m = ui->tablewidget->item(row,1)->data(Qt::DecorationRole);

            1 Reply Last reply Reply Quote 1
            • S
              sashapont last edited by

              @hskoglund said:

              QPixmap m = ui->tablewidget->item(row,1)->data(Qt::DecorationRole);

              no viable conversion from 'QVariant' to 'QPixmap'

              1 Reply Last reply Reply Quote 0
              • hskoglund
                hskoglund last edited by

                Sorry :-) try this:

                QPixmap m = ui->tablewidget->item(row,1)->data(Qt::DecorationRole).value<QPixmap>();
                1 Reply Last reply Reply Quote 1
                • S
                  sashapont last edited by

                  Thank you very much!!!! It is work!

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post