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. Standard icon for QCheckBox?
Forum Updated to NodeBB v4.3 + New Features

Standard icon for QCheckBox?

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

    Hi, I am using fusion style and trying to change the ::indicator background colour for QCheckBox:

    qApp->setStyleSheet("QCheckBox::indicator{background: red}");
    

    It works fine but the checkbox icon is no longer shown, is there any way I can get the standard icon and reapply it there? I know I can get my own icon through resource files but I would rather stick to the standard icons.

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #5

      If you don't want to roll your own checkbox another way could be to customize the style. There's QStyleProxy that allows you to reuse the native style and only customize the small parts you need. You could provide only the checkbox painting and leave everything else to the base implementation. Could be a good way to do it if you'd ever need anything else style related customized.

      CJhaC 1 Reply Last reply
      2
      • Chris KawaC Offline
        Chris KawaC Offline
        Chris Kawa
        Lifetime Qt Champion
        wrote on last edited by
        #2

        Standard image is drawn using the native style plugin. When you set any stylesheet on a widget you're disabling that native style and switching to the stylesheet style.
        Instead of using stylesheet you could try deriving from QCheckBox and reimplement paintEvent to fill the background and then call base implementation to draw the checkbox image.

        1 Reply Last reply
        2
        • CJhaC Offline
          CJhaC Offline
          CJha
          wrote on last edited by
          #3

          @Chris-Kawa Thanks! I was hoping there would be a simpler way, like getting the native checkbox image from Qt (wherever it is stored) and applying it through the stylesheet like an image. I would use :checked, :unchecked, pressed and :indeterminate pseudo-states. This way I would not have to create my own checkbox class.

          1 Reply Last reply
          0
          • Chris KawaC Offline
            Chris KawaC Offline
            Chris Kawa
            Lifetime Qt Champion
            wrote on last edited by
            #4

            Style has a standardPixmap method to retrieve some pixmaps used by the style, but it doesn't seem to have an enum value for a checkbox, so you're out of luck I'm afraid.

            1 Reply Last reply
            1
            • Chris KawaC Offline
              Chris KawaC Offline
              Chris Kawa
              Lifetime Qt Champion
              wrote on last edited by
              #5

              If you don't want to roll your own checkbox another way could be to customize the style. There's QStyleProxy that allows you to reuse the native style and only customize the small parts you need. You could provide only the checkbox painting and leave everything else to the base implementation. Could be a good way to do it if you'd ever need anything else style related customized.

              CJhaC 1 Reply Last reply
              2
              • Chris KawaC Chris Kawa

                If you don't want to roll your own checkbox another way could be to customize the style. There's QStyleProxy that allows you to reuse the native style and only customize the small parts you need. You could provide only the checkbox painting and leave everything else to the base implementation. Could be a good way to do it if you'd ever need anything else style related customized.

                CJhaC Offline
                CJhaC Offline
                CJha
                wrote on last edited by CJha
                #6

                @Chris-Kawa Thanks! I was able to get it to work by using QProxyStyle.

                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