PDA

View Full Version : QListWidget Delegate in QTableView Column How To Scroll



kbatch
7th October 2011, 14:08
I have created a delegate class for the QListWidget and I have added the delegate to a column of a QTableView. My scrollbars appear in my QListWidget when needed but the scroll does not appear to work. I am somewhat new to using the QTableView and delegates. Is there something, perhaps in the editorevent method that must be implemented to allow scrolling to work? If anyone has an example or can point me to something I would appreciate it.

Thanks in advance!

wysota
7th October 2011, 20:14
What scrollbars do you mean? The one from QTableView? What does a delegate have to do with that?

kbatch
10th October 2011, 12:33
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
{
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();
}

wysota
10th October 2011, 12:51
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.
You are just rendering the looks of a widget so it seems obvious any interaction with it will fail since the widget is not really there.

kbatch
10th October 2011, 13:17
Yes, that has occurred to me. Any suggestions as to how someone may go about doing what I am attempting to do?

wysota
10th October 2011, 13:26
First I would ask for a purpose of doing what you are doing. Whatever it is, I don't think embedding a list widget inside a table view is a good solution. I would probably rather use QTreeView or a different solution.