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. "background-color" stylesheet option reject previous drawing results

"background-color" stylesheet option reject previous drawing results

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 2 Posters 1.6k 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.
  • K Offline
    K Offline
    kuzulis
    Qt Champions 2020
    wrote on last edited by kuzulis
    #1

    Hi all.

    I want to have QSlider with some background text. I derive my widget from QSlider and override paintEvent() to draw an text in this way:

    void My::paintEvent(QPaintEvent *ev)
    {
        QPainter p(this);
    
        style()->drawItemText(&p, rect(), Qt::AlignCenter, palette(), true, tr("FOO"));
    
        QStyleOptionSlider opt;
        initStyleOption(&opt);
        opt.subControls = QStyle::SC_SliderHandle;
    
        style()->drawComplexControl(QStyle::CC_Slider, &opt, &p, this);
    }
    

    In this case I see my drawed text in center of widget. But when the handle position is over the text, the text is blocked by the handle (as text is under the handle), it is ok.

    Further, I want to make the handle semi-translucent that my text wasn't blocked by the handle, and stays visible through the handle.
    For this purpose I use styleshhet for handle:

        app.setStyleSheet(
                    " QSlider::handle:horizontal { background-color: rgba(50, 100, 200, 100); width: 13px; } \n"
                    );
    

    All fine, now I see my text through handle.

    BUT, when I try to setup widget's background color, using stylesheet option:

        app.setStyleSheet(
                    " QSlider { background-color: yellow; } \n"
                    " QSlider::handle:horizontal { background-color: rgba(50, 100, 200, 100); width: 13px; } \n"
                    );
    

    then I do not see my text anymore.

    So, what I doing wrong? How to draw my text on "layer" between of the background and the handle? Or, maybe I need other way?

    raven-worxR 1 Reply Last reply
    0
    • K kuzulis

      Hi all.

      I want to have QSlider with some background text. I derive my widget from QSlider and override paintEvent() to draw an text in this way:

      void My::paintEvent(QPaintEvent *ev)
      {
          QPainter p(this);
      
          style()->drawItemText(&p, rect(), Qt::AlignCenter, palette(), true, tr("FOO"));
      
          QStyleOptionSlider opt;
          initStyleOption(&opt);
          opt.subControls = QStyle::SC_SliderHandle;
      
          style()->drawComplexControl(QStyle::CC_Slider, &opt, &p, this);
      }
      

      In this case I see my drawed text in center of widget. But when the handle position is over the text, the text is blocked by the handle (as text is under the handle), it is ok.

      Further, I want to make the handle semi-translucent that my text wasn't blocked by the handle, and stays visible through the handle.
      For this purpose I use styleshhet for handle:

          app.setStyleSheet(
                      " QSlider::handle:horizontal { background-color: rgba(50, 100, 200, 100); width: 13px; } \n"
                      );
      

      All fine, now I see my text through handle.

      BUT, when I try to setup widget's background color, using stylesheet option:

          app.setStyleSheet(
                      " QSlider { background-color: yellow; } \n"
                      " QSlider::handle:horizontal { background-color: rgba(50, 100, 200, 100); width: 13px; } \n"
                      );
      

      then I do not see my text anymore.

      So, what I doing wrong? How to draw my text on "layer" between of the background and the handle? Or, maybe I need other way?

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

      @kuzulis
      draw the text after you draw the slider ;)

      --- 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
      • K Offline
        K Offline
        kuzulis
        Qt Champions 2020
        wrote on last edited by
        #3

        draw the text after you draw the slider ;)

        No, it is not option for me. I need the handle (and groove) at top of text. :(

        raven-worxR 1 Reply Last reply
        0
        • K kuzulis

          draw the text after you draw the slider ;)

          No, it is not option for me. I need the handle (and groove) at top of text. :(

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

          @kuzulis
          sorry but how is this supposed to look like?! This doesn't make much sense?

          --- 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
          • K Offline
            K Offline
            kuzulis
            Qt Champions 2020
            wrote on last edited by
            #5

            This doesn't make much sense?

            My slider will have own tick-marks with values, which are placed inside of slider widget. Also there (inside of widget) will be placed some additional info (e.g. legends, captions and so forth). It is required by design! So, I need to draw all this stuff on "background"... :(

            I use QSlider as base widget, because I want to use its existing "hover" and "groove" stylesheet's properties as need for me (such trick).

            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