![]() |
Two labeled Qlistview
Is there any possibility to make the QListView to a two labeled list like the QValueButton?
|
Re: Two labeled Qlistview
Do you mean like having two rows on a QListItem?
If yes then use a ListDelegate. Do a google search on it and you'll find examples. I have used a ListDelegate on my application Shortcut Stash. Check it out and if it is what you need I can share some source code with you. |
Re: Two labeled Qlistview
Yes that is exactly what I need! It would be wonderfull if you could share some code. Thanks!
|
Re: Two labeled Qlistview
1 Attachment(s)
Ok, here goes.
Attached is the ListDelegate stuff and the code to add item to QListWidget is as follows: Code:
ui->listWidget->setItemDelegate(newListDelegate(ui->listWidget)); QListWidgetItem*item=newQListWidgetItem(); QIconappIcon=QIcon::fromTheme(icon,QIcon(":/images/general_applications.png")); item->setData(Qt::DecorationRole,appIcon); item->setData(Qt::DisplayRole,realName); item->setData(Qt::UserRole,QVariant(exec)); item->setData(Qt::UserRole+1,QVariant(comment.trimmed())); item->setData(Qt::WhatsThisRole,QVariant(2)); ui->listWidget->addItem(item); DisplayRole is the main text UserRole is the data of the item UserRole + 1 is the description text and WhatsThisRole is just some additional data for the item. You can tweak those on the Delegate itself or use whatever roles suits you best. Hope it helps, and if you ever find out how to resize the icon on the DecorationRole, I would really appreciate if you tell me how you did it, cause I am currently having problems with scalable icons on the QListWidget... :( |
Re: Two labeled Qlistview
Quote:
The pixmap is scaled to fit the rectangle, if both the pixmap and rectangle size disagree. |
Re: Two labeled Qlistview
Cheers, I actually figured it out after I posted this.
I used the method in painter to set the icon size and it's working fine. |
Re: Two labeled Qlistview
I got almost everything to work by now, it is just a small but serious problem left.
My program is designed so that on the mainwindow I have two different windows wich should have a listdelegate listview and one of these two should have one too. The problem that when I include the header file it tells me it have already been defined and points on "class ListDelegate : public QAbstractItemDelegate" and tell me previous definition was at the row below wich is just a "{". I can remember I had a problem before quite like this and then it was something with the instances got into a fight about who was the parent and the problem was called something with circular. As I can not remember what it was its to hard to find out :) Any help? Yours, |
Re: Two labeled Qlistview
I'm no C++ expert and without having your code it's really hard to say what's wrong.
I bet u have already googled a lot on this issue, but could this help? Especially this part: "Circular Dependencies vs bidirectional relationships Whenever one file #includes another, there is a strong dependency created between the files. When a dependency like this exists between header files, it can not be bidirectional: the preprocessor is unable to cope with a circular dependency between qheader files, where each one #includes the other. One of the #include statements must be replaced by a forward class declaration. Forward declarations help remove circular dependencies between classes, and in the process, enable bidirectional relationships to exist between them." Are u by any chance including the Delegate twice in two different classes? |
Re: Two labeled Qlistview
Quote:
But if you have it like this way there is a problem: file1.h: Code:
#include "file2.h" Code:
#include "file1.h" |
Re: Two labeled Qlistview
Quote:
If we were talking about java then I could've explained it right. |
All times are GMT. The time now is 15:07. |
vBulletin® Version 3.8.8