Hi all,
If I have a QListWidget and I add for example two or more items, then I click to QListWidget to focus (but not by clicking to some item, just click somewhere else in the QListWidget) it, after that if window loses focus and again gains focus, first item of QListWidget is selected, is this a bug or expected behavior?

Qt Code:
  1. #include <QApplication>
  2. #include <QMainWindow>
  3. #include <QListWidget>
  4. #include <QString>
  5. #include <QHBoxLayout>
  6. #include <QLabel>
  7. #include <QLineEdit>
  9. int main(int argc, char **argv) {
  10. QApplication app(argc, argv);
  11. QMainWindow m_window;
  13. QListWidget *m_listWidget = new QListWidget;
  14. QHBoxLayout *m_layout = new QHBoxLayout;
  15. QLineEdit *m_line = new QLineEdit;
  16. QLabel *m_label = new QLabel;
  17. QWidget *m_widget = new QWidget;
  19. QObject::connect(m_listWidget, SIGNAL(currentRowChanged(int)), m_label, SLOT(setNum(int)));
  21. m_listWidget->addItem("One");
  22. m_listWidget->addItem("Two");
  24. m_layout->addWidget(m_line);
  25. m_layout->addWidget(m_label);
  26. m_layout->addWidget(m_listWidget);
  28. m_widget->setLayout(m_layout);
  29. m_window.setCentralWidget(m_widget);
  31. m_window.show();
  32. app.exec();
  33. return 0;
  34. }
To copy to clipboard, switch view to plain text mode 

If you compile it and run, then click on the list widget, but not on some item, then switch to another window and back, now first item is selected and currentRowChanged is emitted. (This represents QLabel next to QLineEdit).

QLineEdit is there only because to avoid focus of QListWidget on start of application.