I have a QListWidget where I want to add a bunch of items with a custom widget:

Qt Code:
  1. #include <QApplication>
  2. #include <QListWidget>
  3. #include <QListWidgetItem>
  4. #include <QPushButton>
  6. int main(int argc, char** argv)
  7. {
  8. QApplication* app = new QApplication(argc, argv);
  9. QListWidget* listWidget = new QListWidget();
  10. item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
  11. item->setCheckState(Qt::Unchecked);
  12. listWidget->addItem(item);
  13. QWidget* widget = new QPushButton("Example widget");
  14. item->setSizeHint(widget->sizeHint());
  15. listWidget->setItemWidget(item, widget);
  17. listWidget->show();
  18. app->exec();
  19. }
To copy to clipboard, switch view to plain text mode 

The problem is that I can not use the checkbox that appears in the listwidget next to the added widget. It looks completely normal, but nothing happens when I click on it. If I remove the line with setSizeHint it works correctly, but then my widget is no longer visible. How do I solve this problem?