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. Deactivate mouse press event
Forum Updated to NodeBB v4.3 + New Features

Deactivate mouse press event

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.8k 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.
  • J Offline
    J Offline
    jk_mk
    wrote on last edited by
    #1

    Hello,

    I have to functions in my code, they look like this:

    @void MainWindow::x_slice_extract()
    {
    .......code....
    }@

    @void MainWindow::mousejustpressed(int x,int y)
    {
    ......code...
    }@

    The first function (x_slice_extract()) is used to display an image1 in a QGraphicsScene. The second function (mousejustpressed(int x, int y)) is a press mouse event in which every time I press the mouse I call this function and I create an other image2, which I want to display it in the same QGraphicsScene. When I first display my image1 in the QGraphicsScene and when I press the mouse I get the image2 in my QGraphicsScene. But, after pressing the button, and running again the function x_slice_extract(), I should get again image1, but still I have image2 in the QGraphicsScene. Could somebody help me with this problem? When I activate a mouse event, how I could deactivate it?

    1 Reply Last reply
    0
    • J Offline
      J Offline
      jk_mk
      wrote on last edited by
      #2

      While I am doing debuging, I have noticed that when my QGraphicsScene has already image1, when I press the button and insert in the mouse press event function, then the compiler can't get that has already a pixmapItem, but understands that QGraphicsScene is empty. I think this is the mistake. Could somebody help me to solve it?

      @void MainWindow::x_slice_extract()
      {
      .......code....

      static QGraphicsPixmapItem* pixmapItem;

      if (!pixmapItem) {

      QPixmap tmpmap (QPixmap("y.png"));
          pixmapItem = scene_y->addPixmap ( tmpmap.scaled (size_x,size_y) );
      
              ui->graphicsView_y->setScene(scene_y);
          } else {
      

      QPixmap tmpmap (QPixmap("y.png"));
      pixmapItem->setPixmap(tmpmap.scaled ( size_x,size_y));
      }
      }@

      @void MainWindow::mousejustpressed(int x,int y)
      {
      .......code....

      static QGraphicsPixmapItem* pixmapItem;

      if (!pixmapItem) {

      QPixmap tmpmap (QPixmap("y.png"));
          pixmapItem = scene_y->addPixmap ( tmpmap.scaled (size_x,size_y) );
      
              ui->graphicsView_y->setScene(scene_y);
          } else {
      

      QPixmap tmpmap (QPixmap("y.png"));
      pixmapItem->setPixmap(tmpmap.scaled ( size_x,size_y));
      }
      }@

      1 Reply Last reply
      0
      • S Offline
        S Offline
        srikanth_trulyit
        wrote on last edited by
        #3

        If you need only one pixmap to be shown at any point of time( if I understood your problem correctly), then why don't you maintain a QGraphicsPixmapItem say currentPixmapItem which is the ONLY pixmap item added to the scene. In the corresponding methods, just set the pixmap of the currenPixmapItem, so that it changes accordingly.

        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