Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>Using a Qt built-in item model</strong></p> <p>If you are using e.g. <code>QFileSystemModel</code> you have to inherit from it and override the <code>data()</code> behaviour:</p> <pre><code>class MyFileSystemModel : public QFileSystemModel { public: QVariant data(const QModelIndex &amp; index, int role = Qt::DisplayRole) const { if (role == Qt::TextAlignmentRole) return Qt::AlignTop; //maybe different result depending on column/row else return QFileSystemModel::data(index, role); } </code></pre> <p>and then use that class instead.</p> <p><strong>Using own item model</strong></p> <p>If you implemented your own item model all you have to do is handle <code>Qt::TextAlignmentRole</code> in <code>data()</code>:</p> <pre><code>QVariant MyTreeModel::data (const QModelIndex &amp;index, int role) const { if (role == Qt::TextAlignmentRole) return Qt::AlignTop; //maybe different result depending on column/row //handle other roles return QVariant(); } </code></pre> <p>The tree view should now automatically align the items to the top.</p> <p>If you want to customize the appearance even further, <a href="http://qt-project.org/doc/qt-4.8/qt.html#ItemDataRole-enum" rel="nofollow">here</a> are the roles that are used by <code>QTreeView</code>. For more customization I think you have to implement your own <code>QTreeView</code> subclass.</p> <p><strong>Using QStandardItemModel</strong></p> <p>If you did not implement your own model but used <code>QStandardItemModel</code> you have to call <code>setTextAlignment(Qt::Alignment alignment)</code> with <code>Qt::AlignTop</code> on your standard items before adding them to the model.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload