我嘗試創建QML-PYSIDE計算器。但是我找不到任何這樣的例子。我也檢查了pyside wiki,但無法理解如何一起運行QML-PySide。 例如,我想用QML-PySİde運行附加應用程序(a + b = c)。我可以控制由QtDesigner與Python創建的附加應用程序GUI(sumui.ui)(由PySideTools轉換)。但我無法用Python控制添加應用程序QML(inputtext,button)。 我是python-qt的新手。因此,我輸入pyside-qtdesigner和qml GUI來了解PySide-QtWidgets和PySide-QML UI之間的重新聯繫。 (對不起我的英語不好)如何用PySide控制QML UI?
PySide除了應用:
應用程序的圖片:http://postimg.org/image/envp8jgg9/
addition.py:
# addition.py
from PySide import QtCore, QtGui
from sumui import Ui_Form
import sys
def derece(degrees):
return degrees*((2*pi)/400)
class hesap(QtGui.QWidget):
def __init__(self):
QtGui.QWidget.__init__(self)
self.ui = Ui_Form()
self.ui.setupUi(self)
# Validations
tempValidator = QtGui.QDoubleValidator()
tempValidator.setNotation(QtGui.QDoubleValidator.StandardNotation)
self.ui.a.setValidator(tempValidator)
self.ui.b.setValidator(tempValidator)
self.setupConnections()
def topla(self):
a1 = float(self.ui.a.text())
b1 = float(self.ui.b.text())
c1 = a1 + b1
cc1 = str(c1)
self.ui.c.setText(str(cc1))
def setupConnections(self):
self.connect(self.ui.sum, QtCore.SIGNAL('clicked()'),
self.topla)
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
window = hesap()
window.show()
sys.exit(app.exec_())
QML GUI:http://postimg.org/image/pocxfcf19/ addition.qml:
import QtQuick 1.1
Rectangle {
id:r
anchors.centerIn: parent
width: 200
height: 200
Column{
width: r.width*0.8
height: r.height*0.8
spacing: 10
anchors.centerIn: parent
Row{
id:ro
spacing:10
Text {
anchors.centerIn: ro.parent
font.bold: true
text: "a"
}
TextInput {
id: a
width: r.width*3/4
height: 20
selectionColor: "#2f8bc5"
fillColor: "lightgray"
font.bold: true
}
}
Row{
spacing:10
Text {
text: "b"
font.bold: true
}
TextInput {
id: b
width: r.width*3/4
height: 20
fillColor: "lightgray"
font.bold: true
}
}
Rectangle {
id: calculate
width: r.width
height: 30
color: "#8a0800"
//x:b.width*0.2
Text{
anchors.centerIn: calculate
font.bold: true
text:"calculate";color:"white"}
gradient: Gradient {
GradientStop {
position: 0
color: "#8a0800"
}
GradientStop {
position: 1
color: "#330009"
}
}
}
Row{
spacing:10
Text {
text: "c"
font.bold: true
}
TextInput {
id: c
font.bold: true
width: r.width*3/4
height: 20
fillColor: "lightgray"
selectionColor: "#2f8bc5"
font.pixelSize: 12
}
}
}
}
How to ru用QSide添加QML的用戶界面?或者有沒有像PySide-QML計算器的例子? 謝謝
謝謝。是的,我的意思是。我可以用python運行單個QML。但我沒有嘗試用python運行多個QML文件。我將嘗試運行多個QML。這是研究C++ -Qt示例的好主意,我對C++一無所知。但是我會研究C++和PyQt之間的類似例子。然後我會比較它們用於控制信號和插槽。因此PySide和C++使用與Qt相同的API。對不起,我的英語不好。 –