Results 1 to 2 of 2

Thread: Trouble with image painting (QPainter + QImage)

  1. #1
    Join Date
    Jan 2006
    Posts
    36
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Trouble with image painting (QPainter + QImage)

    Hello!

    Why this code is incorrect?
    Why image doesn't painting in frame?

    //////////////////////////////////////////////////////////////////
    #include <QtGui>
    #include <QApplication>
    int main(int argc, char *argv[])
    {
    QApplication app(argc, argv);
    QFrame f;
    QPainter p(&f);
    QImage i("tst.jpg");
    p.drawImage(0,0,i);
    f.show();
    return app.exec();
    }
    //////////////////////////////////////////////////////////////////

    P.S.
    mingw / QT-4.1.0

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Trouble with image painting (QPainter + QImage)

    Quote Originally Posted by krivenok
    Why this code is incorrect?
    Why image doesn't painting in frame?
    1. Everything you draw on a hidden widget will be discarded.
    2. Make sure you have JPEG image format plugin compiled
    3. The docs say:
      Warning: Unless a widget has the Qt::WA_PaintOutsidePaintEvent attribute set. A QPainter can only be used on a widget inside a paintEvent() or a function called by a paintEvent(). On Mac OS X, you can only paint on a widget in a paintEvent() regardless of this attribute's setting.


    If you want to show an image, use QLabel and the QLabel::setPixmap() method.

Similar Threads

  1. get QImage object from buffer
    By Sheng in forum Qt Programming
    Replies: 2
    Last Post: 21st September 2012, 03:03
  2. Multiple QPainters on QImage
    By fire in forum Qt Programming
    Replies: 3
    Last Post: 14th August 2008, 14:10
  3. QPainter and QImage
    By beerkg in forum Newbie
    Replies: 3
    Last Post: 7th September 2006, 15:48

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.