Results 1 to 17 of 17

Thread: Resources files (.qrc) not working

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2008
    Posts
    26
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Windows

    Unhappy Re: Resources files (.qrc) not working

    Did you saw the image after that?
    No, I didn't....

    I think that the resource file is correctly added: I edited this line, adding an icon from the resource file:

    Qt Code:
    1. QIcon MyCanvasViewPlugin::icon() const
    2. {
    3. return QIcon(":/images/qtlogo.png");
    4. }
    To copy to clipboard, switch view to plain text mode 

    and this image appeared in QtDesigner on the WQidget Box next to the custom widget.

    The load image function is also working fine, but calling the slot addButterfly() makes no effect when using the Q3CanvasPolygonalItem class.

    UPDATE

    the slot addButterfly() uses the class Q3CanvasPolygonalItem for displaying the image. I found this on the Internet:

    The Q3CanvasPolygonalItem class provides a polygonal canvas item on a Q3Canvas. More...

    #include <Q3CanvasPolygonalItem>

    This class is part of the Qt 3 support library. It is provided to keep old source code working. We strongly advise against using it in new code. See Porting to Qt 4 for more information.

    Note to Qt Desktop Light Edition users: This class is only available in the Qt Desktop Edition.
    Maybe I should use the class QAbstractGraphicsShapeItem instead?

    Any suggerences?
    Last edited by degs2k4; 20th February 2008 at 12:52. Reason: updated contents

  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: Resources files (.qrc) not working

    Quote Originally Posted by degs2k4 View Post
    No, I didn't....
    So maybe the resources work and the problem is in the code that displays the image?

    What happens if you add:
    Qt Code:
    1. l.setPixmap( QPixmap( ":/images/butterfly.png" ) );
    2. l.show();
    To copy to clipboard, switch view to plain text mode 
    just before return app.exec()?

    Quote Originally Posted by degs2k4 View Post
    Maybe I should use the class QAbstractGraphicsShapeItem instead?
    No, you have to use Q3CanvasItem subclass, if you want to stick with Q3Canvas.

  3. The following user says thank you to jacek for this useful post:

    degs2k4 (21st February 2008)

  4. #3
    Join Date
    Jan 2008
    Posts
    26
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Windows

    Unhappy Re: Resources files (.qrc) not working

    What happens if you add:
    Qt Code:
    Qt Code:
    1. l.setPixmap( QPixmap( ":/images/butterfly.png" ) );
    2. l.show();
    To copy to clipboard, switch view to plain text mode 
    just before return app.exec()?

    If I do that, I can see the image !

    So the problem is in addButterfly() slot then, right?
    Last edited by degs2k4; 20th February 2008 at 13:22. Reason: reformatted to look better

  5. #4
    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: Resources files (.qrc) not working

    Quote Originally Posted by degs2k4 View Post
    So the problem is in addButterfly() slot then, right?
    Try showing Q3CanvasPixmap instead of your custom item.

    What does ImageItem contructor do with the second parameter?

  6. The following user says thank you to jacek for this useful post:

    degs2k4 (21st February 2008)

  7. #5
    Join Date
    Jan 2008
    Posts
    26
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Windows

    Unhappy Re: Resources files (.qrc) not working

    Quote Originally Posted by jacek View Post
    Try showing Q3CanvasPixmap instead of your custom item.

    What does ImageItem contructor do with the second parameter?
    Does this:

    Qt Code:
    1. ImageItem::ImageItem( QImage img, Q3Canvas *canvas )
    2. : Q3CanvasRectangle( canvas ), image(img)
    3. {
    4. setSize( image.width(), image.height() );
    5. imageRTTI = 984376;
    6. #if !defined(Q_WS_QWS)
    7. pixmap.fromImage(image, Qt::OrderedAlphaDither);
    8. #endif
    9. }
    To copy to clipboard, switch view to plain text mode 

  8. #6
    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: Resources files (.qrc) not working

    Quote Originally Posted by degs2k4 View Post
    Does this:
    This looks OK (except that image and pixmap variables esentially hold the same data).

    How does drawShape() implementation look like?

  9. The following user says thank you to jacek for this useful post:

    degs2k4 (21st February 2008)

  10. #7
    Join Date
    Jan 2008
    Posts
    26
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Windows

    Red face Re: Resources files (.qrc) not working

    Quote Originally Posted by jacek View Post
    This looks OK (except that image and pixmap variables esentially hold the same data).

    How does drawShape() implementation look like?
    OK, the problem was with drawShape. drawShape() of ImageItem looked like this:

    Qt Code:
    1. void ImageItem::drawShape( QPainter &p )
    2. {
    3. // On Qt/Embedded, we can paint a QImage as fast as a QPixmap,
    4. // but on other platforms, we need to use a QPixmap.
    5. #if defined(Q_WS_QWS)
    6. p.drawImage( int(x()), int(y()), image, 0, 0, -1, -1, OrderedAlphaDither );
    7. #else
    8. p.drawPixmap( int(x()), int(y()), pixmap );
    9. #endif
    10. }
    To copy to clipboard, switch view to plain text mode 

    And I changed it to this:

    Qt Code:
    1. void ImageItem::drawShape( QPainter &p )
    2. {
    3. // On Qt/Embedded, we can paint a QImage as fast as a QPixmap,
    4. // but on other platforms, we need to use a QPixmap.
    5. #if defined(Q_WS_WIN)
    6. p.drawImage( int(x()), int(y()), image, 0, 0, -1, -1, Qt::OrderedAlphaDither );
    7. #else
    8. p.drawPixmap( int(x()), int(y()), pixmap );
    9. #endif
    10.  
    11. }
    To copy to clipboard, switch view to plain text mode 

    And the butterfly was at last displayed !

    So the problem is with Q_WS_QWS (maybe because it is from Qtopia?): used for detecting the type of windowing system that is used with Qt. Correspondingly there exist Q_WS_X11 and Q_WS_WIN that are set when compiling with Qt/X11 or Qt/Windows (and there's one
    for mac in Qt3 versions).

    Of course I can't just remove the macro that easily.... Why it didn't work when using Q_WS_QWS? It is OK to use Q_WS_X11, Q_WS_WIN... instead?

    (I'm using windows...)
    Last edited by degs2k4; 20th February 2008 at 23:30. Reason: updated contents

  11. #8
    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: Resources files (.qrc) not working

    The problem is ImageItem::ImageItem(). It should be:
    Qt Code:
    1. pixmap = QPixmap::fromImage(image, Qt::OrderedAlphaDither);
    To copy to clipboard, switch view to plain text mode 

  12. The following user says thank you to jacek for this useful post:

    degs2k4 (21st February 2008)

  13. #9
    Join Date
    Jan 2008
    Posts
    26
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Windows

    Smile Re: Resources files (.qrc) not working [SOLVED]

    Quote Originally Posted by jacek View Post
    The problem is ImageItem::ImageItem(). It should be:
    Qt Code:
    1. pixmap = QPixmap::fromImage(image, Qt::OrderedAlphaDither);
    To copy to clipboard, switch view to plain text mode 
    OH!!!! I see:

    The Qt3 version was returning a BOOL ! :
    bool QPixmap::convertFromImage ( const QImage & image, ColorMode mode )
    and the Qt4 version is returning the Pixmap which I have to grab explicitely !
    QPixmap QPixmap::fromImage ( const QImage & image, Qt::ImageConversionFlags flags = Qt::AutoColor )
    THANKS!!!!!!!!!!!!!!!!!!!!!!!!!!!

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.