Question

J'ai créé une classe qui hérite de QSlider. Je veux dessiner une image sur le curseur (Grabber) au lieu de montrer le simple. Comment faire?

--

J'ai trouvé une réponse et posté après avoir reçu la réponse. Avec le respect dû au répondeur, je choisirai cette réponse. Cependant, j'aimerais partager du code afin que toute personne ayant le même problème puisse en bénéficier:

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);
}
Était-ce utile?

La solution

Vous pouvez le faire dans le pairtevent Méthode du widget. Cela vous permet de redessiner tout ou seulement une partie du widget.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top