2013-08-28 4 views
3

Windows에서 Python 2.7과 함께 PyQt4를 사용 중이며 뮤직 플레이어의 경우 Phonon.SeekSliderQDial으로 대체하기로 결정했습니다.
내 문제는 QDial의 최소값이 항상 다이얼의 맨 아래에 있지만,이 값이 상단 (값이 여전히 시계 방향으로 증가 함)에 있도록하려는 것입니다. setInvertedAppearance()setInvertedControls()을 시도했지만 다이얼을 수평으로 뒤집었고 setOrientation()도 도움이되지 않았습니다.
내 질문 : 각도를 지정하여 다이얼의 최소값을 배치하거나 전체 다이얼을 수직으로 뒤집을 수있는 방법이 있습니까?PyQt4/Qt : QDial의 방향 설정 (상단의 최소값)

답변

3

나는 이것을 직접하는 방법이 없다고 생각합니다. 그러나 을 QGraphicsView에 넣고 장면의 항목으로 회전 할 수 있습니다. 이런 식으로 뭔가 작업을해야합니다 :

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_()) 
1

Hackyday 내가 당신에게 QgraphicsView을 사용하지 않고 pyqt 솔루션을 제공, 여기에 QgraphicsView 대답을 제공합니다. 약간의 if/else 문으로 파이썬에서 직접 할 수 있습니다.

당신은 당신의 qDial를 작성, 난 당신이 나침반으로 전화한다고 가정 (0-360 °)를하고 난 당신이 qSpinBoxqDial의 출력) 작성 가정 : 당신이 원하는 경우

<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 °로 이동해야합니다.

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 이동하면서 자동으로 변경 사항을 편집 : 당신이 쓸 수있는 file.py에 따라서 pyqt

if/else 문은 function 내부에서 자동으로를 해결하기

self.dockwidget.spinbox.valueChanged.connect(self.Edit_Slider) 
self.dockwidget.dial.valueChanged.connect(self.Edit_Spinbox) 
+0

성공적으로 올바르게 작동하려면 값을 변환하는 수학, 감사합니다! –