Can't change state of checkable QListViewItem with custom widget
I have a QListWidget where I want to add a bunch of items with a custom widget:
Code:
#include <QApplication>
#include <QListWidget>
#include <QListWidgetItem>
#include <QPushButton>
int main(int argc, char** argv)
{
item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
item->setCheckState(Qt::Unchecked);
listWidget->addItem(item);
item->setSizeHint(widget->sizeHint());
listWidget->setItemWidget(item, widget);
listWidget->show();
app->exec();
}
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?