View Full Version : QListWidget Custom item is not there

6th May 2011, 10:05
I've created a QListWidget, And I also Created a TaskItem.
In Main Window I have a layout. When i add TaskItem to the layout - I can see it. When i Add QListWidget to the layout I can see it. But when i try to add TaskItem to the QListWidget and then show that QListWidget, The TaskItem is not displayed. here is the relevant code:

layout = new QVBoxLayout(this);
item = new TaskItem;
list = new QListWidget;
list->insertItem(0, "asdsa");
list->setItemWidget(list->item(0), item);


If i compile this code, I see the ListWidget with one item "asdsa" inside, when i should see TaskItem...

Added after 27 minutes:

Hm... I'm an idiot :)
I had to set TaskItem's widget size bigger...

Now I have another question:
I created a QScrollArea, in which I placed the QListWidget.
Everything works, but i want the scrollbar to move smooth (right now it jumps from first item to the second if i move the scrollbar)...

Now I found out that the problem is not in QScrollArea, but in the QListWidget itself (i can use QListWidget Without QScrollArea, but it still does not move smooth, but in jumps...

Solved this one also.
Had to use

list->setVerticalScrollMode(QAbstractItemView::ScrollPer Pixel);

Now is the biggest Question: How do i catch a signal, that the button of one TaskItem in the QListWidget has been pressed?

6th May 2011, 13:19
Your widget has to emit this signal by itself. It is not tied to the QListWidget in any way other than that it occupies space meant for a list item.

6th May 2011, 13:24
Ok, but how do u catch the signal from anyone of those TaskItems?