jcr
20th October 2010, 01:56
Hello,
I subclassed QStyledItemDelegate and set that to my QListWidget. To my surprise, the connect between signal itemActivated(QListWidgetItem*) and the slot event_refresh(QListWidgetItem*) is broken.
I suspect the issue is with the signal because the connect was working before I added the subclass of QStyledItemDelegate.
Any idea of what the problem might be?
Thanks!
I have
events_widget = new QListWidget;
events_widget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOf f);
events_widget->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff) ;
events_widget->setItemDelegate(new event_delegate);
connect(events_widget, SIGNAL(itemActivated(QListWidgetItem*)),
this, SLOT(event_refresh(QListWidgetItem*)))
but it looks like the itemActivated signal is not triggered any more but it was working before I set the ItemDelegate.
My event_delegate implementation looks like that:
event_delegate::event_delegate(QObject *parent) :
QStyledItemDelegate(parent)
{
}
void event_delegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
if (qVariantCanConvert<EventOne>(index.data()))
{
EventOne eventOne = qVariantValue<EventOne>(index.data());
if (option.state & QStyle::State_Selected)
{
painter->fillRect(option.rect, option.palette.highlight());
}
eventOne.paint(painter, option.rect, option.palette);
}
else
{
QStyledItemDelegate::paint(painter, option, index);
}
}
QSize event_delegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
{
if (qVariantCanConvert<EventOne>(index.data()))
{
EventOne eventOne = qVariantValue<EventOne>(index.data());
return eventOne.sizeHint();
}
else
{
return QStyledItemDelegate::sizeHint(option, index);
}
}
the class EventOne is like this:
EventOne::EventOne(QString description_, QString date_, QString capacity_)
: description(description_), date(date_), capacity(capacity_)
{
}
void EventOne::paint(QPainter *painter, const QRect &rect, const QPalette &palette) const
{
//qDebug() << "|" << rect << "|";
painter->save();
painter->setRenderHint(QPainter::Antialiasing, true);
painter->drawText(10,50+30*rect.y(), date);
painter->restore();
}
QSize EventOne::sizeHint() const
{
return QSize(1,1);
}
Could it be that the events are stopped by the new delegate. Is there something I should add somewhere?
Thanks!
I subclassed QStyledItemDelegate and set that to my QListWidget. To my surprise, the connect between signal itemActivated(QListWidgetItem*) and the slot event_refresh(QListWidgetItem*) is broken.
I suspect the issue is with the signal because the connect was working before I added the subclass of QStyledItemDelegate.
Any idea of what the problem might be?
Thanks!
I have
events_widget = new QListWidget;
events_widget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOf f);
events_widget->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff) ;
events_widget->setItemDelegate(new event_delegate);
connect(events_widget, SIGNAL(itemActivated(QListWidgetItem*)),
this, SLOT(event_refresh(QListWidgetItem*)))
but it looks like the itemActivated signal is not triggered any more but it was working before I set the ItemDelegate.
My event_delegate implementation looks like that:
event_delegate::event_delegate(QObject *parent) :
QStyledItemDelegate(parent)
{
}
void event_delegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
if (qVariantCanConvert<EventOne>(index.data()))
{
EventOne eventOne = qVariantValue<EventOne>(index.data());
if (option.state & QStyle::State_Selected)
{
painter->fillRect(option.rect, option.palette.highlight());
}
eventOne.paint(painter, option.rect, option.palette);
}
else
{
QStyledItemDelegate::paint(painter, option, index);
}
}
QSize event_delegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
{
if (qVariantCanConvert<EventOne>(index.data()))
{
EventOne eventOne = qVariantValue<EventOne>(index.data());
return eventOne.sizeHint();
}
else
{
return QStyledItemDelegate::sizeHint(option, index);
}
}
the class EventOne is like this:
EventOne::EventOne(QString description_, QString date_, QString capacity_)
: description(description_), date(date_), capacity(capacity_)
{
}
void EventOne::paint(QPainter *painter, const QRect &rect, const QPalette &palette) const
{
//qDebug() << "|" << rect << "|";
painter->save();
painter->setRenderHint(QPainter::Antialiasing, true);
painter->drawText(10,50+30*rect.y(), date);
painter->restore();
}
QSize EventOne::sizeHint() const
{
return QSize(1,1);
}
Could it be that the events are stopped by the new delegate. Is there something I should add somewhere?
Thanks!