I have a text and an icon.
I want to display the text in the left side of the cell and icon to the extreme right of the cell.
How can I do this?
The code I have included is as follows
model = new ItemModel(5, 3, this);
QPixmap arrowIcon
(":/arrowBig.png");
int i=0;
for (QStringList::iterator it
= rowName.
begin(); it
!= rowName.
end();
++it
) {
qDebug()<<current;
model->setData(index,arrowIcon,Qt::DecorationRole);
model->setData(index,current);
}
model = new ItemModel(5, 3, this);
QPixmap arrowIcon(":/arrowBig.png");
int i=0;
for (QStringList::iterator it= rowName.begin(); it != rowName.end(); ++it)
{
QModelIndex index = model->index(i++,columnNameNum,QModelIndex());
QString current = *it;
qDebug()<<current;
model->setData(index,arrowIcon,Qt::DecorationRole);
model->setData(index,current);
}
To copy to clipboard, switch view to plain text mode
{
public:
ItemModel
(int rows,
int columns,
QObject *parent
= 0) :
{}
{
if (role == Qt::TextAlignmentRole) {
return Qt::AlignLeft; // <- Make alignment look different, i.e.
// <- text at the bottom.
}
else {
}
}
};
class ItemModel : public QStandardItemModel
{
public:
ItemModel(int rows, int columns, QObject *parent = 0)
:
QStandardItemModel(rows, columns, parent)
{}
QVariant data(const QModelIndex &index, int role) const
{
if (role == Qt::TextAlignmentRole) {
return Qt::AlignLeft; // <- Make alignment look different, i.e.
// <- text at the bottom.
}
else {
return QStandardItemModel::data(index, role);
}
}
};
To copy to clipboard, switch view to plain text mode
thanks in advance
Bookmarks