Results 1 to 4 of 4

Thread: how to change BackGround image on a stacked widget

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Aug 2009
    Posts
    3
    Qt products
    Qt4

    Default how to change BackGround image on a stacked widget

    Hi.

    I'm using a stacked widget with 6 page on.

    I would like to change the background to a image that I get from a server, the image is put into a pixmap

    I have the following code, and it works ok, but there must be a more easy way to do this, I did try to change the palette but I can't get it to work

    void MainWindow:n_receive_albumcover(QPixmap *p)
    {
    qDebug()<<"Got a picture";
    //ui->label_7->setPixmap(*p);
    p->save("cover_test.jpg");
    ui->stackedWidget->setStyleSheet("QWidget#page{border-image: url(cover_test.jpg) ;}QWidget{background-color: rgb(44, 44, 44);}");
    }


    I manage to get this code working, but only if I do not have any thing in the stylesheet. as soon as I put something into the stylesheet in the desigen it do not work anymore.

    Code for change of palette

    ui->stackedWidget->setAutoFillBackground(true);
    QPalette pal(ui->stackedWidget->palette());
    pal.setBrush(QPalette::Window,QBrush(*p));
    ui->stackedWidget->setPalette(pal);



    So if I put this into the stylesheet. The palette do not work anymore

    QPushButtonressed{
    background-color: qlineargradient(spreadad, x1:0.494, y1:1, x2:0.523, y2:0, stop:0 rgba(0, 0, 0, 255), stop:1 rgba(255, 255, 255, 255));
    border-style:inset;
    border-top: 1px solid gray;
    border-right: 1px solid gray;
    border-bottom: 1px solid white;
    border-left: 1px solid white;
    border-radius: 10px;

    Question why is this ?
    and is there a way to use the pixmap pointer direct to the stylesheet
    and one last thing, the stylesheet in ui-stackedwidget is quite big, and it looks like you need to write everything if you use setStyleSheet.





    Br.
    Michael Rahr

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: how to change BackGround image on a stacked widget

    Question why is this ?
    Because the style sheet overrides the palette.
    You either use a stylesheet, or you don't.

    Your first code is the way to go, if you want to use style sheets.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Aug 2009
    Posts
    3
    Qt products
    Qt4

    Default Re: how to change BackGround image on a stacked widget

    Thanks.

    So just to understand 100% If I use a stylesheet, and I want to dynamic change a image, that is not located in a resource file or on the disk but in a pixmap, then I need to save it to a file, like I already do, it is not possible to use a pointer to a pixmap in the setStylesheet

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: how to change BackGround image on a stacked widget

    is not possible to use a pointer to a pixmap in the setStylesheet
    not to my knowledge.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

Similar Threads

  1. Replies: 10
    Last Post: 10th November 2010, 03:12
  2. Setting background image for Central Widget
    By xfurrier in forum Qt Programming
    Replies: 8
    Last Post: 25th February 2010, 10:14
  3. Replies: 5
    Last Post: 10th April 2008, 09:52
  4. Background image for main window widget using css.
    By Enygma in forum Qt Programming
    Replies: 8
    Last Post: 23rd August 2007, 15:40
  5. Background image and semitransparent widget
    By asieriko in forum Qt Programming
    Replies: 3
    Last Post: 20th August 2007, 16:43

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.