Results 1 to 3 of 3

Thread: subclass qStyledItemDelegate signal itemActivated not triggered

  1. #1
    Join Date
    Jan 2006
    Posts
    73
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    16
    Thanked 3 Times in 3 Posts

    Default subclass qStyledItemDelegate signal itemActivated not triggered

    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
    Qt Code:
    1. events_widget = new QListWidget;
    2. events_widget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    3. events_widget->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    4. events_widget->setItemDelegate(new event_delegate);
    5. connect(events_widget, SIGNAL(itemActivated(QListWidgetItem*)),
    6. this, SLOT(event_refresh(QListWidgetItem*)))
    To copy to clipboard, switch view to plain text mode 
    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:
    Qt Code:
    1. event_delegate::event_delegate(QObject *parent) :
    2. QStyledItemDelegate(parent)
    3. {
    4. }
    5. void event_delegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
    6. {
    7. if (qVariantCanConvert<EventOne>(index.data()))
    8. {
    9. EventOne eventOne = qVariantValue<EventOne>(index.data());
    10. if (option.state & QStyle::State_Selected)
    11. {
    12. painter->fillRect(option.rect, option.palette.highlight());
    13. }
    14. eventOne.paint(painter, option.rect, option.palette);
    15. }
    16. else
    17. {
    18. QStyledItemDelegate::paint(painter, option, index);
    19. }
    20. }
    21. QSize event_delegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
    22. {
    23. if (qVariantCanConvert<EventOne>(index.data()))
    24. {
    25. EventOne eventOne = qVariantValue<EventOne>(index.data());
    26. return eventOne.sizeHint();
    27. }
    28. else
    29. {
    30. return QStyledItemDelegate::sizeHint(option, index);
    31. }
    32. }
    To copy to clipboard, switch view to plain text mode 
    the class EventOne is like this:
    Qt Code:
    1. EventOne::EventOne(QString description_, QString date_, QString capacity_)
    2. : description(description_), date(date_), capacity(capacity_)
    3. {
    4. }
    5. void EventOne::paint(QPainter *painter, const QRect &rect, const QPalette &palette) const
    6. {
    7. //qDebug() << "|" << rect << "|";
    8. painter->save();
    9. painter->setRenderHint(QPainter::Antialiasing, true);
    10. painter->drawText(10,50+30*rect.y(), date);
    11. painter->restore();
    12. }
    13. QSize EventOne::sizeHint() const
    14. {
    15. return QSize(1,1);
    16. }
    To copy to clipboard, switch view to plain text mode 
    Could it be that the events are stopped by the new delegate. Is there something I should add somewhere?

    Thanks!

  2. #2
    Join Date
    Jan 2006
    Posts
    73
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    16
    Thanked 3 Times in 3 Posts

    Default Re: subclass qStyledItemDelegate signal itemActivated not triggered

    Hi,

    The problem is in the sizeHint() function of my EventOne class.
    By returning QSize(1), I think I am making the area able to capture the itemActivated way too small; and that is why the signal is not triggered. Now, the issue is how to write that function.

  3. #3
    Join Date
    Jan 2006
    Posts
    73
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    16
    Thanked 3 Times in 3 Posts

    Default Re: subclass qStyledItemDelegate signal itemActivated not triggered

    Hello,
    Maybe someone could help me clarifying what the sizeHint function does and how it is related to the view's signals.
    My implementation of EventOne now looks like this:
    Qt Code:
    1. EventOne::EventOne(QString description_, QString date_, QString capacity_)
    2. : description(description_), date(date_), capacity(capacity_)
    3. {
    4. }
    5. void EventOne::paint(QPainter *painter, const QRect &rect, const QPalette &palette, const QModelIndex& index) const
    6. {
    7. painter->save();
    8. painter->setRenderHint(QPainter::Antialiasing, true);
    9. painter->drawText(0,70 + rect.y()* 35,date);
    10. //painter->translate(1.0, 0.0);
    11. painter->restore();
    12. }
    13. QSize EventOne::sizeHint(const QRect& rect, const QModelIndex &index) const
    14. {
    15. return QSize(1,1);
    16. //return QSize(rect.width(),30);
    17. //return QSize(300,30);
    18. }
    To copy to clipboard, switch view to plain text mode 
    like this I can see the rows of data. But, those rows cannot be activated. The "activated rows are actually stacked at the top of the widget. if I change the sizeHint function to increase the area, I don't see the rows properly but I can activate a row and click it and get to the next screen.
    How can I have it work?

    Thanks!

Similar Threads

  1. Paint selection in QStyledItemDelegate's subclass
    By woodtluk in forum Qt Programming
    Replies: 2
    Last Post: 26th April 2012, 15:51
  2. QUdpSocket readyRead() signal not triggered
    By deionut in forum Newbie
    Replies: 2
    Last Post: 26th October 2010, 18:19
  3. Replies: 0
    Last Post: 24th May 2010, 08:11
  4. Replies: 1
    Last Post: 11th April 2010, 14:21
  5. Replies: 1
    Last Post: 29th February 2008, 23:04

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.