Show Last element in QListView Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of Show Last element in QListView without wasting too much if your time.

The question is published on by Tutorial Guruji team.

It sounds trivial, but I could not find the function to show the last added element in a QListView.

It works with a model

// Create model
model = new QStringListModel(this);

// Make data
QStringList List;
// Populate our model
// Glue model and view together

Elements are added with

void WidgetMessageList::addString(const QString & message)
    if(model->insertRow(model->rowCount())) {
        QModelIndex index = model->index(model->rowCount() - 1, 0);
        model->setData(index, message);        

In this function the shown element should also be the last.



Scrolls the view if necessary to ensure that the item at index is visible. The view will try to position the item according to the given hint.

We are here to answer your question about Show Last element in QListView - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji