我使用 QDial 控件来输入以秒为单位的时间值。如何更改显示在这些表盘中间的自动添加的文本?
编辑:它们来自 QtCurve 风格。
如果您的程序中没有明确显示此整数值的代码(在信号/插槽中),那么很可能是您当前的 Qt 样式执行此操作。请参阅以下 Qt 样式示例,以了解该整数的显示通常不是 QDial 显示的一部分:
http://qt-project.org/doc/qt-4.8/gallery-plastique.html
http://qt-project.org/doc/qt-4.8/gallery-cde.html
http://qt-project.org/doc/qt-4.8/gallery-gtk.html
http://qt-project.org/doc/qt-4.8/gallery-cleanlooks.html
http://qt-project.org/doc/qt-4.8/gallery-windowsvista.html
http://qt-project.org/doc/qt-4.8/gallery-macintosh.html
有关样式的更多信息,请参见:http: //qt-project.org/doc/qt-4.8/qstyle.html。
您还可以在您的程序代码中查找以下代码:
QApplication::setStyle(...);
您还可以检查以下内容:
如果您仍然没有找到您的样式是如何设置的,那么它可能是您平台的默认样式。
下面说什么?
QStyle *currentStyle = QApplication::style();
qDebug() << currentStyle;
qDebug() << currentStyle->objectName();
qDebug() << currentStyle->metaObject()->className();
编辑:我看到您将样式确定为 QtCurve。
来源有: http://kde-look.org/content/download.php?content=40492&id=1&tan= 23640920
我们可以看到样式负责显示值:
文件:样式/qtcurve.cpp,行:7980
// Draw value...
#ifdef DIAL_DOT_ON_RING
drawItemTextWithRole(painter, outer.adjusted(sliderWidth, sliderWidth, -sliderWidth, -sliderWidth),
Qt::AlignCenter, palette, state&State_Enabled,
QString::number(slider->sliderValue), QPalette::ButtonText);
#else
int adjust=2*sliderWidth;
drawItemTextWithRole(painter, outer.adjusted(adjust, adjust, -adjust, -adjust),
Qt::AlignCenter, palette, state&State_Enabled,
QString::number(slider->sliderValue), QPalette::ButtonText);
#endif
从现在开始,您可以:
假设您的意思是以秒为单位的秒?您可以计算出表盘相对于其完整旋转位置的百分比,然后将其应用于最大秒数的百分比。
例如,如果表盘从 0 转到 360,并且当前位置在 90,则其百分比为
90 / 360 * 100 = 25%。
如果以秒为单位的最大值为 60,则为 60 的 25%。
25 / 100 * 60 = 15 秒。
所以显示屏现在将显示 15 秒。