How to get QPixmap from QItemSelection?



  • Hello.

    How can I get QPixmap from QItemSelection?

    I am trying to make an image viewer. Currently, I have successfully loaded images to QstandarditemModel as below.
    Now, I would like to show an enlarged image which is selected by mouse clicked. To do so, I think, first, I should get QPixmap from QItemSelection in order to show into QLabel Box.

    Please help.

    Thank you.

    @
    this->model = new QStandardItemModel();
    ui->listView->setModel(this->model);
    ui->listView->setGridSize(QSize(320, 240));
    ui->listView->setIconSize(QSize(280, 200));
    ui->listView->setViewMode(QListView::IconMode);
    QObject::connect(ui->listView->selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)), this, SLOT(imageSelectionChanged(QItemSelection)));

    //---------Load Button Event ------------
    QFileDialog::Options options;
    options |= QFileDialog::DontUseNativeDialog;

    QString selectedFilter;
    QStringList fileNames = QFileDialog::getOpenFileNames(this, tr("QFileDialog::getOpenFileNames()"), "./../data", tr("All Files ();;Image Files (.bmp)"), &selectedFilter, options);
    for (int i = 0; i < fileNames.count(); i++) {
    QStandardItem *item = new QStandardItem(QIcon(fileNames[i]), fileNames[i]);
    this->model->appendRow(item);
    }
    @

    [edit: added missing coding tags @ SGaist]


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    You should rather load it from the same file used to create the icon. Your QIcon will have a reduced version of the image while you rather want to have the original.


Log in to reply
 

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