Results 1 to 3 of 3

Thread: Qt: How to set the size of Pixmap?

  1. #1
    Join Date
    May 2012
    Location
    Bangalore, India
    Posts
    271
    Thanks
    29
    Thanked 50 Times in 47 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Red face Qt: How to set the size of Pixmap?

    I want to set the size of pixmap. The code is defined below.
    Qt Code:
    1. QPixmap pix("alarm.png");
    2. painter->drawPixmap(pointf[i], pix);
    To copy to clipboard, switch view to plain text mode 

    It is showing a bigger image.
    How to set the size?

  2. #2
    Join Date
    May 2011
    Posts
    239
    Thanks
    4
    Thanked 35 Times in 35 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Symbian S60

    Default Re: Qt: How to set the size of Pixmap?

    You can either
    1) Scale the pixmap befor drawing it, or
    2) Use a version of drawPixmap that will do the scaling:

    void QPainter::drawPixmap ( const QRectF & target, const QPixmap & pixmap, const QRectF & source )

    Draws the rectangular portion source of the given pixmap into the given target in the paint device.

    Note: The pixmap is scaled to fit the rectangle, if both the pixmap and rectangle size disagree.

  3. The following user says thank you to mvuori for this useful post:

    sonulohani (4th June 2012)

  4. #3
    Join Date
    May 2012
    Location
    Bangalore, India
    Posts
    271
    Thanks
    29
    Thanked 50 Times in 47 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Qt: How to set the size of Pixmap?

    this one works, the one i am showing below--------->

    Qt Code:
    1. int x=points->x();
    2. int y=points->y();
    3. painter->drawpixmap(x,y,width,height,pixmap);//here replace the width and height with the pixmap width and height that you want to resize.
    To copy to clipboard, switch view to plain text mode 

    And then you will get the image with the size that you've configured.

Similar Threads

  1. Change the size of pixmap in a label
    By metRo_ in forum Qt Programming
    Replies: 16
    Last Post: 1st June 2012, 10:21
  2. Replies: 1
    Last Post: 19th April 2011, 11:17
  3. Replies: 0
    Last Post: 26th October 2010, 17:59
  4. Replies: 0
    Last Post: 7th January 2010, 22:03
  5. Drag pixmap on Windows size problem
    By plamkata in forum Qt Programming
    Replies: 1
    Last Post: 19th March 2009, 23: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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.