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. QComboBoxes and stylesheets
Forum Updated to NodeBB v4.3 + New Features

QComboBoxes and stylesheets

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 297 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.
  • M Offline
    M Offline
    Mummoc
    wrote on last edited by
    #1

    Hi everyone,
    In my application I currently have a QComboBox with the following stylesheet applied to it:

    QComboBox {
      border: 1px solid #b4b6ba;
      border-radius: 4px;
      padding: 3px 6px;
    }
    

    Resulting in this: 4a3fdd8a-eed6-4fea-aa9e-5dc3b4214b29-image.png
    The issue is that when navigating using the keyboard, there is no visual clues when this QComboBox gets focus. To fix this I added a rule to my stylesheet:

    QComboBox:focus:!hover{
      background-color: blue;
      background-clip: content;
      color: white;
    }
    

    Now when the QComboBox gets focus i get this result:
    6517f005-6e1f-48dc-b6b0-8c692bb6ee77-image.png
    While this is better, I would like for the drop button to not be coloured, basically it should ignore the previous rule.
    I know i can modify the drop-down using the ::drop-down subcontrol but i'm not sure how to do it.
    I can add rules to the ::drop-down but how can you tell it to ignore a rule of QComboBox ?

    I tried

    QComboBox::drop-down {
     background-color: transparent;
    }
    

    Thinking it would mean the ::drop-down would never get a background but instead the button is invisible now.

    I'm at a loss now I don't know what to try next. Is what I want even possible ?

    Anyway thanks in advance :)

    1 Reply Last reply
    0
    • L Offline
      L Offline
      LucaCiucci
      wrote on last edited by
      #2

      I think the only way to do that is to assign an icon to the ::arrow-down: looks like that if you style ::drop-down, ::arrow-down also looses the icon. In my case, this works:

      /* remove this:
      QComboBox::drop-down {
       background-color: transparent;
      }
      */
      
      QComboBox::down-arrow {
          image: url(:/images/icons/some-icon.svg);
      }
      

      I hope this helps

      M 1 Reply Last reply
      1
      • L LucaCiucci

        I think the only way to do that is to assign an icon to the ::arrow-down: looks like that if you style ::drop-down, ::arrow-down also looses the icon. In my case, this works:

        /* remove this:
        QComboBox::drop-down {
         background-color: transparent;
        }
        */
        
        QComboBox::down-arrow {
            image: url(:/images/icons/some-icon.svg);
        }
        

        I hope this helps

        M Offline
        M Offline
        Mummoc
        wrote on last edited by
        #3

        @LucaCiucci Hi, thanks for your reply.

        I tried what you suggested, and it did not work exactly like I wanted. But it did get me on the right track and instead of putting an image on the ::down-arrow I instead put it directly on the ::drop-down (I simply screenshotted the arrow and added it as a .png).
        Here's how my css looks now:

        QComboBox {
          border: 1px solid #b4b6ba;
          border-radius: 4px;
          padding: 3px 6px;
        }
        
        QComboBox:focus:!hover{
          background-color: blue;
          background-clip: content;
          color: white;
        }
        
        QComboBox::drop-down {
          image: url(:/images/ComboBox_down_arrow.png);
        }
        

        And here's the result I get, which is exactly what I wanted:
        3273f829-29d2-45ce-9e11-5135b57d8c0e-image.png

        Thanks for your help, I'm marking this as solved.

        1 Reply Last reply
        2

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved