I created a class that inherits from QSlider. I want to draw a picture on the slider (grabber) instead of showing simple. How to do it?
-
I found the answer and sent after I received the answer. With due respect to the defendant, I will choose this answer. However, I would like to share the code so that anyone with the same problem can win:
void InheritedSlider::paintEvent(QPaintEvent *event)
{
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing);
QPainterPath volPath;
volPath.moveTo(60.0, 40.0);
volPath.arcTo(20.0, 20.0, 40.0, 40.0, 0.0, 360.0);
volPath.moveTo(40.0, 40.0);
volPath.lineTo(40.0, 80.0);
volPath.lineTo(80.0, 80.0);
volPath.lineTo(80.0, 40.0);
volPath.closeSubpath();
painter.drawPath(volPath);
}
source
share