View Full Version : How centralize images on QMdiArea

16th September 2008, 20:10
Hi people,

I need centralize a image into MdiArea and I don't know do this.
When I load a image to MdiArea, as the image have 75x150px it is displayed
in tiled.

Thanks for any help

16th September 2008, 20:28
How are you loading the image ??
YOu cud subclass MDiarea and override paint function. There you can draw ur pixmap once

16th September 2008, 20:30
This form:

QImage img("logo.jpg");

17th September 2008, 06:26
setBackground will treat the pixmap as a brush, and so it will be tiled.

You will need to subclass the MdiArea and draw the pixmap in paintEvent urself

17th September 2008, 13:25
Can you send-me a litle example of how do this?

Thanks in advanced.

17th September 2008, 18:36
something like -

MyMdiArea::paintEvent ( QPaintEvent * event )
QMdiArea::paintEvent(event); // this will cause draw a gray background
QPainter painter(this);
int x = (geometry().width() - pixmap.width() ) /2;
int y = (geometry().height() - pixmap.height() ) /2;
painter.drawPixmap(x,y,myPixmap); // draw the pixmap in center, or whatever location u want

17th September 2008, 21:27
Ok. Thanks for while.

5th October 2010, 14:10
Hello to everybody,
I'm a newbie of c++ and QT and i need to place an image in the center of a QMdiArea. I take your code but... how can I use it into QtCreator form? I tryed to promote a widget but QMdiArea can't be used as base widget , so I tryed to create plugin but it can't be attached (or I didn't be able to do it) to QtCreator widget list (, and more, how can I change the image from there? How can I change your constant in a property or pass it from the upper class using it?

Thanks a lot for your time.


PS. I'm using 2010.04 QT sdk on Windows