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. Padding/Margin is not applied to last two elements in QTreeView

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

Scheduled Pinned Locked Moved Unsolved General and Desktop
qtreeviewqtreewidgetstylesheet
6 Posts 4 Posters 5.0k Views
  • 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.
  • J Offline
    J Offline
    JoseTomasTocino
    wrote on last edited by JoseTomasTocino
    #1

    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?

    Taz742T 1 Reply Last reply
    0
    • J JoseTomasTocino

      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?

      Taz742T Offline
      Taz742T Offline
      Taz742
      wrote on last edited by
      #2

      @JoseTomasTocino
      Try setStyleSheet only your QTreeWiev.
      like this:

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

      Do what you want.

      1 Reply Last reply
      1
      • J Offline
        J Offline
        JoseTomasTocino
        wrote on last edited by
        #3

        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.

        raven-worxR 1 Reply Last reply
        0
        • J JoseTomasTocino

          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.

          raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #4

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

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          J 1 Reply Last reply
          0
          • raven-worxR raven-worx

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

            J Offline
            J Offline
            JoseTomasTocino
            wrote on last edited by
            #5

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

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

            1 Reply Last reply
            0
            • R Offline
              R Offline
              Rafeek
              wrote on last edited by
              #6

              A late reply, but it looks like those elements are different in that they don't have children. Have you checked that you don't have a style with

              QTreeView::item:!has-children {
                  padding: ...
              }
              

              defined anywhere which could be overriding the style when applied at the branch level?

              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