Results 1 to 2 of 2

Thread: How to fill label backgroud with picture?--- finished

  1. #1
    Join Date
    Oct 2012
    Posts
    35
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    26

    Default How to fill label backgroud with picture?--- finished

    Hi All,

    eg.
    i have a picture which size is 100*100 , and the label size is 200*200, i want to the picture fill the label , whent the label's size change, the background can be changed also and fitted the label.(eg. when the label's size is 500*500, the picture's size must change to 500*500 so than fit the label)

    i use the below code ,but cann't not realize.

    label->setStyleSheet("QLabel{background-image:url(:/images/labelbackground_click.png)}");

    or

    backgroudPalette.setBrush(label->backgroundRole(), QBrush(QPixmap(":/images/bg.png")));
    label->setPalette(backgroudPalette);
    label->setAutoFillBackground(true);



    Please give me any advice.

    thanks and best regards.

    ken
    Last edited by kenchan; 14th December 2012 at 09:03. Reason: updated contents

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: How to fill label backgroud with picture?--- finished

    Why not simply use QLabel::setPixmap() and set scaled contents to true?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. CharFormat how set backgroud color ??
    By Pablik in forum Qt Programming
    Replies: 6
    Last Post: 25th July 2012, 07:15
  2. Replies: 3
    Last Post: 8th March 2012, 23:51
  3. Insert picture in a form using label
    By cwnelatury in forum Newbie
    Replies: 14
    Last Post: 18th March 2010, 23:43
  4. Replies: 1
    Last Post: 2nd February 2009, 10:04
  5. how to set backgroud in QTableView's title
    By catherine_98 in forum Qt Programming
    Replies: 1
    Last Post: 13th September 2007, 10:13

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.