Draw below of style sheets
-
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
-
Call the base class (or the QStyle API by hand) after you paint in your paintEvent()?
-
no, that doesn't work. Stylesheets seem to be painted before paintEvent() is even called.
-
have you check the style sheet drawing by reading the Qt source?
-
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.
-
@
#ifndef SOUNDLEVELBAR_H
#define SOUNDLEVELBAR_H#include <QFrame>
class SoundLevelBar : public QFrame
{
Q_OBJECTprotected:
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.