Results 1 to 3 of 3

Thread: How to always display latest element in QTableView while model get filled.

  1. #1
    Join Date
    Jan 2008
    Location
    Germany
    Posts
    80
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default How to always display latest element in QTableView while model get filled.

    Hi,

    I would like to know how I can force a QTableView to always display the latest row of it model when I do insert my elements at the end of the model.

    This is how I do insert my elements in the model:

    Qt Code:
    1. bool
    2. CommunicationModel::addFrame(const Can_Frame &frame) {
    3. beginInsertRows(QModelIndex(), m_communication.count(), m_communication.count());
    4. m_communication.append(frame);
    5. endInsertRows();
    6. return true;
    7. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. class CommunicationModel : public QAbstractTableModel
    2. {
    3. Q_OBJECT
    4. public:
    5. static CommunicationModel* instance(QWidget* parent = 0);
    6.  
    7. int rowCount( const QModelIndex &index) const;
    8. int columnCount( const QModelIndex &index) const;
    9.  
    10. QVariant data(const QModelIndex &index, int role) const;
    11. QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
    12. Qt::ItemFlags flags( const QModelIndex& ) const ;
    13. bool insertRows(int position, int rows, const QModelIndex &index=QModelIndex());
    14. bool removeRows(int position, int rows, const QModelIndex &index=QModelIndex());
    15. bool addFrame(const Can_Frame &frame);
    16. void clear();
    17.  
    18. void sort (int column, Qt::SortOrder order = Qt::AscendingOrder );
    19. private:
    20. CommunicationModel(QObject *parent = 0);
    21. QList<Can_Frame> m_communication; // Communication log
    22. };
    To copy to clipboard, switch view to plain text mode 

    When doing this I am seeing a scroll bar appearing as soon as the number of rows in the model is becoming higher than the number of rows that can be displayed on the screen, but the scrollbar remains at the top, becoming smaller while the model get filled. What I would like to have is that the scroll bar of the QTableView is remaining at the bottom while I am filling the model so that I can always see the latest row filled in the model.
    Attached Images Attached Images

  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 always display latest element in QTableView while model get filled.

    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
    Jan 2008
    Location
    Germany
    Posts
    80
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: How to always display latest element in QTableView while model get filled.

    Thank you,

    this worked for me:

    Qt Code:
    1. CommunicationView::CommunicationView( QWidget* parent ) :
    2. PrintableTableView(parent)
    3. {
    4. m_model = CommunicationModel::instance(this);
    5. setModel(m_model);
    6.  
    7. connect(m_model,SIGNAL(rowsInserted(const QModelIndex&, int, int)), this, SLOT(scrollToBottom()) );
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Replies: 2
    Last Post: 7th June 2009, 10:47
  2. How to display selected columns in QTableView widget.
    By kaushal_gaurav in forum Qt Programming
    Replies: 2
    Last Post: 8th August 2008, 08:30

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.