Results 1 to 8 of 8

Thread: QTreeView problem scrolling to end.

  1. #1
    Join Date
    Jan 2006
    Posts
    132
    Thanked 16 Times in 16 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Question QTableView problem scrolling to end.

    [Qt 4.1.0, windows]

    In a QTableView I want to add a new row at the end, scroll to it and open the first column for editing. However it only scrolls down to the second last row (the one that was the last one before the new row was added). The new row remains outside of visibility. I have also tried with scrollToBottom(), but exactly the same.

    Qt Code:
    1. if (act == iActionAddValue) {
    2. ALocalvalueModel* model = (ALocalvalueModel*)iTable->model();
    3. model->insertRow(model->rowCount());
    4. iTable->resizeRowsToContents();
    5. iTable->clearSelection();
    6. QModelIndex index(model->index(model->rowCount()-1,0));
    7. iTable->scrollTo(index);
    8. iTable->edit(index);
    9. } // if
    To copy to clipboard, switch view to plain text mode 
    Last edited by seneca; 24th January 2006 at 12:26.

  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: QTreeView problem scrolling to end.

    Did you try using different scroll hints? And does a proper row get edited?

  3. #3
    Join Date
    Jan 2006
    Posts
    132
    Thanked 16 Times in 16 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTreeView problem scrolling to end.

    When there is enough space in the visible table to add another row everything works as expected: the new row gets added and the first column of it is opened for editing as expected.

    I have not yet looked at scroll hints, only tried scrollTo(index) and scrollToBottom(). So basicly it should default to QAbstractItemView::EnsureVisible, but I will give the others a try.

    Could it be related to the fact that I allways need to do resizeRowsToContents() because by default the new rows are allways to high?

    Edit:
    I tried all availabe scroll hints now without success. It allways scrolls one row to few to show the last row, whatever hint is used.

    Next I tried to add 2 rows at a time, and to my surprise the scroll halts so that non of them is shown. I now suspect that there needs to be a function call or something as an idle event loop between adding the row(s) and scrolling.
    Last edited by seneca; 24th January 2006 at 15:27.

  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: QTreeView problem scrolling to end.

    You can try setting a timer with timeout set to 0 and insert those scroll and edit commands there. The timer will go off as soon as the event queue gains control over the application.

  5. #5
    Join Date
    Jan 2006
    Posts
    132
    Thanked 16 Times in 16 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTreeView problem scrolling to end.

    Yes, the timer did the trick. This is how it is working now, including the new slot:

    Qt Code:
    1. ...
    2. if (act == iActionAddValue) {
    3. iTable->clearSelection();
    4. QAbstractItemModel* model = iTable->model();
    5. model->insertRow(model->rowCount());
    6. iTable->resizeRowsToContents();
    7. QTimer::singleShot(0, this, SLOT(scrollAndEdit()));
    8. } // if
    9. ...
    10.  
    11. void AMainWindow::scrollAndEdit() // declared as private slot
    12. {
    13. QAbstractItemModel* model = iTable->model();
    14. QModelIndex index(model->index(model->rowCount()-1,0));
    15. iTable->scrollTo(index);
    16. iTable->edit(index);
    17. } // scrollAndEdit
    To copy to clipboard, switch view to plain text mode 

    Well surely not an elegant solution, but at least a workaround. I wonder if there is a more convenient way to let the pending events be consumed between two statements.

  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: QTreeView problem scrolling to end.

    I think you can post it to Trolltech as a bug.

  7. #7
    Join Date
    Jan 2006
    Posts
    132
    Thanked 16 Times in 16 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTreeView problem scrolling to end.

    Yes it is considered a bug by TT and should get fixed. An easier workaround for the problem is to issue QApplication::sendPostedEvents() immediately before the call to scrollTo().

  8. #8
    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: QTreeView problem scrolling to end.

    Ran into same issue & came across that this bug has not fixed in Qt4.x from https://bugreports.qt.io/browse/QTBUG-9326.
    Is there a work around for this, singleShot timer did not work in my case, I tried signal slot also did not work
    Any suggestions from experts ??


    I have some modelindex (ex: l_ modelIndex);

    Qt Code:
    1. scrollTo(l_modelIndex, , QAbstractItemView::PositionAtTop);
    2. //Is not getting scroll to this index, I tried printing data just to make sure that index is proper or not , qDebug() << l_modelIndex.data() is printing expected data to where it needs to move.
    To copy to clipboard, switch view to plain text mode 
    Last edited by prasad_N; 22nd December 2015 at 13:20. Reason: updated contents
    Thanks :-)

Similar Threads

  1. QTreeView and QDirmodel 's problem?
    By ggs0110 in forum Qt Programming
    Replies: 8
    Last Post: 31st July 2012, 13:11
  2. QGraphicsView scrolling problem with 4.3.0
    By hb in forum Qt Programming
    Replies: 8
    Last Post: 30th August 2007, 23:18
  3. Problem with index in a QTreeView
    By hubert_p in forum Qt Programming
    Replies: 4
    Last Post: 22nd October 2006, 16:54
  4. Replies: 2
    Last Post: 8th October 2006, 21:14
  5. Selection problem in QTreeView
    By Valheru in forum Qt Programming
    Replies: 3
    Last Post: 7th October 2006, 17:02

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.