Results 1 to 7 of 7

Thread: Image into QMdiArea (again)

  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

    Unhappy Image into QMdiArea (again)

    Hi people,

    I did like to put an image (logo) in my MdiArea. Already I tried many methods but nothing worked.
    The application main window was created with QDesigner and I create the mdiarea like this:

    qBuilder::qBuilder(QWidget* parent, Qt::WFlags fl)
    : QMainWindow( parent, fl ), Ui::formQBuilder()
    {
    setupUi(this);
    mdiArea = new QMdiArea(this);
    setCentralWidget(mdiArea);

    }

    I try use:

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

    but the logo is showd in tiled mode. Already I tried to use also QPaintEvent but also didn't works

    Can someone help me to resolve this problem?

    Thanks

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Image into QMdiArea (again)

    Quote Originally Posted by vcp View Post
    qBuilder::qBuilder(QWidget* parent, Qt::WFlags fl)
    : QMainWindow( parent, fl ), Ui::formQBuilder()
    {
    setupUi(this);
    mdiArea = new QMdiArea(this);
    setCentralWidget(mdiArea);

    }
    Ok, that looks stange to me. Normally you set the QMdiArea already in the designer so only "setupUi(this);" is necessary (or how's your ui file) and then just set the background:

    Qt Code:
    1. qBuilder::qBuilder(QWidget* parent, Qt::WFlags fl)
    2. : QMainWindow( parent, fl ), Ui::formQBuilder()
    3. {
    4. setupUi(this);
    5. QImage img("logo.jpg");
    6. mdiArea->setBackground(img);
    7. }
    To copy to clipboard, switch view to plain text mode 

    Not proofed, but should work if "logo.jpg" exists.

    Lykurg

  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: Image into QMdiArea (again)

    Hi thanks for your answer, but the problem is that the image is shown side by side (tiled)

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Image into QMdiArea (again)

    Quote Originally Posted by vcp View Post
    Hi thanks for your answer, but the problem is that the image is shown side by side (tiled)
    Ah, sorry, have read to fast. So you have to subclass:
    Qt Code:
    1. #ifndef MYQMIDIAREA_H
    2. #define MYQMIDIAREA_H
    3.  
    4. #include <QtGui>
    5.  
    6. class myQMdiArea : public QMdiArea
    7. {
    8. Q_OBJECT
    9. public:
    10. myQMdiArea(QWidget *parent = 0);
    11. protected:
    12. void paintEvent(QPaintEvent *);
    13. };
    14.  
    15. #endif // MYQMIDIAREA_H
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. #include "myqmdiarea.h"
    2.  
    3. myQMdiArea::myQMdiArea(QWidget *parent)
    4. : QMdiArea(parent)
    5. {}
    6.  
    7. void myQMdiArea::paintEvent(QPaintEvent *paintEvent)
    8. {
    9. QPainter painter(viewport());
    10. painter.fillRect(paintEvent->rect(), QColor(23,200,123));
    11. QImage img("/home/lykurg/Desktop/icons/oxygen/16x16/apps/gimp.png");
    12. painter.drawImage(QPointF(10,10),img);
    13. }
    To copy to clipboard, switch view to plain text mode 
    Note: the paintEvent is not very nice, only an example!

  5. #5
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Image into QMdiArea (again)

    ok, better in paintEvent:
    Qt Code:
    1. void myQMdiArea::paintEvent(QPaintEvent *paintEvent)
    2. {
    3. QMdiArea::paintEvent(paintEvent);
    4. // and now only paint your image here
    5. }
    To copy to clipboard, switch view to plain text mode 

  6. #6
    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

    Talking Re: Image into QMdiArea (again)

    Hi Lykurg,

    Yor explanation was very good and simple.

    Thanks a lot! You help

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

    Default Re: Image into QMdiArea (again)

    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. can Qlabel display a series of image one by one ?
    By jirach_gag in forum Qt Tools
    Replies: 3
    Last Post: 11th August 2008, 15:36
  2. Finding marks on scanned image for alignment
    By caduel in forum Qt Programming
    Replies: 1
    Last Post: 23rd September 2007, 02:10
  3. Explanation to Image Formats
    By sincnarf in forum Qt Programming
    Replies: 13
    Last Post: 6th July 2007, 17:02
  4. Help needed handling image data
    By toratora in forum General Programming
    Replies: 2
    Last Post: 11th May 2007, 09:24
  5. How and when to repaint a widget ?
    By yellowmat in forum Newbie
    Replies: 7
    Last Post: 3rd April 2006, 16:36

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.