Results 1 to 9 of 9

Thread: How to get data from TableView - QML Desktop Components

  1. #1
    Join Date
    Dec 2011
    Posts
    21
    Thanks
    2
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default How to get data from TableView - QML Desktop Components

    Anyone has an idea how to get data from currently selected item from TableView?
    In ListView there is currentItem, but in TableView there is only currentIndex. Index should be enough, just get data at index. But how do do that? It should be extremely simple.

    I'd like to get item and show additional info (description) in separate text area.

    Any ideas?

  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: How to get data from TableView - QML Desktop Components

    Hmmm... by getting the index number from currentIndex.row ?
    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
    Dec 2011
    Posts
    21
    Thanks
    2
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to get data from TableView - QML Desktop Components

    currentIndex itself is row index so I have row index but still no idea how to get object at this index. I can get it from python backend, but I don't want to - unnecessary redundant code.
    If I have ListView there is currentItem and I'm able to operate directly on this item.

  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: How to get data from TableView - QML Desktop Components

    Doesn't this work?

    javascript Code:
    1. model.get(currentIndex).someRole
    To copy to clipboard, switch view to plain text mode 
    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. The following user says thank you to wysota for this useful post:

    TheIndependentAquarius (1st October 2016)

  6. #5
    Join Date
    Dec 2011
    Posts
    21
    Thanks
    2
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to get data from TableView - QML Desktop Components

    TypeError: Result of expression 'model.get' [undefined] is not a function.

    The same with model[currentIndex]

    TypeError: Result of expression 'model[currentIndex]' [undefined] is not an object.

  7. #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: How to get data from TableView - QML Desktop Components

    Is model a "ListModel" or some other kind of model?
    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.


  8. #7
    Join Date
    Dec 2011
    Posts
    21
    Thanks
    2
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to get data from TableView - QML Desktop Components

    In python implementation of AbstractListModel.
    Of course all data from model appears correctly.

  9. #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: How to get data from TableView - QML Desktop Components

    If it's a QAbstractItemModel then you need to provide your own method for accessing data from the model.

    I suggest an equivalent of the following:
    Qt Code:
    1. QVariantMap Model::get(int idx) const {
    2. QVariantMap map;
    3. foreach(int k, roleNames().keys()) {
    4. map[roleNames().value(k)] = data(index(idx, 0), k);
    5. }
    6. return map;
    7. }
    To copy to clipboard, switch view to plain text mode 
    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.


  10. The following user says thank you to wysota for this useful post:

    travick (23rd January 2013)

  11. #9
    Join Date
    Dec 2011
    Posts
    21
    Thanks
    2
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to get data from TableView - QML Desktop Components

    Thanks a lot, it works!

Similar Threads

  1. QML Desktop Components weird Menu ...
    By travick in forum Qt Quick
    Replies: 9
    Last Post: 23rd December 2012, 22:09
  2. Using QML Components for the Desktop with PySide
    By hansotronic in forum Qt Quick
    Replies: 2
    Last Post: 30th October 2012, 00:49
  3. Replies: 3
    Last Post: 13th July 2012, 09:39
  4. QtCreator and Desktop Components
    By Splashy in forum Qt Quick
    Replies: 6
    Last Post: 24th March 2012, 00:43
  5. Replies: 2
    Last Post: 16th March 2012, 14:22

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.