Custum widget at QListWidget [SOLVED]
-
Hi there,
I try to add a custom widget to a QListWidget. The widget I want to add is called "NoticeListWidget" and looks like this:
!http://s14.directupload.net/images/140627/q4k8hy4o.jpg(ListWidget)!
In my mainwindow class I try to add the widget to a QListWidget with the following code:@
if(!noticeMap.empty())
{
QUuid id;
QString title;
QString content;
QString creationDate;
Notice notice;QMap<QUuid, Notice>::iterator i = noticeMap.begin(); while(i != noticeMap.end()) { notice = i.value(); id = notice.GetID(); title = notice.GetName(); content = notice.GetComment(); creationDate = this->dateToString(notice.GetCreationDate()); NoticeListWidget *listItem = new NoticeListWidget(this, id, title, content, creationDate); QListWidgetItem *item = new QListWidgetItem(); _ui->listOfNotices->addItem(item); _ui->listOfNotices->setItemWidget(item, listItem); ++i; } }
@
I added one item and after the call above the widget is added but like you can see, it's empty.
!http://s14.directupload.net/images/140627/pzzud5a8.jpg(ListWidget)!How do I display my custom widget?
Any help here appreciated.
Thanks
basteln--
Ot version 5.3.0 -
Why you are creating NoticeListWidget *listItem = new NoticeListWidget(this, id, title, content, creationDate); every time in the loop ?
Where is your QListWidget ?
What is _ui->listOfNotices ? Is it QListWidget ?
-
I create a new NoticeListWidget every time, because I want to add more than one item. Later my list should look like this for example:
!http://i47.tinypic.com/nwnekw.jpg(blubb)!
Is there a better way to realize this?
yes, "_ui->listOfNotices" is my QListWidget.
-
Try to add the some size hint like this.
Item->setSizeHint(QSize(200,50));Another option is to write custom delegate for this.
-
nice, the setSizeHint did it.
Thank you a lot!
-
Put the case into solved state. Njoy