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. Draw below of style sheets

Draw below of style sheets

Scheduled Pinned Locked Moved General and Desktop
6 Posts 4 Posters 3.0k 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.
  • E Offline
    E Offline
    eddyilg
    wrote on last edited by
    #1

    Hi,

    using paintEvent to draw on a subclassed QFrame draws ontop of style sheets. How can I draw below them (i.e. render the stylesheet after doing my drawing) ?

    Best regards,

    Eddy

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dangelog
      wrote on last edited by
      #2

      Call the base class (or the QStyle API by hand) after you paint in your paintEvent()?

      Software Engineer
      KDAB (UK) Ltd., a KDAB Group company

      1 Reply Last reply
      0
      • E Offline
        E Offline
        eddyilg
        wrote on last edited by
        #3

        no, that doesn't work. Stylesheets seem to be painted before paintEvent() is even called.

        1 Reply Last reply
        0
        • G Offline
          G Offline
          giesbert
          wrote on last edited by
          #4

          have you check the style sheet drawing by reading the Qt source?

          Nokia Certified Qt Specialist.
          Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

          1 Reply Last reply
          0
          • A Offline
            A Offline
            andre
            wrote on last edited by
            #5

            Show us your drawing code, please. I assume you call the base implementation of your QFrame's paintevent? If so, you will want to perform your own drawing first, and then the call the base implementation. However, that may overdraw what you have just drawn, I think.

            1 Reply Last reply
            0
            • E Offline
              E Offline
              eddyilg
              wrote on last edited by
              #6

              @
              #ifndef SOUNDLEVELBAR_H
              #define SOUNDLEVELBAR_H

              #include <QFrame>

              class SoundLevelBar : public QFrame
              {
              Q_OBJECT

              protected:
              int m_level;

              public:
              explicit SoundLevelBar(QWidget *parent = 0);
              int level() { return m_level; }

              protected:
              void paintEvent(QPaintEvent *paintEvent);

              public slots:
              void setLevel(int level);

              signals:
              void levelSet(int level);
              };

              #endif // SOUNDLEVELBAR_H

              #include <QStyle>
              #include <QPainter>
              #include <QStyleOption>
              #include <QStylePainter>

              #include "soundlevelbar.h"

              SoundLevelBar::SoundLevelBar(QWidget *parent) :
              QFrame(parent),
              m_level(0)
              {
              setStyleSheet("QWidget { border: 1px solid #AAAAAA; border-radius: 3px; margin-bottom: 1px; }\n");
              }

              void SoundLevelBar::setLevel(int level)
              {
              if(m_level==level)
              return;

              m_level=level; 
              
              levelSet(m_level);
              
              update();
              

              }

              void SoundLevelBar::paintEvent(QPaintEvent *paintEvent)
              {
              int l=height()*m_level/100;

              QPainter p(this);
              p.fillRect(0,height()-l,width(),l,QBrush(QColor(0,166,16)));
              
              QFrame::paintEvent(paintEvent);
              

              }

              @

              The rectangle in paintEvent is painted over the frame with round corners.

              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