Results 1 to 7 of 7

Thread: catch Left most down element in QTreeView

  1. #1
    Join Date
    Jun 2015
    Location
    India
    Posts
    185
    Thanks
    8
    Thanked 14 Times in 14 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default catch Left most down element in QTreeView

    Hi, My previous post related to this question is here, , I reported bug also : http://www.qtcentre.org/threads/6391...ted?highlight= & Bug Report: https://bugreports.qt.io/browse/QTBUG-48725

    Again : I wanted to load data with lazy population for my tree view, But lazy population (canFetchMore() & fetchMore()) doesn't works as expected, this functions are not getting called during scroll down for non root Items. (For non root items this functions are getting called only when collapse & expand not during scroll down). So some how I am finding a way to load data incrementally for non root items also.

    So during a scroll I wanted to find left most last (down) tree item, with which i will find whether it has more children or not & then based this I wanted to add children (If it expanded because lazy population works for root item & top level items gets added on fly).

    But I really don't have an idea How to find last element while scroll, I tried connecting to scrollBar move signal & them in a slot I tried to find last element something like
    Qt Code:
    1. ItemAt(viewPort()->rect()->bottomLeft())
    To copy to clipboard, switch view to plain text mode 
    , But with this approach Items are getting skipped (Not able to find last items If scroll little fast).

    Then I tried doing same thing in data() function (I found this is the place where no items get skipped even If I scroll fast), here I am checking each Item (Not exactly, checking only left most items) how many children It has & based on that I am Loading few more children (Lazy population for child items). (But some how I felt this is not a good way, doing some calculations adding children in data() function).

    Can somebody help me how to find out the leftmost down element when I am scrolling in view port with what ever the speed. OR any other idea how to do lazy population for children also.

    Thanks a lot for reading long post :-)
    Last edited by prasad_N; 12th November 2015 at 20:20. Reason: added more info
    Thanks :-)

  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: catch Left most down element in QTreeView

    Why is speed an issue? Your model can "lag behind" if you scroll too fast but it should work. If the last index you loaded children for is e.g. row 100 and the last visible row is 120 then you need to load children for rows 101-120.
    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
    Jun 2015
    Location
    India
    Posts
    185
    Thanks
    8
    Thanked 14 Times in 14 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: catch Left most down element in QTreeView

    Quote Originally Posted by wysota View Post
    If the last index you loaded children for is e.g. row 100 and the last visible row is 120 then you need to load children for rows 101-120.
    Got the point but, ItemAt(viewPort()->rect()->bottomLeft()) (I put it in the slot connected to vertical scroll bar moved) But it is not able to find the element when i scroll the element too fast, But it is able to find this element when I scroll slowly. I really couldn't get where to put this statement ItemAt(viewPort()->rect()->bottomLeft()) (Or looking for an another way to get the element).
    Thanks :-)

  4. #4
    Join Date
    Jun 2015
    Location
    India
    Posts
    185
    Thanks
    8
    Thanked 14 Times in 14 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: catch Left most down element in QTreeView

    Quote Originally Posted by wysota View Post
    Why is speed an issue? Your model can "lag behind" if you scroll too fast but it should work. If the last index you loaded children for is e.g. row 100 and the last visible row is 120 then you need to load children for rows 101-120.

    misunderstanding might be : I am not talking about top level items they can be load with canFetchMore() & fetchMore(). This functions are not working properly for non top level & root items (Can see my links above).

    The prob is, I have 100 top level items loaded in my view, And now I expanded 1st top level item which as 1000 child's, Now what I did I loaded only 500 child's Now my view has Top level 1st item & its child's (hardly 30 to 40 child's) visible. Now if i scroll my view down My idea is to catch 500th child Of 1st top level Item & add remaining 500 child's but I am not able to find it with ItemAt(viewPort()->rect()->bottomLeft()).
    When I scroll little fast, this function is not able to find that (basically its not able to find all items which are coming from down entry point, skipping some). & I am using this statement in slot connected to vertical scroll bar moved.

    Hopes it clear.
    Thanks :-)

  5. #5
    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: catch Left most down element in QTreeView

    Quote Originally Posted by prasad_N View Post
    Got the point but, ItemAt(viewPort()->rect()->bottomLeft()) (I put it in the slot connected to vertical scroll bar moved) But it is not able to find the element when i scroll the element too fast, But it is able to find this element when I scroll slowly. I really couldn't get where to put this statement ItemAt(viewPort()->rect()->bottomLeft()) (Or looking for an another way to get the element).
    So what does itemAt() return if it "isn't able to find the element"?

    Quote Originally Posted by prasad_N View Post
    misunderstanding might be : I am not talking about top level items they can be load with canFetchMore() & fetchMore(). This functions are not working properly for non top level & root items (Can see my links above).

    The prob is, I have 100 top level items loaded in my view, And now I expanded 1st top level item which as 1000 child's, Now what I did I loaded only 500 child's Now my view has Top level 1st item & its child's (hardly 30 to 40 child's) visible. Now if i scroll my view down My idea is to catch 500th child Of 1st top level Item & add remaining 500 child's but I am not able to find it with ItemAt(viewPort()->rect()->bottomLeft()).
    When I scroll little fast, this function is not able to find that (basically its not able to find all items which are coming from down entry point, skipping some). & I am using this statement in slot connected to vertical scroll bar moved.
    If itemAt() returns top-level index with row = 2 and previously you fetched items with parent set to row = 1 then based on that you can deduce you should fetch those missing items from first top-level 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.


  6. #6
    Join Date
    Jun 2015
    Location
    India
    Posts
    185
    Thanks
    8
    Thanked 14 Times in 14 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: catch Left most down element in QTreeView while scrolling down

    Quote Originally Posted by wysota View Post
    So what does itemAt() return if it "isn't able to find the element"?
    When I scroll down IndexAt() (very sorry It is IndexAt() not ItemAt()) is returning some items randomly (As I scroll down All the items should come into view from down & I thought IndexAt() can recognize all the items, But as I said it is skipping some items & its is happening randomly, there is no particular pattern even).


    Quote Originally Posted by wysota View Post
    If itemAt() returns top-level index with row = 2 and previously you fetched items with parent set to row = 1 then based on that you can deduce you should fetch those missing items from first top-level row.


    I just attached a result to make clear what is the exact problem. tree.PNG


    - In attachement, 20 is child of my 1st top level Item but this has more siblings down which I did not load initially.
    - Now when I scroll down I wanted to find this items (which has data as 20) & find out if its more siblings & add them

    For that I did some thing like this

    Qt Code:
    1. QScrollBar* l_vScroll = verticalScrollBar();
    2. if(l_vScroll)
    3. {
    4. connect(l_vScroll, SIGNAL(valueChanged(int)), this, SLOT(verticallScrollBarMoved(int)), Qt::DirectConnection);
    5. }
    6.  
    7.  
    8. void TreeView::verticallScrollBarMoved(int f_val)
    9. {
    10. QModelIndex index = this->indexAt(this->viewport()->rect().bottomLeft());
    11.  
    12. //Now my assumption is as I scroll down in this function index of last child (which has data 20) should get caught (correct me If i am wrong) & with this index I can add more siblings to it
    13.  
    14. //But here I am not able to get all the indexes which are coming from down when I am scrolling
    15. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by prasad_N; 24th November 2015 at 08:36. Reason: change title to more clear
    Thanks :-)

  7. #7
    Join Date
    Jun 2015
    Location
    India
    Posts
    185
    Thanks
    8
    Thanked 14 Times in 14 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: catch Left most down element in QTreeView while scrolling down

    Still looking for the solution....
    Thanks :-)

Similar Threads

  1. Not Able to put breakpoint inside catch() of try,catch block
    By vinothrajendran in forum Qt Programming
    Replies: 0
    Last Post: 15th July 2015, 09:22
  2. Always show QTreeview branches in the far left column
    By Nightfox in forum Qt Programming
    Replies: 15
    Last Post: 10th September 2010, 01:15
  3. How to catch QTreeView column moved by user?
    By liversedge in forum Qt Programming
    Replies: 1
    Last Post: 26th July 2010, 22:07
  4. QTreeView/QHeaderView : resize handle on the left
    By Jeremy in forum Qt Programming
    Replies: 3
    Last Post: 14th May 2009, 23:43
  5. how to catch Shift + Left arrow? [Soved]
    By thomaspu in forum Qt Programming
    Replies: 2
    Last Post: 29th December 2007, 00:16

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.