how to avoid leading spaces in qtreeview with qfilesystem model header text?

236 Views Asked by At

I am using QFileSystem Model with QTreeView, and I am able to change the text by sub classing QFileSystem model like this...

QVariant customFileSystemModel::headerData(int section,
                                           Qt::Orientation orientation,
                                           int role) const
{

    switch(role)
    {

    case(Qt::DisplayRole):
    {
        return QString("YourText");
    }

    case(Qt::TextAlignmentRole):
    {
        return Qt::AlignLeading;
    }


    default:{}
    }

    return QFileSystemModel::headerData(section, orientation,role);

}

but I am not able to remove the leading spaces in header text, could any one suggest how to do it.

enter image description here

1

There are 1 best solutions below

0
On

I don't think it can be easily done. This is definitely not within the scope of your model. This is more a question of the selected style. Maybe something can be done with stylesheets. Or you can change the QHeaderView from your QTreeView. In worst case you have to subclass QHeaderView and override how the label is painted. But I don't think you have to go that far.