Results 1 to 3 of 3

Thread: Image issue

  1. #1
    Join Date
    Feb 2006
    Posts
    42
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Arrow Image issue

    Hi all,

    How to scale an image to a label's size and display it on the label. I tried to
    do this, but even though I have scaled the pixel values of image to label size,
    it is displayed partially on the label. Here is the code I have written

    QLabel *mylabel = new MyLabel(mywid,"myfirstlabel");
    mylabel->setGeometry(0,6,100,100);

    QPixmap mypix;
    mypix.load ("query.png");

    mypix.scaledToWidth(100,Qt::FastTransformation);
    mypix.scaledToHeight(100,Qt::FastTransformation);

    mylabel->setPixmap(mypix);
    mylabel->setFrameStyle(QFrame::Panel | QFrame::Sunken);

    Can some body explain how to do it?

    Thanks in Advance,
    Seema

  2. #2
    Join Date
    Feb 2006
    Location
    Kirovohrad, Ukraine
    Posts
    72
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Image issue

    Let me guess: are you trying to scale the pixmap so that it is as high as the standart label?
    Try this:
    Qt Code:
    1. // Create an empty label
    2. QLabel *mylabel = new QLabel;
    3. //Load the pixmap
    4. QPixmap mypix("query.png");
    5. //Create the instance of the default application font
    6. QFont font;
    7. //Create font metrics of the font
    8. QFontMetrics metrics(font);
    9. //Scale the pixmap to the height of the font
    10. mypix = mypix.scaledToHeight(metrics.height());
    11. //Set the result to the label
    12. mylabel->setPixmap(mypix);
    To copy to clipboard, switch view to plain text mode 

    P.S.: Please, next time use the [code] and [/code] tags to make your QT code readable.

  3. #3
    Join Date
    Feb 2006
    Posts
    4
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Image issue

    If you want the qlabel to automatically scale the pixmap for you so that it takes up all the space, all the time, then check this out:

    Qt4: http://doc.trolltech.com/4.1/qlabel....dContents-prop

    Qt3: http://doc.trolltech.com/3.3/qlabel....ScaledContents

Similar Threads

  1. can Qlabel display a series of image one by one ?
    By jirach_gag in forum Qt Tools
    Replies: 3
    Last Post: 11th August 2008, 15:36
  2. Finding marks on scanned image for alignment
    By caduel in forum Qt Programming
    Replies: 1
    Last Post: 23rd September 2007, 02:10
  3. Help needed handling image data
    By toratora in forum General Programming
    Replies: 2
    Last Post: 11th May 2007, 09:24
  4. Qt image support Issue in Installation?
    By vishal.chauhan in forum Installation and Deployment
    Replies: 2
    Last Post: 26th April 2007, 07:50
  5. How and when to repaint a widget ?
    By yellowmat in forum Newbie
    Replies: 7
    Last Post: 3rd April 2006, 16:36

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.