[solved]Displaying current QListWidgetItem in QGraphicsView on the same Widget

  • Hi,
    I want to display the populated qlistwidget item (image files), in the qgraphicsview which is also in the same widget. I would like to enable it by clicking the current item in QListWidget. I tried drag and drop but, i couldn't find a correct way of doing it. So i felt displaying image by clicking the item might be easier. But i have little idea how to implement it. It would be great if you could suggest me some way to implement the above mentioned.

    @ void Widget::on_listWidget_itemClicked(QListWidgetItem *item)
    } @

  • Lifetime Qt Champion


    Get the image path

    Create a pixmap from the file

    Create a QGraphicsPixmapItem

    Set the pixmap on the item

    Add the item to the scene

    Set the item coordinates to something sensible

    Hope it helps

  • Hi,

    Can you please suggest me some example for the implementation. I have no idea how to implement it. It would be fine if i could get an idea how to implement drag and drop between the qlistwidget and qgraphicsview. Awaiting your valuable response...

  • Lifetime Qt Champion

    It all depends on how you use your QListWidget, where do you keep the image path etc...

  • Hi,

    I have used my QListWidget to populate datas through QDialog as followed

    void Widget::on_pushButton_clicked()

     QString fileName;
     QStringList fileNames;
     QFileDialog dialog(this);
      if (dialog.exec())
         fileNames = dialog.selectedFiles();
      foreach (fileName, fileNames)
          QListWidgetItem *item = new QListWidgetItem(ui->listWidget);
         QFileInfo fi(fileName);
         QString name = fi.fileName();
         QIcon icon = iconSource.icon(fi);



    Now i want to establish drag and drop between the QListWidget and QGraphicsView designed through QDesigner in same widget. I am not sure how to convert the Url which is stored in qlistwidget into qpixmap... It would be great to have your suggestion regarding how to implement this..

    Thanks and regards
    Venkatesh Padmanabhan

  • Lifetime Qt Champion

    I answered to a similar question "there":http://qt-project.org/forums/viewthread/31764/

  • Hi,
    I tried to implement as per your suggestion but the image is not getting displayed


    void Widget::on_listwidget_itemClicked(QListWidgetItem *item)
    QFileInfo info(item->text());
    QString str= info.absoluteFilePath();
    QPixmap pix(str);
    QGraphicsScene *scn= new QGraphicsScene(ui->graphicsView_2);

    I think there is some problem in my method of getting the file path. But if i change the


    It displays the full path of the image in the scene. But i don't know why the pix doesn't create the pixmap from the string.

    This problem is really creating me so much of trouble :(

  • Lifetime Qt Champion

    The answer I gave you on your other thread can also apply here

Log in to reply

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