I have created a delegate class "CheckedListBoxDelegate : public QStyledItemDelegate" and I am creating a QListWidget in the paint method to be drawn for a column in my QTableView. The scrollbars that I am talking about are the scrollbars on the QListWidget. The up/down arrows on the QListWidget's scrollbars are being drawn but do not allow the widget to scroll.
void CheckedListBoxDelegate
::paint(QPainter* painter,
const QStyleOptionViewItem
& option,
const QModelIndex
& index
) const {
list_widget.resize(option.rect.width(),option.rect.height());
{
item->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsSelectable | Qt::ItemIsEnabled);
if(list.contains(str))
{
item->setCheckState(Qt::CheckState::Checked);
}
else
{
item->setCheckState(Qt::CheckState::Unchecked);
}
list_widget.addItem(item);
}
painter->save();
painter->setClipRect(option.rect);
painter->translate(option.rect.topLeft());
list_widget.render(painter);
painter->restore();
}
void CheckedListBoxDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
{
QStringList list = index.data().toStringList();
QListWidget list_widget;
list_widget.resize(option.rect.width(),option.rect.height());
foreach(QString str, listBoxData)
{
QListWidgetItem *item = new QListWidgetItem(str);
item->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsSelectable | Qt::ItemIsEnabled);
if(list.contains(str))
{
item->setCheckState(Qt::CheckState::Checked);
}
else
{
item->setCheckState(Qt::CheckState::Unchecked);
}
list_widget.addItem(item);
}
painter->save();
painter->setClipRect(option.rect);
painter->translate(option.rect.topLeft());
list_widget.render(painter);
painter->restore();
}
To copy to clipboard, switch view to plain text mode
Bookmarks