Results 1 to 3 of 3

Thread: Display full scaled image on a QLabel

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2011
    Posts
    22
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Display full scaled image on a QLabel

    I have an Image I am trying to display in a label.

    I am using some code like the following:

    Qt Code:
    1. transformPixels(0,0,1,imheight,imwidth,1);//sets unsigned char** imageData
    2.  
    3. unsigned char* fullCharArray = new unsigned char[imheight * imwidth];
    4. for (int i = 0 ; i < imheight ; i++)
    5. for (int j = 0 ; j < imwidth ; j++)
    6. fullCharArray[(i*imwidth)+j] = imageData[i][j];
    7.  
    8. QImage *qi = new QImage(fullCharArray, imwidth, imheight, QImage::Format_RGB32);
    9.  
    10. ui->viewLabel->setPixmap(QPixmap::fromImage(*qi,Qt::AutoColor));
    To copy to clipboard, switch view to plain text mode 

    The imageData array contains a single unsigned char per pixel. It is a grayscale image, not full RGB32, but that format seems to be the closest I have gotten so far. the problem is, my label is only showing a portion of the image, which is large (larger than the screen). How can I make my image scale, keeping the proper proportions, so that it fits in the label? I dont want it to be stretched ot skewed or anything - just the full image, small enough to fit in the label.

    Thanks
    Last edited by high_flyer; 18th January 2011 at 21:11. Reason: code tags

Similar Threads

  1. display image in qlabel
    By aj2903 in forum Qt Programming
    Replies: 3
    Last Post: 3rd July 2014, 11:09
  2. QLabel size, for image display
    By C167 in forum Qt Programming
    Replies: 13
    Last Post: 25th October 2013, 16:09
  3. Replies: 5
    Last Post: 11th June 2011, 15:29
  4. Replies: 7
    Last Post: 13th August 2008, 18:27
  5. 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

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.