Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt 6.3.1 QFileSystemModel TextAlignmentRole issue
Forum Updated to NodeBB v4.3 + New Features

Qt 6.3.1 QFileSystemModel TextAlignmentRole issue

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 216 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Rory_1
    wrote on last edited by
    #1

    My program subclasses QFileSystemModel to set the alignment for a data in a QTreeView. I have created a minimal program to show the issue. I am using a Mac Studio and the latest MacOS and XCode.

    pro file:

    QT += core gui widgets
    SOURCES += main.cpp
    qnx: target.path = /tmp/$${TARGET}/bin
    else: unix:!android: target.path = /opt/$${TARGET}/bin
    !isEmpty(target.path): INSTALLS += target
    

    main.cpp

    #include <QtWidgets>
    
    class FSModel : public QFileSystemModel
    {
    public:
        FSModel(QWidget *parent = nullptr) {}
        QVariant data(const QModelIndex &index, int role) const {
            if (role == Qt::TextAlignmentRole)
                return static_cast<QVariant>(Qt::AlignRight | Qt::AlignVCenter);
            return QFileSystemModel::data(index, role);
        }
    };
    
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
        QMainWindow mw;
        QTreeView tree;
        FSModel fsModel;
        fsModel.setRootPath(fsModel.myComputer().toString());
        tree.setModel(&fsModel);
        tree.setStyleSheet("QTreeView::item{padding:10px;}");
        tree.setFixedSize(500,60);
        mw.setCentralWidget(&tree);
        mw.show();
        return a.exec();
    }
    

    The line

    return static_cast<QVariant>(Qt::AlignRight | Qt::AlignVCenter);
    

    works when compiled in any prior version of Qt, but combining horizontal and vertical alignments does not work in 6.3.1.

    Result with 6.3.0
    f1cf6577-7f94-4486-9c33-52992b7e3e1e-image.png
    Result with 6.3.1
    4451f7dd-801f-4fc2-8997-3703541abad5-image.png

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      I am surprised it works at all, you should not use static_cast, it's the wrong tool. You should properly create a QVariant for example using the fromValue method.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      R 1 Reply Last reply
      1
      • SGaistS SGaist

        Hi,

        I am surprised it works at all, you should not use static_cast, it's the wrong tool. You should properly create a QVariant for example using the fromValue method.

        R Offline
        R Offline
        Rory_1
        wrote on last edited by
        #3

        @SGaist Thanks!! That did the trick.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved