3

我在 Windows 上使用 PyQt4 和 Python 2.7,对于音乐播放器,我决定Phonon.SeekSliderQDial.
我的问题是,a 的最小值QDial总是在表盘的底部,但我希望它在顶部(值仍然顺时针增加)。我试过setInvertedAppearance()and setInvertedControls(),但这只是水平翻转表盘,setOrientation()也没有帮助。
我的问题:有没有办法指定一个角度来定位表盘上的最小值或垂直翻转整个表盘?

4

3 回答 3

4

我不相信有办法直接做到这一点。但是,您可以将 放置在QDialQGraphicsView,并将其作为场景中的项目进行旋转。像这样的东西应该工作:

import sys
from PyQt4 import QtGui, QtCore

class RotatableView(QtGui.QGraphicsView):
    def __init__(self, item, rotation=0):
        QtGui.QGraphicsView.__init__(self)
        scene = QtGui.QGraphicsScene(self)
        self.setScene(scene)
        graphics_item = scene.addWidget(item)
        graphics_item.rotate(rotation)

        # make the QGraphicsView invisible
        self.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
        self.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
        self.setFixedHeight(item.height())
        self.setFixedWidth(item.width())
        self.setStyleSheet("border: 0px")

class DialExample(QtGui.QWidget):
    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self, parent)
        dial = QtGui.QDial()
        dial.setNotchesVisible(True)
        label = QtGui.QLabel('0')
        dial.valueChanged.connect(label.setNum)

        layout = QtGui.QVBoxLayout()
        layout.addWidget(RotatableView(dial, 180))
        layout.addWidget(label)
        self.setLayout(layout)

if __name__ == '__main__':
    app = QtGui.QApplication(sys.argv)
    dialexample = DialExample()
    dialexample.show()
    sys.exit(app.exec_())
于 2013-08-30T22:55:15.417 回答
2

Hackyday 给个QgraphicsView答案,这里我给你一个pyqt不使用QgraphicsView. 你可以直接在 python 上用一个小if/else语句来做。

你创建你的qDial,我想你想要一个表盘作为指南针(0 - 360°),我想你写了一个输出qDialqSpinBox

<widget class="QDial" name="dial">
 <property name="geometry">
  <rect>
   <x>20</x>
   <y>150</y>
   <width>101</width>
   <height>111</height>
  </rect>
 </property>
 <property name="mouseTracking">
  <bool>false</bool>
 </property>
 <property name="acceptDrops">
  <bool>false</bool>
 </property>
 <property name="layoutDirection">
  <enum>Qt::LeftToRight</enum>
 </property>
 <property name="minimum">
  <number>0</number>
 </property>
 <property name="maximum">
  <number>360</number>
 </property>
 <property name="singleStep">
  <number>0</number>
 </property>
 <property name="pageStep">
  <number>0</number>
 </property>
 <property name="value">
  <number>135</number>
 </property>
 <property name="sliderPosition">
  <number>135</number>
 </property>
 <property name="orientation">
  <enum>Qt::Horizontal</enum>
 </property>
 <property name="invertedAppearance">
  <bool>false</bool>
 </property>
 <property name="invertedControls">
  <bool>false</bool>
 </property>
 <property name="wrapping">
  <bool>true</bool>
 </property>
 <property name="notchesVisible">
  <bool>false</bool>
 </property>
</widget>


<widget class="QSpinBox" name="oAzimuth">
 <property name="geometry">
  <rect>
   <x>10</x>
   <y>110</y>
   <width>52</width>
   <height>30</height>
  </rect>
 </property>
 <property name="maximum">
  <number>360</number>
 </property>
 <property name="value">
  <number>315</number>
 </property>
</widget>

如果要将滑块的默认位置设置为 315°,请按照我的示例将其设置为 135°。为什么 ?因为您在 0° 和 180° 之间的所有度数都必须转换为 +180°,而 181° 和 360° 之间的度数必须转换为 -180°。

依此类推pyqt,在您的file.py中,您可以编写并if/else声明以在 a 中自动更正function

def Edit_Slider(self):
    if self.dockwidget.spinbox.value() > 180:
         self.dockwidget.dial.setValue(self.dockwidget.spinbox.value()-180)
    else:
         self.dockwidget.dial.setValue(self.dockwidget.spinbox.value()+180)

def Edit_Spinbox(self):
    if self.dockwidget.dial.value() > 180:
         self.dockwidget.spinbox.setValue(self.dockwidget.dial.value()-180)
    else:
         self.dockwidget.spinbox.setValue(self.dockwidget.dial.value()+180)

并在您移动滑块或 SpinValue 时自动编辑此更改:

self.dockwidget.spinbox.valueChanged.connect(self.Edit_Slider)
self.dockwidget.dial.valueChanged.connect(self.Edit_Spinbox)
于 2017-10-19T09:49:22.527 回答
0

您也可以在 linedit 中使用 qdial 值。由于 QDial 仅适用于整数,通过使用以下命令,您可以使用浮点中的任何值。 self.dial_object = QtGui.QDial(self.centralwidget) self.dial_object.setNotchesVisible(True) self.dial_object.setGeometry(QtCore.QRect(15,110,45,45)) self.dial_object.setMinimum(50) 这将拨号最小值设置为 0.5 self.dial_object.setMaximum(100) 这将拨号最大值设置为 1 self.dial_object.setSingleStep(10) 这将拨号分辨率值设置为 0.01 self.dial_object.setValue(0) 这将拨号起始值设置为 0 self.dial_object.valueChanged.connect(self.dvalue1)def dvalue1(self): self.lineEdit_object.setText(str(float(self.dial_object.value())*0.01)) 会将值更改为浮点到字符串类型(在 setText 中使用)。0.01 决定表盘分辨率。

于 2018-12-12T04:26:14.277 回答