Results 1 to 10 of 10

Thread: Extend QML Image

  1. #1
    Join Date
    Sep 2014
    Posts
    3
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Extend QML Image

    Hello!

    How can I extend the QML Image element? I want to override paint method to draw a rounded image.

  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: Extend QML Image

    Quote Originally Posted by Gigitsu View Post
    Hello!

    How can I extend the QML Image element? I want to override paint method to draw a rounded image.
    You cannot do that this way (by extending), at least with QtQuick2 (Qt5). But what you can do is to apply a shader effect that will mask the image with the shape of your choice. You can either apply a fragment shader program directly or you can use OpacityMask item from QtGraphicalEffects to use a rounded rect as a mask for your image.

    By the way, in QtQuick 2 there is no "paint method" for Qt Quick items. Drawing is done by constructing a scene graph consisting of OpenGL primitives that render the item.
    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
    Sep 2014
    Posts
    3
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: Extend QML Image

    Is there any way to do this with qt4 and QtQuick 1.0?

    Thank you

  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: Extend QML Image

    In QtQuick 1 all items are derived from QGraphicsItem so you can override the paint() method for them. It should be quite straightforward to implement a custom image item, e.g. using QGraphicsEffect.
    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
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Extend QML Image

    In QtQuick2 it is possible to paint an item with the traditiona QPainter API using QQuickPaintedItem.

    Cheers,
    _

  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: Extend QML Image

    Quote Originally Posted by anda_skoa View Post
    In QtQuick2 it is possible to paint an item with the traditiona QPainter API using QQuickPaintedItem.
    Only for completely custom items, not for extending built-in ones. And even then you are painting on a texture that is later passed to a node in the graph and continues along the same path.
    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
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Extend QML Image

    Right, just wanted to make sure this option is also known.

    Cheers,
    _

  8. #8
    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: Extend QML Image

    Quote Originally Posted by anda_skoa View Post
    Right, just wanted to make sure this option is also known.
    Sure, I just wanted to make sure we don't get a question about extending existing QtQuick2 items with QPainter
    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.


  9. #9
    Join Date
    Sep 2014
    Posts
    3
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: Extend QML Image

    Quote Originally Posted by wysota View Post
    In QtQuick 1 all items are derived from QGraphicsItem so you can override the paint() method for them. It should be quite straightforward to implement a custom image item, e.g. using QGraphicsEffect.
    Ok, this is whati I've done so far:

    Qt Code:
    1. void RoundImage::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
    2. {
    3. QImage image(m_url.url());
    4. QBrush brush(image);
    5.  
    6. int h = m_explicitSourceSize ? m_sourcesize.height() : image.height();
    7. int w = m_explicitSourceSize ? m_sourcesize.width() : image.width();
    8.  
    9. QPen pen;
    10. pen.setColor(Qt::darkGray);
    11. pen.setJoinStyle(Qt::RoundJoin);
    12.  
    13. painter->setBrush(brush);
    14. painter->setPen(pen);
    15. painter->drawRoundedRect(0, 0, w, h, w/2, h/2);
    16. }
    To copy to clipboard, switch view to plain text mode 

    and the m_url is a QUrl.

    The problem is that I don't know how to load an image or pixmap from an url and I need to use a QUrl because the source can be an image provider too

  10. #10
    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: Extend QML Image

    The QDeclarativeEngine instance has a QNetworkAccessManager instance you can use.
    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.


Similar Threads

  1. Extend QGraphicsScene only in one direction
    By sean.reynolds in forum Qt Programming
    Replies: 0
    Last Post: 25th April 2011, 12:20
  2. Extend a Qt signal?
    By realdarkman71 in forum Newbie
    Replies: 2
    Last Post: 3rd December 2010, 10:29
  3. i need extend image using QPainter
    By erichong81 in forum Qt Programming
    Replies: 1
    Last Post: 18th March 2010, 08:51
  4. Extend the ui_xxx.h file
    By dosto.walla in forum Qt Tools
    Replies: 20
    Last Post: 23rd September 2008, 17:44
  5. How to extend a class ?
    By agent007se in forum Newbie
    Replies: 11
    Last Post: 27th June 2006, 12:09

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.