Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QTreeWidget item border style breaks selection style



  • Hi there. I'm trying to customize a QTreeWidget::item (QT v.6.0.0 msvc2019_64) and set a look for a border.

    Here is the unstyled component without/with selected items. It looks good:

    e6e593db-ca2f-4f5b-90aa-08a8d05e022d-image.png

    But once I put the style to the widget:

    QTreeWidget::item {
    	border-bottom: 1px dotted grey;
    }
    

    Something strange happens. The unselected view of the widget looks as expected, but when I select items, the view gets broken.

    328e7d41-4135-4662-97d6-24b1eff14659-image.png

    What exactly goes wrong is:

    1. Outline color changes to Red.
    2. Background of items loses its default Blue highlight.

    Can anyone point me out, cow could a border style cause that? Did I do something wrong, or that is a QT bug?



  • Bug confirmed (On windows) for Qt 6.0.
    Please try installing Qt 6.1.1 and see if it's already fixed.
    If it's not, open a bug report, you can attach the below as a minimal example:

    #include <QApplication>
    #include <QTreeWidget>
    #include <QDialog>
    #include <QDialogButtonBox>
    #include <QVBoxLayout>
    
    int main(int argc, char *argv[])
    {
        QApplication app(argc,argv);
        QDialog dial;
        dial.setWindowTitle(QStringLiteral("Edit Headers"));
        QDialogButtonBox *dialButtons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, &dial);
        QObject::connect(dialButtons, &QDialogButtonBox::accepted, &dial, &QDialog::accept);
        QObject::connect(dialButtons, &QDialogButtonBox::rejected, &dial, &QDialog::reject);
        QTreeWidget* treeWidget = new QTreeWidget(&dial);
        treeWidget->setColumnCount(2);
        treeWidget->model()->insertRows(0,2);
        treeWidget->model()->setHeaderData(0,Qt::Horizontal,QStringLiteral("Name"));
        treeWidget->model()->setHeaderData(1,Qt::Horizontal,QStringLiteral("Value"));
        treeWidget->model()->setData(treeWidget->model()->index(0,0),QStringLiteral("h1"));
        treeWidget->model()->setData(treeWidget->model()->index(0,1),QStringLiteral("v1"));
        treeWidget->model()->setData(treeWidget->model()->index(1,0),QStringLiteral("h2"));
        treeWidget->model()->setData(treeWidget->model()->index(1,1),QStringLiteral("v2"));
        QVBoxLayout* dialLay = new QVBoxLayout(&dial);
        dialLay->addWidget(treeWidget);
        dialLay->addWidget(dialButtons);
        dial.setStyleSheet(QStringLiteral("QTreeWidget::item { border-bottom: 1px dotted grey; }"));
        dial.show();
        return app.exec();
    }
    

Log in to reply