Tim
Tim

Reputation: 667

QListWidget not removing items on screen

Im using QListWidget to show names as a type of dropdown when someone types entries in another QLineEdit field. It hits the database and shows all possibilities to choose from. As they type, the list changes, so I want it to delete all entries and re-fill the QListWidget.

When I call the following code, it indeed empties the QListWidget list, but the screen elements are still visible. Can someone help me figure out why they arent being removed from the display? Im using Qt 4.8.4. Thank you!

void myClass::clearListWidget()
{
    QListWidget * lw = m_ui->db_listWidget;

    while(lw->selectedItems().size())
    {
         delete lw->takeItem(0);
    }
    lw->update();
    lw->repaint();
    qApp->processEvents();
}

Upvotes: 0

Views: 383

Answers (1)

Maxim Makhun
Maxim Makhun

Reputation: 2231

Use slot void QListWidget::clear() to clear all contents. QListWidget documentation is here.

Upvotes: 3

Related Questions