Results 1 to 2 of 2

Thread: QMainWindow image background and QScrollArea fail.

  1. #1
    Join Date
    Jun 2012
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QMainWindow image background and QScrollArea fail.

    Hi everyone,

    I created a QMainWindow app using Qt Creator 2.4.1 and Qt SDK 1.2.1. The app only have a QScrollArea. In the QMainWindow constructor I did:

    Qt Code:
    1. QPalette palette;
    2. QString appdir = QApplication::applicationDirPath();
    3.  
    4. QImage imgfondo;
    5.  
    6. imgfondo.load( appdir + "/imagenes/fondo_aplicacion.jpg" );
    7. palette.setBrush( this->backgroundRole(), QBrush(imgfondo) );
    8. this->setPalette( palette );
    9. this->resize( imgfondo.width(), imgfondo.height() );
    To copy to clipboard, switch view to plain text mode 

    The image "fondo_aplicacion.jpg" is 1000 x 800 pixel image.

    The scrollarea is inside MainWindow with no special values. I just dragged the QScrollArea object and dropped inside the form (using Qt Designer).

    When I run the app the background image is ok on MainWindow but in the scrollarea the background image is not ok, It was like the background image is repainted again inside it. When I run the app I get this:

    Screenshot from 2012-08-19 00:49:47.jpg

    Actually, I try to find how the draw works over widgets, because if I use a QFrame instead of QScrollArea there's no problem.

    Thanks to anyone who try to help.

  2. #2
    Join Date
    Jun 2012
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QMainWindow image background and QScrollArea fail.

    I would like to add that when you add a ScrollArea object, Qt Designer add a ScrollAreaContainer objecto too. Maybe this is why scrollarea (or scrollareacontainer) background is repainted. I would like to find a way to make scrollarea background "transparent" to avoid this effect on MainWindow background.

    By the way, I have to use a scrollarea because I have to display a image. Actually I load a image in a QLabel object which is created inside ScrollArea.. but the image in the QLabel doesn't cover totally the effect of the scrollarea background image.

    I hope this new information will be useful to help me.

    Thanks.


    Added after 42 minutes:


    Hi every one,

    I found a solution, but I think it's not a elegant solution. I created a new image call "fondo_transparente.png" which is an 30 x 30 image (the size doesn't matter) with transparent property. So I set this image as scrollarea background and that's it.. works fine. I think this is not a pretty solution but it works for now. This is app running after my changes..

    Screenshot from 2012-08-19 12:16:20.jpg

    Qt Code:
    1. QPalette palette;
    2. QString appdir = QApplication::applicationDirPath();
    3.  
    4. QImage imgfondo( appdir + "/imagenes/fondo_aplicacion.jpg" );
    5. palette.setBrush( this->backgroundRole(), QBrush(imgfondo) );
    6. this->setPalette( palette );
    7. this->resize( imgfondo.width(), imgfondo.height() );
    8.  
    9. QImage imgfondoscroll( appdir + "/imagenes/fondo_transparente.png" );
    10. palette.setBrush( this->ui->scaSemanario->backgroundRole(), imgfondoscroll );
    11. this->ui->scaSemanario->setPalette( palette );
    To copy to clipboard, switch view to plain text mode 

    I'll try to figure out what this happen and what I have to do to solve it.

    Thanks to everyone. I hope my partial solution will be useful for others.
    Last edited by kuko; 19th August 2012 at 19:22.

Similar Threads

  1. QScrollArea misbehaving background style
    By Cruz in forum Qt Programming
    Replies: 6
    Last Post: 7th March 2021, 22:46
  2. Replies: 3
    Last Post: 13th November 2011, 09:12
  3. Replies: 0
    Last Post: 5th April 2011, 14:36
  4. Replies: 5
    Last Post: 19th March 2010, 19:13
  5. Set background image in QMainWindow
    By superteny in forum Qt Programming
    Replies: 4
    Last Post: 26th May 2009, 06:23

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.