Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [solved]Displaying current QListWidgetItem in QGraphicsView on the same Widget
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved General and Desktop
8 Posts 2 Posters 3.6k Views 1 Watching
  • 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.
  • V Offline
    V Offline
    venkatesh
    wrote on last edited by
    #1

    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)
    {
    } @

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      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

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • V Offline
        V Offline
        venkatesh
        wrote on last edited by
        #3

        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...

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

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

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • V Offline
            V Offline
            venkatesh
            wrote on last edited by
            #5

            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);
              dialog.setFileMode(QFileDialog::ExistingFiles);
              if (dialog.exec())
                 fileNames = dialog.selectedFiles();
              foreach (fileName, fileNames)
             {
                  QListWidgetItem *item = new QListWidgetItem(ui->listWidget);
                  ui->listWidget->setViewMode(QListWidget::IconMode);
                 QFileInfo fi(fileName);
                 QString name = fi.fileName();
                 item->setText(name);
                 QIcon icon = iconSource.icon(fi);
                 item->setIcon(icon);
                 ui->listWidget->setIconSize(QSize(30,30));
                  }
              ui->listWidget->update();
            

            }

            @

            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

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

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

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • V Offline
                V Offline
                venkatesh
                wrote on last edited by
                #7

                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);
                scn->addPixmap(pix);
                ui->graphicsView_2->setScene(scn);
                ui->graphicsView_2->show();
                update();
                }
                @

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

                @
                scn->setText(str);
                @

                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 :(

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

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

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved