Results 1 to 7 of 7

Thread: How assign dynamically QPixmap to QML delegate when using QAbstractItemModel in 5.7 ?

  1. #1
    Join Date
    Aug 2011
    Posts
    38
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default How assign dynamically QPixmap to QML delegate when using QAbstractItemModel in 5.7 ?

    I do have
    Qt Code:
    1. TreeView {
    2. id: view
    3. enabled: !settingsData.allDisabled
    4. TableViewColumn {
    5. title: "Icon"
    6. role: "image"
    7. width: 32
    8. delegate: Image {
    9. height: 20
    10. source: "image://icons/" + id
    11. // source: image
    12. }
    13. }
    14. TableViewColumn {
    15. title: "Name"
    16. role: "display"
    17. resizable: true
    18. visible: true
    19. }
    20. TableViewColumn {
    To copy to clipboard, switch view to plain text mode 

    And

    Qt Code:
    1. QHash<int, QByteArray> PasswordListModel::roleNames() const {
    2.  
    3. QHash<int, QByteArray> result = QAbstractItemModel::roleNames();
    4. result.insert(ImageRole, QByteArrayLiteral("image"));
    5. result.insert(LastAccessedRole, QByteArrayLiteral("lastAccessed"));
    6. result.insert(LastModifiedRole, QByteArrayLiteral("lastModified"));
    7. result.insert(ContainerIdRole, QByteArrayLiteral("containerId"));
    8. return result;
    9. }
    To copy to clipboard, switch view to plain text mode 

    and

    Qt Code:
    1. QVariant PasswordListModel::data(const QModelIndex &index, int role) const
    2. {
    3. if (!index.isValid())
    4. return QVariant();
    5.  
    6. .
    7. .
    8. .
    9.  
    10.  
    11. case ImageRole: {
    12. qDebug () << "ImageRole";
    13. // return QVariant(QString("image://icons/password_icon"));
    14. // return QVariant(QString("password_icon"));
    15. return QString ("password_icon");
    16. }
    To copy to clipboard, switch view to plain text mode 

    How to ImagaProvider will get notification to return correct bitmap for QML side. Based on my debugging, MyClass::requestPixmap(const QString &id, QSize */*size*/, const QSize &requestedSize) will not get request from system.
    Last edited by anda_skoa; 20th July 2016 at 22:27. Reason: changed [qtclass] to [code]

  2. #2
    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: How assign dynamically QPixmap to QML delegate when using QAbstractItemModel in 5

    Maybe you can start by describing what you have.

    I assume you images are not on disk or anywhere else that is referencable by URL, right?

    How does your application generate them and where/how to you store them in memory?

    Cheers,
    _

  3. #3
    Join Date
    Aug 2011
    Posts
    38
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How assign dynamically QPixmap to QML delegate when using QAbstractItemModel in 5

    It's in the disk, QQuickImageProvider derived class will provided them . Model should show correct icon based on type of item which be different in child list. Icons are included in the project.

  4. #4
    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: How assign dynamically QPixmap to QML delegate when using QAbstractItemModel in 5

    Ok, but if they are on disk, why do you need a custom image provider?

    Just let the model return the file URI. see QUrl::fromLocalFile().

    Cheers,
    _

  5. #5
    Join Date
    Aug 2011
    Posts
    38
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How assign dynamically QPixmap to QML delegate when using QAbstractItemModel in 5

    yes, ok. How to assign this URI to delegate in use ?

  6. #6
    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: How assign dynamically QPixmap to QML delegate when using QAbstractItemModel in 5

    Like any other model data

    Qt Code:
    1. source: styleData.value
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

  7. #7
    Join Date
    Aug 2011
    Posts
    38
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How assign dynamically QPixmap to QML delegate when using QAbstractItemModel in 5

    It helped, thanks.

Similar Threads

  1. Replies: 2
    Last Post: 13th November 2014, 12:32
  2. Replies: 0
    Last Post: 8th May 2014, 22:09
  3. Replies: 5
    Last Post: 19th March 2014, 13:05
  4. Replies: 2
    Last Post: 24th December 2010, 19:08
  5. Replies: 4
    Last Post: 16th March 2009, 10:08

Tags for this Thread

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.