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. Enter different images

Enter different images

Scheduled Pinned Locked Moved Unsolved General and Desktop
imageimage displayqgraphicsentrylist
8 Posts 3 Posters 1.1k Views
  • 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.
  • O Offline
    O Offline
    Omar Medhat
    wrote on last edited by Omar Medhat
    #1

    In my program i should put a different image for every entry i create
    here is the code of create entry :
    void MainWindow::creatEntry()
    {
    auto entry = m_controller -> creatEntry();
    if (entry){
    ui->listWidget->addItem(entry->name());
    auto listItem =ui->listWidget->item(ui->listWidget->count()-1); //mohem min1:33
    m_entryMap.insert(listItem,entry);
    }
    }

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

      Hi and welcome to devnet,

      What image are you talking about ?
      Where are they coming from ?

      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
      2
      • O Offline
        O Offline
        Omar Medhat
        wrote on last edited by
        #3

        This is the image open and display function :
        void MainWindow::on_openImage_clicked()
        {

         QString imagePath = QFileDialog::getOpenFileName(
              this,
              tr("Open File"),
              "",
              tr("JPEG (*.jpg *.jpeg);;PNG (*.png)")
              );
        imageObject = new QImage();
        imageObject->load(imagePath);
        
        image = QPixmap::fromImage(*imageObject);
        scene = new QGraphicsScene(this);
        scene->addPixmap(image);
        scene->setSceneRect(image.rect());
        ui->graphicsView->setScene(scene);
        

        }

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

          Don't create new scene for each image you want to add. What you are currently doing is replacing the scene each time.

          Create the scene once in the class constructor. In your function, just add your new images to it.

          On a side note, don't allocate your QImage on the heap. There's no need for that in the usual cases.
          On another note, there's no need for that QImage, you can create a QPixmap from a file path.

          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
          3
          • O Offline
            O Offline
            Omar Medhat
            wrote on last edited by
            #5

            still having the same image for all entries

            i want to load different image for each entry

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

              Then explain exactly how you create these entries and how you are associating an entry to an image.

              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
              • O Offline
                O Offline
                Omar Medhat
                wrote on last edited by
                #7

                i have menubar that have add entry with function above 1

                jsulmJ 1 Reply Last reply
                0
                • O Omar Medhat

                  i have menubar that have add entry with function above 1

                  jsulmJ Online
                  jsulmJ Online
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @Omar-Medhat Show your current void MainWindow::on_openImage_clicked() implementation. The previous one was wrong as @SGaist pointed out...

                  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