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. drawComplexControl and transparent background
Forum Update on Monday, May 27th 2025

drawComplexControl and transparent background

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 2 Posters 3.3k 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.
  • mrjjM Offline
    mrjjM Offline
    mrjj
    Lifetime Qt Champion
    wrote on last edited by
    #1

    Hi
    I have an combobox with a paintevent.
    I try to paint the arrow on it but faces this issue
    that the background is not transparent but filled so
    all i drew before is erased.

    alt text

    I draw the arrow like this:
    QStyleOptionComboBox comboOptions;
    comboOptions.subControls = QStyle::SC_ComboBoxArrow;
    QApplication::style()->drawComplexControl(QStyle::CC_ComboBox, &comboOptions, &painter);

    I tried setting NoBrush on the painter but it had no effect.

    Anyone, knows how to make it transparent ? (if possible)

    (and no, i cant paint arrow first as other drawing will clear also)

    raven-worxR 2 Replies Last reply
    0
    • mrjjM mrjj

      Hi
      I have an combobox with a paintevent.
      I try to paint the arrow on it but faces this issue
      that the background is not transparent but filled so
      all i drew before is erased.

      alt text

      I draw the arrow like this:
      QStyleOptionComboBox comboOptions;
      comboOptions.subControls = QStyle::SC_ComboBoxArrow;
      QApplication::style()->drawComplexControl(QStyle::CC_ComboBox, &comboOptions, &painter);

      I tried setting NoBrush on the painter but it had no effect.

      Anyone, knows how to make it transparent ? (if possible)

      (and no, i cant paint arrow first as other drawing will clear also)

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

      @mrjj
      you need to set the palette of the passed styleoption accordingly.
      Probably you need to set the QPalette::Base or QPalette::Window role of it.
      The QStyle initializes the painter on it's own.

      Alternatively instead of drawing the whole complex control you could also just paint the sub control QStyle::SC_ComboBoxArrow
      Or QStyle::SC_ComboBoxFrame first, then your painting then the QStyle::SC_ComboBoxArrow

      --- 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
      • mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #3

        @raven-worx said in drawComplexControl and transparent background:

        The QStyle initializes the painter on it's own.

        Ah, that is why nothing really had any effect.

        -Alternatively instead of drawing the whole complex control you could also just paint the sub control QStyle::SC_ComboBoxArrow
        Or QStyle::SC_ComboBoxFrame first, then your painting then the QStyle::SC_ComboBoxArrow

        Hmm. First i draw via a delegate so it looks the same open and closed.

         QStyleOptionComboBox comboOptions;
            initStyleOption(&comboOptions);
        // draw as delegate 
            const QModelIndex modelIdx = view()->model()->index(currentIndex(), modelColumn());
            view()->itemDelegate()->paint(&painter, delegateFromCombo(comboOptions, modelIdx), modelIdx);
        // then draw arrow
            comboOptions.subControls = QStyle::SC_ComboBoxArrow;
            QApplication::style()->drawComplexControl(QStyle::CC_ComboBox, &comboOptions, &painter);
        

        So not sure I can split it as you suggest.
        is there another draw function that take QStyle::SC_ComboBoxArrow , other than
        drawComplexControl ?

        I will try the palette. Thank you.

        raven-worxR 1 Reply Last reply
        1
        • mrjjM mrjj

          @raven-worx said in drawComplexControl and transparent background:

          The QStyle initializes the painter on it's own.

          Ah, that is why nothing really had any effect.

          -Alternatively instead of drawing the whole complex control you could also just paint the sub control QStyle::SC_ComboBoxArrow
          Or QStyle::SC_ComboBoxFrame first, then your painting then the QStyle::SC_ComboBoxArrow

          Hmm. First i draw via a delegate so it looks the same open and closed.

           QStyleOptionComboBox comboOptions;
              initStyleOption(&comboOptions);
          // draw as delegate 
              const QModelIndex modelIdx = view()->model()->index(currentIndex(), modelColumn());
              view()->itemDelegate()->paint(&painter, delegateFromCombo(comboOptions, modelIdx), modelIdx);
          // then draw arrow
              comboOptions.subControls = QStyle::SC_ComboBoxArrow;
              QApplication::style()->drawComplexControl(QStyle::CC_ComboBox, &comboOptions, &painter);
          

          So not sure I can split it as you suggest.
          is there another draw function that take QStyle::SC_ComboBoxArrow , other than
          drawComplexControl ?

          I will try the palette. Thank you.

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

          @mrjj said in drawComplexControl and transparent background:

          So not sure I can split it as you suggest.
          is there another draw function that take QStyle::SC_ComboBoxArrow , other than
          drawComplexControl ?

          my fault sry. I wrongly remembered a QStyle::drawSubControl()
          Didn't the palette approach work?

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

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

            @mrjj said in drawComplexControl and transparent background:

            So not sure I can split it as you suggest.
            is there another draw function that take QStyle::SC_ComboBoxArrow , other than
            drawComplexControl ?

            my fault sry. I wrongly remembered a QStyle::drawSubControl()
            Didn't the palette approach work?

            mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by mrjj
            #5

            @raven-worx

            Well QPalette::Background had no effect and
            QPalette::Window seems to be used as border ?

            alt text

             QPalette bgpal = palette();
             bgpal.setColor (QPalette::Window, Qt::red);
             setPalette(bgpal);
            

            But your idea is very valid. Just need to find out what role it uses :)

            ps: i also think i saw drawSubControl() but it was drawControl

            1 Reply Last reply
            0
            • mrjjM mrjj

              Hi
              I have an combobox with a paintevent.
              I try to paint the arrow on it but faces this issue
              that the background is not transparent but filled so
              all i drew before is erased.

              alt text

              I draw the arrow like this:
              QStyleOptionComboBox comboOptions;
              comboOptions.subControls = QStyle::SC_ComboBoxArrow;
              QApplication::style()->drawComplexControl(QStyle::CC_ComboBox, &comboOptions, &painter);

              I tried setting NoBrush on the painter but it had no effect.

              Anyone, knows how to make it transparent ? (if possible)

              (and no, i cant paint arrow first as other drawing will clear also)

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

              @mrjj said in drawComplexControl and transparent background:
              what i meant was rather something like this:

              QStyleOptionComboBox comboOptions;
              QPalette p = comboOptions.palette;
                   p.setColor(QPalette::Base, Qt::transparent);
              comboOptions.palette = p;
              QApplication::style()->drawComplexControl(QStyle::CC_ComboBox, &comboOptions, &painter);
              

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

              mrjjM 1 Reply Last reply
              3
              • raven-worxR raven-worx

                @mrjj said in drawComplexControl and transparent background:
                what i meant was rather something like this:

                QStyleOptionComboBox comboOptions;
                QPalette p = comboOptions.palette;
                     p.setColor(QPalette::Base, Qt::transparent);
                comboOptions.palette = p;
                QApplication::style()->drawComplexControl(QStyle::CC_ComboBox, &comboOptions, &painter);
                
                mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by mrjj
                #7

                @raven-worx said in drawComplexControl and transparent background:

                Thank you.
                It have no effect.
                I will try other QPalette::keys

                I tried

                    QPalette bgpal = palette();
                    for (int cc=0; cc < QPalette::NColorRoles; cc++ )
                    bgpal.setColor (cc, Qt::red);
                    setPalette(bgpal);
                

                and got
                alt text

                But clearly it should be via comboOptions.palette as you suggest.

                Update::
                Oddly, setting all palette to trans, gives

                alt text

                    QPalette p = comboOptions.palette;
                    for (int cc = 0; cc < QPalette::NColorRoles; cc++ ) {
                      p.setColor (cc, Qt::transparent);    }
                    comboOptions.palette = p;
                

                Time to use the source, luke, i think :)

                Thank you for your input. Clearly its something like that.

                raven-worxR 1 Reply Last reply
                2
                • mrjjM mrjj

                  @raven-worx said in drawComplexControl and transparent background:

                  Thank you.
                  It have no effect.
                  I will try other QPalette::keys

                  I tried

                      QPalette bgpal = palette();
                      for (int cc=0; cc < QPalette::NColorRoles; cc++ )
                      bgpal.setColor (cc, Qt::red);
                      setPalette(bgpal);
                  

                  and got
                  alt text

                  But clearly it should be via comboOptions.palette as you suggest.

                  Update::
                  Oddly, setting all palette to trans, gives

                  alt text

                      QPalette p = comboOptions.palette;
                      for (int cc = 0; cc < QPalette::NColorRoles; cc++ ) {
                        p.setColor (cc, Qt::transparent);    }
                      comboOptions.palette = p;
                  

                  Time to use the source, luke, i think :)

                  Thank you for your input. Clearly its something like that.

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

                  @mrjj said in drawComplexControl and transparent background:

                  Time to use the source, luke, i think :)

                  ^^

                  Thank you for your input. Clearly its something like that.

                  or maybe not. QStyle sometimes isn't that cooperative, especially when using the native style.
                  Mostly you have the best chances to update such things by using the qstylesheet style. But thats also sometimes not an option when the native look is needed.

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

                  mrjjM 1 Reply Last reply
                  2
                  • raven-worxR raven-worx

                    @mrjj said in drawComplexControl and transparent background:

                    Time to use the source, luke, i think :)

                    ^^

                    Thank you for your input. Clearly its something like that.

                    or maybe not. QStyle sometimes isn't that cooperative, especially when using the native style.
                    Mostly you have the best chances to update such things by using the qstylesheet style. But thats also sometimes not an option when the native look is needed.

                    mrjjM Offline
                    mrjjM Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on last edited by mrjj
                    #9

                    @raven-worx

                    Well it seems that fusion style
                    kinda do not use palette and then again, it does affect it.

                    But i never really fooled around with QStyle so not giving up yet.

                    However, I can also just draw the arrow myself since i can ask for the rect/placement it seems.
                    So maybe that is how to do it.

                    Update:
                    Turned out SC_ComboBoxArrow was something else.
                    it seems that i tried to

                    So i solved it by using
                    QApplication::style()->drawPrimitive(QStyle::PE_IndicatorArrowDown,&comboOptions, &painter);
                    To draw arrow myself.

                    1 Reply Last reply
                    4

                    • Login

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