PDA

View Full Version : QMainWindow image background and QScrollArea fail.



kuko
19th August 2012, 08:02
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:



QPalette palette;
QString appdir = QApplication::applicationDirPath();

QImage imgfondo;

imgfondo.load( appdir + "/imagenes/fondo_aplicacion.jpg" );
palette.setBrush( this->backgroundRole(), QBrush(imgfondo) );
this->setPalette( palette );
this->resize( imgfondo.width(), imgfondo.height() );


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:

8132

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.

kuko
19th August 2012, 19:22
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..

8136



QPalette palette;
QString appdir = QApplication::applicationDirPath();

QImage imgfondo( appdir + "/imagenes/fondo_aplicacion.jpg" );
palette.setBrush( this->backgroundRole(), QBrush(imgfondo) );
this->setPalette( palette );
this->resize( imgfondo.width(), imgfondo.height() );

QImage imgfondoscroll( appdir + "/imagenes/fondo_transparente.png" );
palette.setBrush( this->ui->scaSemanario->backgroundRole(), imgfondoscroll );
this->ui->scaSemanario->setPalette( palette );


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.