我一直在阅读一些关于 WordWrap 不适用于 QTreeView 的论坛(如屏幕外显示的文本),但我找不到任何解决此问题的“黑客”。 bookTreeView 被封装在另一个小部件中,这可能是问题所在……或者它只是不受支持?

    bookTreeView->setModel(standardModel);
    bookTreeView->setEditTriggers(QAbstractItemView::NoEditTriggers);
    bookTreeView->setWordWrap(true);
    bookTreeView->sizeHint();
    bookTreeView->setTextElideMode(Qt::ElideNone);
    bookTreeView->setExpandsOnDoubleClick(true);
    bookTreeView->setUniformRowHeights(true);
    bookTreeView->setHeaderHidden(true);
    bookTreeView->setStyleSheet("QTreeView { font-size: 27px; show-decoration-selected: 0; } QTreeView::branch:has-siblings:!adjoins-item { border-image: none; } QTreeView::branch:has-siblings:adjoins-item { border-image: none; } QTreeView::branch:!has-children:!has-siblings:adjoins-item { border-image: none;} QTreeView::branch:has-children:!has-siblings:closed, QTreeView::branch:closed:has-children:has-siblings { border-image: none; image: url(':images/images/right_arrow.png'); } QTreeView::branch:open:has-children:!has-siblings, QTreeView::branch:open:has-children:has-siblings  { border-image: none; image: url(':images/images/down_arrow.png'); } ");

    QVBoxLayout *layout = new QVBoxLayout;
    layout->addWidget(someWidget);
    layout->addWidget(bookTreeView);

    QWidget *page = new QWidget;
    page->setLayout(layout);

    return page;

最佳答案

我只知道 hack - 它是 Tree Item 中的 QLabel。

关于Qt - QTreeView WordWrap 不起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/4371829/

10-10 06:13