ejoshva
5th February 2015, 09:51
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)
{
QModelIndex index = model->index(i++,columnNameNum,QModelIndex());
QString current = *it;
qDebug()<<current;
model->setData(index,arrowIcon,Qt::DecorationRole);
model->setData(index,current);
}
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);
}
}
};
thanks in advance
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)
{
QModelIndex index = model->index(i++,columnNameNum,QModelIndex());
QString current = *it;
qDebug()<<current;
model->setData(index,arrowIcon,Qt::DecorationRole);
model->setData(index,current);
}
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);
}
}
};
thanks in advance