【问题标题】:How to draw a picture instead of the slider on Qt QSlider?如何在 Qt QSlider 上绘制图片而不是滑块?
【发布时间】:2009-12-17 06:11:11
【问题描述】:

我创建了一个继承自 QSlider 的类。我想在滑块(抓取器)上画一张图片,而不是显示普通的。怎么办?

--

我在收到回复后找到了答案并发布了。出于对响应者的应有尊重,我将选择该答复。但是,我想分享代码,以便遇到相同问题的任何人都可以受益:

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);
}

【问题讨论】:

    标签: qt paint subclassing redraw qslider


    【解决方案1】:

    您可以在小部件的paintEvent 方法中执行此操作。这允许您重绘所有或仅部分小部件。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-06-23
      • 1970-01-01
      • 2013-06-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多