[SOLVED] QListView: slot connected to clicked(const QModelIndex &) never gets called for the first item
-
Hi,
I have a custom widget in my QListView. The strange part is that the slot connected to the clicked() signal never gets called for the first item .
My Delegate looks like this:
@Characters_view_delegate::Characters_view_delegate(QWidget *parent)
: QItemDelegate(parent)
, m_item_widget(new Characters_details_widget(parent))
{
}@Characters_details_widget is my custom widget.
Strange thing is if i remove the parent in "Characters_details_widget" like:
@Characters_view_delegate::Characters_view_delegate(QWidget *parent)
: QItemDelegate(parent)
, m_item_widget(new Characters_details_widget())
{
}@My slots gets called for the first item.
Please let me know what is going wrong here.
Thanks :)
-
all I can think about is that is that it doesn't have a parent when firstly constructed and it may be possible to be constructed with the default parent witch is 0. have you tried to debug it line by line to see how the values are changing? try to set up a breaking point and see for yourself what are the values there on first call. then on the second call it may have a parent and is working fine.
-
I figured out the problem.
since my custom widget is defined in the constructor, and I also use it in my delegate paint() to paint it as per the number of items, this widget constructed in the constructor overlaps what the painter paints and thus its not working for the first item.
-
ok now that you have figured out what was wrong can you please mark this topic as [SOLVED] for other to know that. just edit your main post title