Results 1 to 7 of 7

Thread: Can't show Image in widget connected to a lib.

  1. #1
    Join Date
    Apr 2011
    Posts
    7
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Can't show Image in widget connected to a lib.

    I'm trying to add an image to a widget which is connected to a lib. But for some reason I just can't seem to get the image to show. Or the image is hidden behind the widget, I don't know. I tried this on a new widget with no lib and it's working fine. Any help would be highely appreciated.

    I have tried with two different codes:

    Qt Code:
    1. void CDILedIndicator::paintEvent(QPaintEvent *)
    2. {
    3. QPainter *test = new QPainter(this);
    4. QImage test1;
    5. if(knapp)
    6. test1.load(":/Images/BlueOff");
    7. else
    8. test1.load(":/Images/BlueOn");
    9.  
    10. test->drawImage(0, 0, test1);
    11. }
    To copy to clipboard, switch view to plain text mode 

    and also with:

    Qt Code:
    1. void CDILedIndicator::paintEvent(QPaintEvent *)
    2. {
    3. QPoint pos(0,0);
    4.  
    5. drawIcon(m_painter, &pos);
    6. }
    7.  
    8. void CDILedIndicator::drawIcon(QPainter *painter, QPoint *position)
    9. {
    10. QImage OnIcon(":/Images/BlueOn");
    11. QImage OffIcon(":/Images/BlueOff");
    12.  
    13. ledValue ? painter->drawImage(*position, OnIcon) :
    14. painter->drawImage(*position, OffIcon);
    15. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Can't show Image in widget connected to a lib.

    What does QImage::isNull() return for your image objects?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Apr 2011
    Posts
    7
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Can't show Image in widget connected to a lib.

    Thank you for the quick reply.

    It is returning true.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Can't show Image in widget connected to a lib.

    Apparently then your images are not loaded. You are either missing image plugins or the paths you use don't point to valid images. Make sure you don't get a warning from the compiler about missing files when it tries to assemble the resource file (qrc).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Apr 2011
    Posts
    7
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Can't show Image in widget connected to a lib.

    I don't get why they shouldn't be loaded. I have made sure atleast a dozen times that all the paths is correct. I dont get any warning from the compiler what so ever.
    Also what do you mean by image plugins?

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Can't show Image in widget connected to a lib.

    Quote Originally Posted by Eneswar View Post
    I have made sure atleast a dozen times that all the paths is correct.
    What does this return?
    Qt Code:
    1. QFile::exists(":/Images/BlueOn");
    To copy to clipboard, switch view to plain text mode 

    Also what do you mean by image plugins?
    http://www.qtcentre.org/faq.php?faq=...missing_images
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Apr 2011
    Posts
    7
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Can't show Image in widget connected to a lib.

    Thank you for your reply, sorry I have not been able to reply as I have been home sick.
    The problem I had has now been fixed, thanks again.


    Edit:
    For those who are curious to fix my problem I had to recall Q_INIT_RESOURCE.
    Last edited by Eneswar; 2nd May 2011 at 09:57.

Similar Threads

  1. Replies: 10
    Last Post: 29th May 2010, 18:42
  2. Show portion of an image
    By ucntcme in forum Qt Programming
    Replies: 1
    Last Post: 22nd May 2010, 08:10
  3. How to show moving image
    By nrabara in forum Newbie
    Replies: 1
    Last Post: 30th December 2009, 08:24
  4. download and store/show image
    By peter_hr892h in forum Qt Programming
    Replies: 3
    Last Post: 25th June 2009, 05:16
  5. Show Image on a QLabel
    By ^NyAw^ in forum Newbie
    Replies: 11
    Last Post: 15th April 2008, 15:45

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.