PDA

View Full Version : Can't show Image in widget connected to a lib.



Eneswar
19th April 2011, 15:39
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:


void CDILedIndicator::paintEvent(QPaintEvent *)
{
QPainter *test = new QPainter(this);
QImage test1;
if(knapp)
test1.load(":/Images/BlueOff");
else
test1.load(":/Images/BlueOn");

test->drawImage(0, 0, test1);
}

and also with:


void CDILedIndicator::paintEvent(QPaintEvent *)
{
QPoint pos(0,0);

drawIcon(m_painter, &pos);
}

void CDILedIndicator::drawIcon(QPainter *painter, QPoint *position)
{
QImage OnIcon(":/Images/BlueOn");
QImage OffIcon(":/Images/BlueOff");

ledValue ? painter->drawImage(*position, OnIcon) :
painter->drawImage(*position, OffIcon);
}

wysota
19th April 2011, 15:40
What does QImage::isNull() return for your image objects?

Eneswar
19th April 2011, 15:46
Thank you for the quick reply.

It is returning true.

wysota
19th April 2011, 16:05
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).

Eneswar
19th April 2011, 16:10
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?

wysota
19th April 2011, 16:13
I have made sure atleast a dozen times that all the paths is correct.

What does this return?

QFile::exists(":/Images/BlueOn");


Also what do you mean by image plugins?
http://www.qtcentre.org/faq.php?faq=qt_images#faq_qt_missing_images

Eneswar
2nd May 2011, 10:43
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.