How to show two icon in QTreeView
Hello
I am developing an application using Christophe Dumez's blog cdumez http://blogspot.in/2010/11/how-to-us...del-in-qml.htm
Then i am showing my items using QTreeView.
In tree model it take only one icon.
Now i want to show two icons (One on left side of text & other on right side of text) in same row.
so how can i do that.
Can any one suggest me(any example) for that
Re: How to show two icon in QTreeView
Maybe could you provide a piece of your code?
Re: How to show two icon in QTreeView
My model is custom, which is an abstract model. I have learned about Item delegate & try to find example code to display tow icons in a row but not successful. I found example about custom delegate e.g star delegate(http://qt-project.org/doc/qt-4.8/ite...rdelegate.html) but nothing for TreeView. I want to only display two icons in a row which display when my treeview display. But still i don't have any idea how to do that, so thats why i can't provide any code?
Re: How to show two icon in QTreeView
QTreeView uses the same delegates as other view classes. You can use exactly the same approach. I have no idea what it has to do with the QML-related block post you linked to in your opening post.
Re: How to show two icon in QTreeView
Hi,
i am using QItemDelegates paint method for custom delegate. My code is as following
.h file
Code:
#include <QItemDelegate>
#include <QModelIndex>
#include <QObject>
#include <QSize>
#include <QSpinBox>
{
Q_OBJECT
public:
TreeViewItemDelegate
(QObject *parent
= 0);
};
.cpp file
Code:
TreeViewItemDelegate
::TreeViewItemDelegate(QObject *parent
){
}
void TreeViewItemDelegate
::paint( QPainter * painter,
{
QString contactURI
= index.
model()->data
(index, Qt
::DisplayRole).
toString();
QIcon icon
= qvariant_cast<QIcon>
(index.
model()->data
(index, Qt
::DecorationRole));
QIcon icon2
= qvariant_cast<QIcon>
(index.
model()->data
(index, Qt
::UserRole+5));
QPixmap iconPixmap
= icon.
pixmap(option.
decorationSize);
QPixmap iconPixmap2
= icon2.
pixmap(option.
decorationSize);
myoption.displayAlignment = Qt::AlignCenter;
myoption2.decorationAlignment = Qt::AlignLeft;
myoption3.decorationAlignment = Qt::AlignRight;
drawBackground(painter, myoption, index);
drawDecoration(painter, myoption, myoption2.rect, iconPixmap);
drawDisplay(painter,myoption, myoption.rect, contactURI);
drawDecoration(painter, myoption, myoption3.rect, iconPixmap2);
drawFocus(painter, myoption,myoption.rect);
}
There is on problem that only one icon is displaying. I know i am doing something wrong, so can anyone help me to correct this code to display both icon??
Re: How to show two icon in QTreeView
Don't call drawDecoration() for the additional icon. Instead use QPainter::drawPixmap() directly.
Re: How to show two icon in QTreeView
i added two more lines in my cpp file
Code:
painter->drawPixmap(rect,iconPixmap);
but it is not working..
Re: How to show two icon in QTreeView
It doesn't even compile. And if it did, the rect probably doesn't make sense anyway.