Results 1 to 6 of 6

Thread: Scaling Background Image behind Widgets / dynamic stylesheet resources ?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1

    Default Re: Scaling Background Image behind Widgets / dynamic stylesheet resources ?

    Hi,

    for some reason stylesheet doesn't want to display files from NumbatEngine. Copying file back from NumbatEngine to hard disk as following writes the file just fine, i.e. it's not damaged or something:

    Qt Code:
    1. QPixmap pixFromNumbat("???Hello.jpg");
    2. pixFromNumbat.save("pixFromNumbat.jpg");
    To copy to clipboard, switch view to plain text mode 

    Also, stylesheet does display the image if it's read from hard disk (by disabling NumbatEngine from main()).

    I'm using Qt 4.7.2. Please, can anyone confirm that NumbatEngine works for you? I'm desperate

    EDIT
    This works too (taken from):
    Qt Code:
    1. /* Demonstration. */
    2. MainWindow::MainWindow(QWidget *parent)
    3. : QMainWindow(parent)
    4. {
    5. QPixmap pix("image.jpeg");
    6. pix.save("???Hello.jpg");
    7.  
    8. QLabel * lbl = new QLabel;
    9. //lbl->setStyleSheet("QLabel {background-image:url(\"???Hello.jpg\");}");
    10. lbl->setText("<b> this is a test</b><img src=\"???Hello.jpg\" />");
    11. setCentralWidget(lbl);
    12. }
    To copy to clipboard, switch view to plain text mode 

    but it doesn't work for styleSheet. Bug in Qt?
    Last edited by Flakes; 21st March 2011 at 15:27.

  2. #2
    Join Date
    Jun 2012
    Posts
    2

    Default Re: Scaling Background Image behind Widgets / dynamic stylesheet resources ?

    For posterity and because Google return this as the first result, the solution is to edit the widget palette with a brush using a QImage as "stamp".

    Qt Code:
    1. QPalette p = palette();
    2. QBrush brush = QBrush(generateMyQImage());
    3. p.setBrush(QPalette::Base, brush);
    4. p.setBrush(QPalette::Window, brush);
    5. setPalette(p);
    6. setAutoFillBackground(true);
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. background-image on a set of widgets
    By asieriko in forum Qt Programming
    Replies: 4
    Last Post: 22nd May 2010, 07:59
  2. Setting QDial background image using stylesheet
    By dpatel in forum Qt Programming
    Replies: 0
    Last Post: 28th April 2010, 13:13
  3. Zooming effect by scaling widgets
    By Cruz in forum Qt Programming
    Replies: 3
    Last Post: 1st February 2009, 09:43
  4. Resources in dynamic libraries
    By seneca in forum Qt Programming
    Replies: 0
    Last Post: 19th January 2009, 17:26
  5. Replies: 1
    Last Post: 7th October 2007, 23:02

Tags for this Thread

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.