Results 1 to 3 of 3

Thread: loading QPixmap doesn't work

  1. #1
    Join Date
    Nov 2011
    Posts
    8
    Thanks
    2

    Default loading QPixmap doesn't work

    Qt Code:
    1. MainPlayerBoard::MainPlayerBoard(QString naam, short count, QWidget *parent):
    2. QMainWindow(parent),
    3. ui(new Ui::MainPlayerBoard)
    4. {
    5. ui->setupUi(this);
    6. QImage eerste;
    7. eerste.load(":/image.gif");
    8. ui->tile1->pixmap();
    9. ui->tile1->setPixmap(QPixmap::fromImage(eerste));
    10. ui->tile1->show();
    11. MainPlayerBoard::setWindowTitle(naam);
    12. m_count = count;
    13. }
    To copy to clipboard, switch view to plain text mode 

    I first tried to load the pictures from a QVector<QPixmap*> which didn't work.
    Then I tried to load them from a QPixmap, didn't work either...
    after a while I tried this...
    But the problem remains, the QPixmap on my screen does not show up...
    Please help me out

  2. #2
    Join Date
    Oct 2007
    Location
    Lake Forest, CA, USA
    Posts
    132
    Thanks
    10
    Thanked 27 Times in 22 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default Re: loading QPixmap doesn't work

    What is 'tile1'? I assume it should be QLabel in you UI. The following code is enough to show pixmap:
    Qt Code:
    1. ui->pixmapLabel->setPixmap(QPixmap::fromImage(QImage(":/image.jpg")));
    To copy to clipboard, switch view to plain text mode 
    Oleg Shparber

  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: loading QPixmap doesn't work

    Quote Originally Posted by dieter View Post
    Qt Code:
    1. MainPlayerBoard::MainPlayerBoard(QString naam, short count, QWidget *parent):
    2. QMainWindow(parent),
    3. ui(new Ui::MainPlayerBoard)
    4. {
    5. ui->setupUi(this);
    6. QImage eerste;
    7. eerste.load(":/image.gif");
    8. ui->tile1->pixmap();
    9. ui->tile1->setPixmap(QPixmap::fromImage(eerste));
    10. ui->tile1->show();
    11. MainPlayerBoard::setWindowTitle(naam);
    12. m_count = count;
    13. }
    To copy to clipboard, switch view to plain text mode 
    Line 7: Have you checked the return value from QImage::load()? Do you have a GIF image format plugin built and/or deployed?
    Line 8 is pointless: I don't know what you are trying to achieve here, but you ignore the return value anyway.
    Line 10 is pointless: The label (I assume tile1 is a label) will be shown by default when its parent is shown.

    You should be able to construct a QPixmap directly from a GIF or PNG file without an intermediate QImage.

Similar Threads

  1. Problem loading QPixmap on Qt 4.2 in Symbian s60
    By Tito in forum Qt Programming
    Replies: 9
    Last Post: 11th May 2010, 13:30
  2. Replies: 0
    Last Post: 19th February 2010, 16:33
  3. QPixmap::save() doesn't work
    By Persoontje in forum Qt Programming
    Replies: 2
    Last Post: 25th November 2009, 11:53
  4. Loading a QPixmap from raw data
    By pherthyl in forum Qt Programming
    Replies: 1
    Last Post: 27th January 2008, 10:12
  5. Loading a custom image into a QPixmap
    By KShots in forum Qt Programming
    Replies: 12
    Last Post: 5th August 2006, 00:16

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.