Results 1 to 5 of 5

Thread: Insert an image with transparent background on base background

  1. #1
    Join Date
    Oct 2013
    Posts
    2
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Insert an image with transparent background on base background

    Hello Everybody!
    I'm a newbie of Qt. I have a problem need help. I want insert an image with transparent background (icon-home.png) in to a window which I created.
    This window I set background by follow command:

    Qt Code:
    1. window->setStyleSheet("background-image: url(./images/bg.jpg");
    To copy to clipboard, switch view to plain text mode 

    Image I insert by:
    Qt Code:
    1. QLabel *image = new QLabel;
    2. image->setPixmap(QPixmap("./images/icon-home.png"));
    To copy to clipboard, switch view to plain text mode 

    Then:
    Qt Code:
    1. layout->addWidget(image);
    2. window->setLayout(layout);
    To copy to clipboard, switch view to plain text mode 

    but when program run, the area transparent of image haven't color of base background (otherwise, the area stransparent of image cover base background).
    How to make this area transparent dont cover base background ?
    Thanks!
    Attached Images Attached Images
    Last edited by mrphunghuy; 31st October 2013 at 09:23.

  2. #2
    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: Insert an image with transparent background on base background

    Try This:

    Qt Code:
    1. setStyleSheet("background-image: url(:/bg.jpg)");
    2. QLabel *image = new QLabel(this);
    3. image->setPixmap(QPixmap(":/icon-home.png"));
    To copy to clipboard, switch view to plain text mode 

    Make sure your images are available in the resource file with prefix "/".
    Heavy Metal Rules. For those about to rock, we salute you.
    HIT THANKS IF I HELPED.

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

    mrphunghuy (31st October 2013)

  4. #3
    Join Date
    Oct 2013
    Posts
    2
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Insert an image with transparent background on base background

    It work! Thanks you!

  5. #4
    Join Date
    Sep 2013
    Posts
    107
    Thanks
    16
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Insert an image with transparent background on base background

    hi.. how to move the image which u have inserted on the top of background. based on the certain time intervals inserted image can change the location ont he background. something like tracking of the objects/devices/systems.

    Thanks in advance.

  6. #5
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Insert an image with transparent background on base background

    For custom drawing , you will need to override the QWidget::paintEvent function.

Similar Threads

  1. Transparent Push button over background image
    By KumarKandasamy in forum Newbie
    Replies: 2
    Last Post: 15th May 2014, 08:22
  2. Replies: 0
    Last Post: 5th April 2011, 14:36
  3. Replies: 1
    Last Post: 25th June 2010, 19:31
  4. How to insert an image in background of a Form?
    By awanish_jmi in forum Qt Tools
    Replies: 2
    Last Post: 8th August 2008, 11:52
  5. Transparent background on QLabel on transparent QWidget
    By codeslicer in forum Qt Programming
    Replies: 1
    Last Post: 13th February 2008, 03:10

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.