AaronMK
24th January 2008, 17:34
I am using QStandardItem (http://doc.trolltech.com/latest/qstandarditem.html) and QStandardModel (http://doc.trolltech.com/latest/qstandardmodel.html) for my data model. I like this much better than the base QAbstractItemView (http://doc.trolltech.com/latest/qabstractitemview.html) because of the Item class that I can use to treat clumps of data as a single object, but I can't figure out how to get any data into columns other than the root column on the first row.
Example Code:
class QMyModel : public QStandardItemModel
{
Q_OBJECT
public:
QMyModel(QObject *parent) : QStandardItemModel(parent) {};
virtual ~QMyModel();
enum Columns
{
COLUMN_NAME,
COLUMN_CUSTOM,
NUM_COLUMNS
};
};
class QMyItem : public QStandardItem
{
QMyItem(QString Name, QString Description, QString First, QString Second)
: QStandardItem()
{
setData(Name, Qt::DisplayRole);
// TODO: Put Description beside Name and make editable in TreeView.
setChild(0, QMyModel::COLUMN_NAME, "First:");
setChild(0, QMyModel::COLUMN_CUSTOM, First);
setChild(1, QMyModel::COLUMN_NAME, "Second:");
setChild(1, QMyModel::COLUMN_CUSTOM, Second);
}
}
This results in the following for the QTreeView (http://doc.trolltech.com/latest/qtreeview.html) with QMyItem("Item Name", "A Simple Item", "String 1", "String 2"):
+ Item Name
- - First: | String 1
- - Second: | String 2
How do I get it to look like this:
+ Item Name | A Simple Item
- - First: | String 1
- - Second: | String 2
And is there a way to do it within the QStandardItem, instead of having to go back to the parent view?
Thank you for your assistance.
Example Code:
class QMyModel : public QStandardItemModel
{
Q_OBJECT
public:
QMyModel(QObject *parent) : QStandardItemModel(parent) {};
virtual ~QMyModel();
enum Columns
{
COLUMN_NAME,
COLUMN_CUSTOM,
NUM_COLUMNS
};
};
class QMyItem : public QStandardItem
{
QMyItem(QString Name, QString Description, QString First, QString Second)
: QStandardItem()
{
setData(Name, Qt::DisplayRole);
// TODO: Put Description beside Name and make editable in TreeView.
setChild(0, QMyModel::COLUMN_NAME, "First:");
setChild(0, QMyModel::COLUMN_CUSTOM, First);
setChild(1, QMyModel::COLUMN_NAME, "Second:");
setChild(1, QMyModel::COLUMN_CUSTOM, Second);
}
}
This results in the following for the QTreeView (http://doc.trolltech.com/latest/qtreeview.html) with QMyItem("Item Name", "A Simple Item", "String 1", "String 2"):
+ Item Name
- - First: | String 1
- - Second: | String 2
How do I get it to look like this:
+ Item Name | A Simple Item
- - First: | String 1
- - Second: | String 2
And is there a way to do it within the QStandardItem, instead of having to go back to the parent view?
Thank you for your assistance.