Padding/Margin is not applied to last two elements in QTreeView



  • Hello.

    I have a QTreeView with the following styles applied to the items:

    QTreeView::item {
        padding: 5px;
        color: red;
    }
    

    If you check the following screenshot you'll see the last two items do not have the proper padding. The same happens if I switch from padding to margin. I set the color to red to make sure that rule was getting applied to all items.

    0_1525775495106_b0e96c6f-ac73-437e-88ef-911b3b9298bf-image.png

    I'm not sure what else to test, any clue?

    Edit: Ok I've been researching into the bug a little bit more and it's getting stranger. If instead of loading the stylesheet from a file, I do this:

    QApplication a(argc, argv);
    a.setStyleSheet("QTreeView::item {"
                      "padding: 15px;"
                      "color: red;"
                      "}");
    

    The behavior is the same, last two elements have no padding. However if I apply THE SAME stylesheet in the window's constructor, like this:

    ControllerWindow::ControllerWindow(QWidget *parent) :
        QMainWindow(parent), ui(new ::Ui::ControllerWindow)
    {
        ui->setupUi(this);
    
        setStyleSheet("QTreeView::item {"
                      "padding: 15px;"
                      "color: red;"
                      "}");
    

    It works!... ???? I'm baffled, this makes no sense. Is this a bug?



  • @JoseTomasTocino
    Try setStyleSheet only your QTreeWiev.
    like this:

    ui->treeView->setStyleSheet("QTreeView::item {"
                      "padding: 15px;"
                      "color: red;"
                      "}");
    


  • As I stated in the initial post, if I apply the stylesheet to either the containing window or the QTreeView itself it works, but it doesn't if I apply it to the QApplication, and it makes no sense.


  • Moderators

    @JoseTomasTocino
    do you apply a custom item delegate to your view?
    is your model static? Or do the items get added dynamically?



  • @raven-worx I don't use any custom item delegate.

    My model doesn't update, its items are fixed.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.