Results 1 to 5 of 5

Thread: scaling a QPixmap, devides Pixmap in different parts

  1. #1
    Join Date
    Jul 2012
    Location
    Switzerland
    Posts
    32
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    7

    Default scaling a QPixmap, devides Pixmap in different parts

    Hello everyone,

    I've written a application which resizes a QPixmap (which is added in a QGraphicsPixmapItem which is added to a QGraphicsScene). When I grab a corner, the QPixmap resizes (with a QTransform object). My Problem is, that the scaling isn't doing what I want. It's deviding the picture in 4 parts (see image).
    Has someone an idea why this happens? Or is this a performance issue?

    thank you

    airglide


    pic.PNG

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Wiki edits
    17

    Default Re: scaling a QPixmap, devides Pixmap in different parts

    Has someone an idea why this happens? Or is this a performance issue?
    Sure, you are doing something odd in your code. I only we could see the code...

  3. #3
    Join Date
    Jul 2012
    Location
    Switzerland
    Posts
    32
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    7

    Default Re: scaling a QPixmap, devides Pixmap in different parts

    I've set some Dots to grab and set the derived QPixmap class as a parentitem, then I've installed a sceneEventFilter

    Qt Code:
    1. bool PixmapItem::sceneEventFilter(QGraphicsItem *watched, QEvent *event)
    2. {
    3. GrabDot *dot = dynamic_cast<GrabDot *> (watched);
    4. if(dot == NULL)
    5. return false;
    6.  
    7. int expandX = 0;
    8. int expandY = 0;
    9.  
    10. switch(event->type())
    11. {
    12.  
    13. case QEvent::GraphicsSceneMousePress:
    14. {
    15.  
    16. }break;
    17.  
    18. case QEvent::GraphicsSceneMouseRelease:
    19. {
    20.  
    21. }break;
    22.  
    23.  
    24. case QEvent::GraphicsSceneMouseMove:
    25. {
    26. QGraphicsSceneMouseEvent *e = dynamic_cast<QGraphicsSceneMouseEvent *>(event);
    27. switch(dot->getDotNumber())
    28. {
    29. case 0:
    30. {
    31. expandX = -1;
    32. expandY = -1;
    33. //this->setPos(this->cursor().pos());
    34. }break;
    35.  
    36. case 1:
    37. {
    38. expandX = 0;
    39. expandY = -1;
    40. }break;
    41.  
    42. case 2:
    43. {
    44. expandX = 1;
    45. expandY = -1;
    46. }break;
    47.  
    48. case 3:
    49. {
    50. expandX = 1;
    51. expandY = 0;
    52. }break;
    53.  
    54. case 4:
    55. {
    56. expandX = 1;
    57. expandY = 1;
    58. }break;
    59.  
    60. case 5:
    61. {
    62. expandX = 0;
    63. expandY = 1;
    64. }break;
    65.  
    66. case 6:
    67. {
    68. expandX = -1;
    69. expandY = 1;
    70. }break;
    71.  
    72. case 7:
    73. {
    74. expandX = -1;
    75. expandY = 0;
    76. }break;
    77. }
    78.  
    79. int width = 0;
    80. int height = 0;
    81.  
    82. //if side is dragged, save the new Bounding rect
    83. bool sideDragged = false;
    84.  
    85. switch(dot->getDotNumber())
    86. {
    87. case 0:
    88. case 2:
    89. case 4:
    90. case 6:
    91. {
    92. //if a corner is grabbed, the proportion has to stay the same
    93. //only the change of the x value is interesting
    94. width = boundingRect().width() + (expandX * e->pos().x());
    95. height = width * propRect.height()/propRect.width();
    96. sideDragged = false;
    97. }break;
    98.  
    99. default:
    100. width = boundingRect().width() +(expandX * e->pos().x());
    101. height = boundingRect().height() +(expandY * e->pos().y());
    102. sideDragged = true;
    103. break;
    104.  
    105. }
    106.  
    107. QTransform trans = QTransform();
    108. trans.scale(width/boundingRect().width(), height/boundingRect().height());
    109. prepareGeometryChange();
    110. setPixmap(pixmap().transformed(trans));
    111.  
    112. if(sideDragged)
    113. {
    114. saveBoundingRect();
    115. }
    116. switch(dot->getDotNumber())
    117. {
    118.  
    119. case 0:
    120. {
    121. setPos(pos().x() + e->pos().x(), pos().y() + e->pos().y());
    122. }break;
    123.  
    124. case 1:
    125. {
    126. setPos(pos().x(), pos().y() + e->pos().y());
    127. }break;
    128.  
    129. case 2:
    130. {
    131. setPos(pos().x(), pos().y() + e->pos().y());
    132. }break;
    133.  
    134. case 6:
    135. {
    136. setPos(pos().x() + e->pos().x(), pos().y());
    137. }break;
    138.  
    139. case 7:
    140. {
    141. setPos(this->pos().x() + e->pos().x(), this->pos().y());
    142. }break;
    143. }
    144.  
    145. setGrabDotPos();
    146. }break;
    147.  
    148. default:
    149. {
    150. return false;
    151. }break;
    152.  
    153. }
    To copy to clipboard, switch view to plain text mode 

    thank you for your help

  4. #4
    Join Date
    Feb 2010
    Posts
    96
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    4
    Thanked 5 Times in 5 Posts

    Default Re: scaling a QPixmap, devides Pixmap in different parts

    Why not save the original pixmap as an object ( in PyQt: self.originalPixmap = self.pixmap() ) and then when you scale the image set the scale from the original pixmap ( in PyQt: self.setPixmap(self.originalPixmap.scaled(width/boundingRect().width(), height/boundingRect().height()) )?

  5. The following user says thank you to prof.ebral for this useful post:

    airglide (26th November 2012)

  6. #5
    Join Date
    Jul 2012
    Location
    Switzerland
    Posts
    32
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    7

    Default Re: scaling a QPixmap, devides Pixmap in different parts

    I wanted to implement that later, but now it works. I've added to my Pixmap class a QPixmap object called originalPixmap. I scale this image and display it.

    great
    thank you

Similar Threads

  1. Image/Pixmap after scaling parcelled into 4 pieces.
    By Douglish in forum Qt Programming
    Replies: 2
    Last Post: 19th February 2011, 10:28
  2. Pixmap scaling problem
    By tommy in forum Qt Programming
    Replies: 1
    Last Post: 14th May 2009, 18:00
  3. Replies: 8
    Last Post: 12th March 2009, 15:12
  4. finding maximum scaling of a pixmap
    By babu198649 in forum Newbie
    Replies: 1
    Last Post: 31st March 2008, 15:32
  5. Pixmap scaling
    By yellowmat in forum Newbie
    Replies: 3
    Last Post: 4th January 2007, 17:01

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.