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