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] QGraphicsItem always visible in QGpraphicScene
Qt 6.11 is out! See what's new in the release blog

[SOLVED] QGraphicsItem always visible in QGpraphicScene

Scheduled Pinned Locked Moved General and Desktop
qgraphicssceneqgraphicsitem
2 Posts 1 Posters 2.2k 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.
  • T Offline
    T Offline
    tmoranduzzo
    wrote on last edited by tmoranduzzo
    #1

    Hi everyone,

    I spent two day trying to figure out how to solve my problem but I'm not able to find a solution. I'm sure it is a matter of setting the right property but I do not which I have to modify. I created a simple code to show an image in a QGraphicScene and every time an event happens the image is modified and showed in the scene. At the same time I need to create a Line item and show it in the center of the scene. I did it in this way:

    void inspection::on_horizontalSlider_actionTriggered(int action)
    {
    
    int value2 = ui->horizontalSlider->value();
     //here I create the transfer_image
     ui->graphicsView->setScene(scene);
    QGraphicsPixmapItem* item_pop = new      
    QGraphicsPixmapItem(QPixmap::fromImage(transfer_image));
    scene->addItem(item_pop);
    ui->graphicsView->show();
    if (pass ==false)
    {
    // if it is the first time I create the line
          item = new MyItem();
          item->setVisible(true);
          scene->addItem(item);
    }
     pass = true;
    }
    

    My problem is that the first time I enter the function I can see the object but then every time I update the scene I cannot see the line anymore. How can I keep it always on the top of the scene?

    thank you

    T 1 Reply Last reply
    0
    • T tmoranduzzo

      Hi everyone,

      I spent two day trying to figure out how to solve my problem but I'm not able to find a solution. I'm sure it is a matter of setting the right property but I do not which I have to modify. I created a simple code to show an image in a QGraphicScene and every time an event happens the image is modified and showed in the scene. At the same time I need to create a Line item and show it in the center of the scene. I did it in this way:

      void inspection::on_horizontalSlider_actionTriggered(int action)
      {
      
      int value2 = ui->horizontalSlider->value();
       //here I create the transfer_image
       ui->graphicsView->setScene(scene);
      QGraphicsPixmapItem* item_pop = new      
      QGraphicsPixmapItem(QPixmap::fromImage(transfer_image));
      scene->addItem(item_pop);
      ui->graphicsView->show();
      if (pass ==false)
      {
      // if it is the first time I create the line
            item = new MyItem();
            item->setVisible(true);
            scene->addItem(item);
      }
       pass = true;
      }
      

      My problem is that the first time I enter the function I can see the object but then every time I update the scene I cannot see the line anymore. How can I keep it always on the top of the scene?

      thank you

      T Offline
      T Offline
      tmoranduzzo
      wrote on last edited by
      #2

      @tmoranduzzo

      I added

      item_pop->setPixmap(QPixmap::fromImage(transfer_image));
      

      to update the view and that solved my problem

      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