Results 1 to 2 of 2

Thread: set background image for frames and labels

  1. #1
    Join Date
    Feb 2012
    Location
    Armenia/Yerevan
    Posts
    400
    Thanks
    15
    Thanked 16 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default set background image for frames and labels

    as to drop some images inside a frame, with its background image loaded, you may use this:
    Qt Code:
    1. frame->setStyleSheet("background:black;background-position: center; background-image: url(:/truck/image.png);background-repeat: no-repeat; ");
    To copy to clipboard, switch view to plain text mode 

    Although widgets fall on top of the image, this way was not nice for me as frame does not have setPixmap(). So, in order to scale my image to fit the template, I used a QLabel instead. This was a nice way as you may see:
    Qt Code:
    1. QImage myImage;
    2. myImage.load(":/truck/image.png");
    3. QImage image = myImage.scaled(love->width(), love->height(), Qt::IgnoreAspectRatio );
    4. love->setPixmap(QPixmap::fromImage(image));
    To copy to clipboard, switch view to plain text mode 
    here, love is a QLabel . anyway, I found this way pretty disappointing as widgets now disappear and they do not fall on top of the QLabel background image!

    I both want to scale the image to fit the template as well as the widgets to fall on top of the image, do you have any idea how i can do that? and can you also explain why in the case of QLabel, widgets do not fall on top of the image.

  2. #2
    Join Date
    Feb 2012
    Location
    Armenia/Yerevan
    Posts
    400
    Thanks
    15
    Thanked 16 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: set background image for frames and labels

    well, I reply to my own post. We can apply HTML tags in a Label with setText() function:
    Qt Code:
    1. QLabel *label = new QLabel();
    2. label->setText("<img src='your_image_path'/><br>SomeText");
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Replies: 0
    Last Post: 25th October 2012, 08:50
  2. Replies: 3
    Last Post: 3rd August 2012, 10:35
  3. Replies: 0
    Last Post: 5th April 2011, 13:36
  4. Replies: 1
    Last Post: 25th June 2010, 18:31
  5. No Background Image on Example
    By igor in forum Qt Programming
    Replies: 3
    Last Post: 19th January 2007, 12:41

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.