Custom QWidget with more than 2 controls including buttons inside QListView
I want to put a QWidget inside QListView, tried with setItemWidget and not worked, but now I'm using QListView in a new project and need to do this.
It's a download list.
How can I do this ?
Re: Custom QWidget with more than 2 controls including buttons inside QListView
QListView is a different thing from QListWidget which i assume you want to use because this one has setItemWidget.
Re: Custom QWidget with more than 2 controls including buttons inside QListView
I've used the Widget before, but not worked, now I've started another project using QListView and want to do this using it. I'm trying to do this with delegates.
How I can calculate the sizes ?
I'm using this code but I don't think it's the best way:
Code:
void DownloadItemDelegate::paint(
const QStyleOptionViewItem& option,
const QModelIndex& index) const
{
painter->drawText(option.rect.x() + 2, option.rect.y() + option.fontMetrics.height(), index.data(Qt::DisplayRole).toString());
sop.
state = QStyle::State_Enabled;
sop.rect = option.rect.adjusted(2, option.fontMetrics.boundingRect(index.data(Qt::DisplayRole).toString()).height() + option.fontMetrics.height() / 2, -2, 0);
sop.fontMetrics = option.fontMetrics;
sop.minimum = 0;
sop.maximum = 100;
sop.progress = 50;
sop.orientation = Qt::Horizontal;
sop.textVisible = false;
}
QSize DownloadItemDelegate
::sizeHint(const QStyleOptionViewItem
& option,
const QModelIndex
& index
) const {
if (option.
rect.
width() == 0 || option.
rect.
height() == 0) return QSize();
QSize size
= option.
rect.
size();
size.setHeight(option.fontMetrics.boundingRect(index.data(Qt::DisplayRole).toString()).height());
size.setHeight(size.height() + 20);
qDebug() << size.width() << "x" << size.height();
return size;
}