Results 1 to 8 of 8

Thread: How centralize images on QMdiArea

  1. #1
    Join Date
    Jul 2007
    Location
    Jundiai/SP, Brazil
    Posts
    114
    Thanks
    5
    Thanked 7 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question How centralize images on QMdiArea

    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

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How centralize images on QMdiArea

    How are you loading the image ??
    YOu cud subclass MDiarea and override paint function. There you can draw ur pixmap once

  3. #3
    Join Date
    Jul 2007
    Location
    Jundiai/SP, Brazil
    Posts
    114
    Thanks
    5
    Thanked 7 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How centralize images on QMdiArea

    This form:

    QImage img("logo.jpg");
    mdiArea->setBackground(QPixmap::fromImage(img));

  4. #4
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How centralize images on QMdiArea

    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

  5. #5
    Join Date
    Jul 2007
    Location
    Jundiai/SP, Brazil
    Posts
    114
    Thanks
    5
    Thanked 7 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How centralize images on QMdiArea

    Can you send-me a litle example of how do this?

    Thanks in advanced.

  6. #6
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How centralize images on QMdiArea

    something like -

    Qt Code:
    1. MyMdiArea::paintEvent ( QPaintEvent * event )
    2. {
    3. QMdiArea::paintEvent(event); // this will cause draw a gray background
    4. QPainter painter(this);
    5. int x = (geometry().width() - pixmap.width() ) /2;
    6. int y = (geometry().height() - pixmap.height() ) /2;
    7. painter.drawPixmap(x,y,myPixmap); // draw the pixmap in center, or whatever location u want
    8. }
    To copy to clipboard, switch view to plain text mode 

  7. #7
    Join Date
    Jul 2007
    Location
    Jundiai/SP, Brazil
    Posts
    114
    Thanks
    5
    Thanked 7 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Smile Re: How centralize images on QMdiArea

    Ok. Thanks for while.

  8. #8
    Join Date
    Oct 2009
    Posts
    65
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How centralize images on QMdiArea

    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.

    Michele

    PS. I'm using 2010.04 QT sdk on Windows

Similar Threads

  1. import large number of images
    By sriluyarlagadda in forum Qt Programming
    Replies: 5
    Last Post: 15th May 2008, 10:26
  2. QMdiArea unwanted actvation
    By fullmetalcoder in forum Qt Programming
    Replies: 7
    Last Post: 12th November 2007, 07:09

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.