maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Development (https://talk.maemo.org/forumdisplay.php?f=13)
-   -   Two labeled Qlistview (https://talk.maemo.org/showthread.php?t=65574)

Lullen 2010-11-13 17:13

Two labeled Qlistview
 
Is there any possibility to make the QListView to a two labeled list like the QValueButton?

rooster13 2010-11-13 19:32

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.

Lullen 2010-11-14 20:44

Re: Two labeled Qlistview
 
Yes that is exactly what I need! It would be wonderfull if you could share some code. Thanks!

rooster13 2010-11-14 21:22

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);
DecorationRole is the icon
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... :(

Diph 2010-11-15 07:21

Re: Two labeled Qlistview
 
Quote:

Originally Posted by rooster13 (Post 873408)
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... :(

You draw the icon with QIcon:: paint method. Maybe you should use QPainter::drawPixmap instead.

The pixmap is scaled to fit the rectangle, if both the pixmap and rectangle size disagree.

rooster13 2010-11-15 11:51

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.

Lullen 2010-11-15 19:21

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,

rooster13 2010-11-15 19:50

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?

Diph 2010-11-15 20:22

Re: Two labeled Qlistview
 
Quote:

Originally Posted by rooster13 (Post 874366)
IAre u by any chance including the Delegate twice in two different classes?

That shouldn't be a problem.

But if you have it like this way there is a problem:

file1.h:
Code:

#include "file2.h"
file2.h
Code:

#include "file1.h"
Use forward declaration like rooster13 said.

rooster13 2010-11-15 20:36

Re: Two labeled Qlistview
 
Quote:

Originally Posted by Diph (Post 874384)
But if you have it like this way there is a problem:

file1.h:
Code:

#include "file2.h"
file2.h
Code:

#include "file1.h"
Use forward declaration like rooster13 said.

Thx, that's what I was actually trying to say :)
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