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. itemdelegate ignores stylesheet
Qt 6.11 is out! See what's new in the release blog

itemdelegate ignores stylesheet

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 2 Posters 2.4k Views 1 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.
  • MegamouseM Offline
    MegamouseM Offline
    Megamouse
    wrote on last edited by
    #1

    Hi,

    I want to give the tablewidget items a nice padding.
    But as soon as i use QTableWidget::setItemDelegate the following stylesheet won't apply anymore:

    QTableView::item {
        border-left: 4px solid white;
        border-right: 4px solid white;
    }
    

    Why could this be happening?

    raven-worxR 1 Reply Last reply
    0
    • MegamouseM Megamouse

      Hi,

      I want to give the tablewidget items a nice padding.
      But as soon as i use QTableWidget::setItemDelegate the following stylesheet won't apply anymore:

      QTableView::item {
          border-left: 4px solid white;
          border-right: 4px solid white;
      }
      

      Why could this be happening?

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

      @Megamouse said in itemdelegate ignores stylesheet:

      But as soon as i use QTableWidget::setItemDelegate

      what type of item delegate?

      --- 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

      1 Reply Last reply
      0
      • MegamouseM Offline
        MegamouseM Offline
        Megamouse
        wrote on last edited by
        #3

        I use a subclass of QItemDelegate with a drawFocus override that I use to prevent the ugly dotted selection rectangles around the items.
        But even if I simply use a default QItemDelegate it won't apply the style.

        So I'm looking for either a way to apply those styles to the items WITH the delegate applied,
        or
        for a way to remove the selection rectangles without using a delegate.

        raven-worxR 1 Reply Last reply
        0
        • MegamouseM Megamouse

          I use a subclass of QItemDelegate with a drawFocus override that I use to prevent the ugly dotted selection rectangles around the items.
          But even if I simply use a default QItemDelegate it won't apply the style.

          So I'm looking for either a way to apply those styles to the items WITH the delegate applied,
          or
          for a way to remove the selection rectangles without using a delegate.

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

          @Megamouse said in itemdelegate ignores stylesheet:

          I use a subclass of QItemDelegate

          k, then you need to subclass QStyledItemDelegate instead.
          For obvious reasons ;)

          --- 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

          1 Reply Last reply
          2
          • MegamouseM Offline
            MegamouseM Offline
            Megamouse
            wrote on last edited by
            #5

            That works for the stylesheet :) , but now I can't override drawFocus anymore to remove the selection rectangles :(

            raven-worxR 1 Reply Last reply
            0
            • MegamouseM Megamouse

              That works for the stylesheet :) , but now I can't override drawFocus anymore to remove the selection rectangles :(

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

              @Megamouse
              either in the initStyleOption() or in the paint() method do:

              option->state &= ~QStyle::State_HasFocus
              

              and draw the desired focus rect yourself

              --- 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

              1 Reply Last reply
              3
              • MegamouseM Offline
                MegamouseM Offline
                Megamouse
                wrote on last edited by
                #7

                @raven-worx worked like a charm. Thank you.

                Only the selection-background-color seems to be useless in the TableWidget stylesheet, so I simply styled QTableView::item:selected instead.

                The selection-color works though

                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