Results 1 to 7 of 7

Thread: Image into QMdiArea (again)

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    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

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

    Default Re: Image into QMdiArea (again)

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

  3. #3
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    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!

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    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 

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
  •  
Qt is a trademark of The Qt Company.