Pregunta

He creado una clase que hereda de QSLider. Quiero dibujar una imagen en el control deslizante (agarre) en lugar de mostrar la simple. ¿Cómo hacerlo?

--

Encontré una respuesta y publiqué después de haber recibido la respuesta. Con el debido respeto al respondedor, elegiré esa respuesta. Sin embargo, me gustaría compartir código para que cualquier persona con el mismo problema pueda beneficiarse:

void InheritedSlider::paintEvent(QPaintEvent *event)
{
    // uncomment to draw the parent first. Comment out to just ignore it.
    //QSlider::paintEvent(event);

    QPainter painter(this);
    painter.setRenderHint(QPainter::Antialiasing);

    //painter.translate(width() / 2, height() / 2);
    //painter.scale(100 / 200.0, 100 / 200.0);

    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);
}
¿Fue útil?

Solución

Puedes hacerlo en el pintura Método del widget. Esto le permite volver a dibujar todo o solo una parte del widget.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top