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] QGraphicsPixmapItem resize using mouse
Forum Updated to NodeBB v4.3 + New Features

[solved] QGraphicsPixmapItem resize using mouse

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 582 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.
  • S Offline
    S Offline
    Sridharan
    wrote on last edited by Sridharan
    #1

    virtual void operator()(QGraphicsItem* item, const QRectF& rect)
    {
    QGraphicsPixmapItem* imageItem = dynamic_cast<QGraphicsPixmapItem*>(item);
    QGraphicsRectItem* rectItem = dynamic_cast<QGraphicsRectItem*>(item);

    if (imageItem)
    {
    	QString fileName = "D:/Qt samples/build-QtGraphics-Desktop_Qt_6_3_2_MinGW_64_bit-Debug/google.PNG";
    	QImage myImage(fileName);
    	QPixmap myPixMap(100, 50);
    	myPixMap = QPixmap::fromImage(myImage);
    	myPixMap = myPixMap.scaled(QSize(rect.width(), rect.height()), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
    	imageItem->setPixmap(myPixMap);
    	
    	// imageItem->setPos(rect.x(), rect.y());     If i add this line, resize behaviour is unpredictable for operations in which top-left coordinate changes
    }
        else if (rectItem)
        {
              // Incaseof QGraphicsRectItem, I can set the bounding box and it works fine.
              rectItem->setRect(rect);     
        }
    

    }

    I need to resize QGraphicsPixmapItem using resize handler. It works fine for drag operations in which top-left coordinates of 'QGraphicsPixmapItem'
    is not changed (Drag using right side resize handler)

    It doesn't work correct if drag using top resize handler.

    In the above function, 2nd parameter receives the new bounding box size

    Original image

    Original image.PNG

    Resize using right handle

    Resize using right handler.PNG

    Resize using top handler

    Resize using top handler.PNG

    S 1 Reply Last reply
    0
    • S Sridharan

      virtual void operator()(QGraphicsItem* item, const QRectF& rect)
      {
      QGraphicsPixmapItem* imageItem = dynamic_cast<QGraphicsPixmapItem*>(item);
      QGraphicsRectItem* rectItem = dynamic_cast<QGraphicsRectItem*>(item);

      if (imageItem)
      {
      	QString fileName = "D:/Qt samples/build-QtGraphics-Desktop_Qt_6_3_2_MinGW_64_bit-Debug/google.PNG";
      	QImage myImage(fileName);
      	QPixmap myPixMap(100, 50);
      	myPixMap = QPixmap::fromImage(myImage);
      	myPixMap = myPixMap.scaled(QSize(rect.width(), rect.height()), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
      	imageItem->setPixmap(myPixMap);
      	
      	// imageItem->setPos(rect.x(), rect.y());     If i add this line, resize behaviour is unpredictable for operations in which top-left coordinate changes
      }
          else if (rectItem)
          {
                // Incaseof QGraphicsRectItem, I can set the bounding box and it works fine.
                rectItem->setRect(rect);     
          }
      

      }

      I need to resize QGraphicsPixmapItem using resize handler. It works fine for drag operations in which top-left coordinates of 'QGraphicsPixmapItem'
      is not changed (Drag using right side resize handler)

      It doesn't work correct if drag using top resize handler.

      In the above function, 2nd parameter receives the new bounding box size

      Original image

      Original image.PNG

      Resize using right handle

      Resize using right handler.PNG

      Resize using top handler

      Resize using top handler.PNG

      S Offline
      S Offline
      Sridharan
      wrote on last edited by
      #2

      It gets solved by adding offset.

      QGraphicsPixmapItem* imageItem = dynamic_cast<QGraphicsPixmapItem*>(item);

                  if (imageItem)
                  {
                      QPixmap myPixMap = sourceImage.scaled(QSize(rect.width(), rect.height()), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
                      imageItem->setOffset(rect.x(), rect.y());
                      imageItem->setPixmap(myPixMap);
                 }
      
      1 Reply Last reply
      0
      • P Offline
        P Offline
        Proton Phoenix
        wrote on last edited by Proton Phoenix
        #3

        @Sridharan said in [solved] QGraphicsPixmapItem resize using mouse:

        It gets solved by adding offset.
        QGraphicsPixmapItem* imageItem = dynamic_cast<QGraphicsPixmapItem*>(item);
        if (imageItem)
        {
        QPixmap myPixMap = sourceImage.scaled(QSize(rect.width(), rect.height()), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
        imageItem->setOffset(rect.x(), rect.y());
        imageItem->setPixmap(myPixMap);
        }

        can you share the full code bro i have been searching for it for couple of days

        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