def init(self, window): self.window = window # Create div. self.createTicker() self.createUpnDownButtons() self.createBackButton() # Create first level menu. rootElement = self.contentsDoc.documentElement() self.createRootMenu(rootElement) # Create second level menus. level2MenuNode = rootElement.firstChild() while not level2MenuNode.isNull(): level2MenuElement = level2MenuNode.toElement() self.createSubMenu(level2MenuElement) # Create leaf menu and example info. exampleNode = level2MenuElement.firstChild() while not exampleNode.isNull(): exampleElement = exampleNode.toElement() self.readInfoAboutExample(exampleElement) self.createLeafMenu(exampleElement) exampleNode = exampleNode.nextSibling() level2MenuNode = level2MenuNode.nextSibling() # Support QML if possible. try: from PyQt4 import QtDeclarative except ImportError: return self.declarativeEngine = QtDeclarative.QDeclarativeEngine(self) component = QtDeclarative.QDeclarativeComponent( self.declarativeEngine, QtCore.QUrl('qrc:/qml/qmlShell.qml'), self) if component.isReady(): self.qmlRoot = component.create() if self.qmlRoot is not None: self.qmlRoot.setHeight(window.scene.sceneRect().height()) self.qmlRoot.setWidth(window.scene.sceneRect().width()) self.qmlRoot.setZValue(101) self.qmlRoot.setCursor(QtCore.Qt.ArrowCursor) window.scene.addItem(self.qmlRoot) window.viewport().setFocusPolicy(QtCore.Qt.NoFocus) window.setFocusPolicy(QtCore.Qt.StrongFocus) window.scene.setStickyFocus(True) window.setFocus() else: Colors.debug( "Error initializing QML subsystem, Declarative examples will not work" )
def main(argv): app = QtGui.QApplication(argv) view = QtDeclarative.QDeclarativeView() colors = [ "red", "green", "blue" ] context = view.rootContext() context.setContextProperty("colorModel", colors) view.setSource(QtCore.QUrl("main.qml")) view.show() app.exec_()
def main(argv): app = QtGui.QApplication(argv) view = QtDeclarative.QDeclarativeView() view.setSource(QtCore.QUrl("main.qml")) messenger = Messenger() root = view.rootObject() root.messageRequested.connect(messenger.emit_message) messenger.message.connect(root.updateMessage) root.updateMessage("Hallo Welt!") view.show() app.exec_()
def main(argv): app = QtGui.QApplication(argv) view = QtDeclarative.QDeclarativeView() app.setOverrideCursor( QtGui.QCursor( QtCore.Qt.BlankCursor ) ) view.setSource(QtCore.QUrl("qml/main2.qml")) glw = QtOpenGL.QGLWidget() view.setViewport(glw) view.showFullScreen() #view.resize(800, 600) view.show() app.exec_()
def main(argv): app = QtGui.QApplication(argv) main = QtGui.QMainWindow() view = QtDeclarative.QDeclarativeView(main) view.setResizeMode(QtDeclarative.QDeclarativeView.SizeViewToRootObject) view.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn) view.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn) view.setSource(QtCore.QUrl("main2.qml")) main.setCentralWidget(view) main.resize(360, 480) main.show() app.exec_()
def setupUi(self, WaitScreen): WaitScreen.setObjectName(_fromUtf8("WaitScreen")) WaitScreen.resize(800, 480) self.declarativeView = QtDeclarative.QDeclarativeView(WaitScreen) self.declarativeView.setGeometry(QtCore.QRect(-1, -1, 800, 480)) self.declarativeView.setObjectName(_fromUtf8("declarativeView")) self.label = QtGui.QLabel(WaitScreen) self.label.setGeometry(QtCore.QRect(160, 140, 501, 161)) font = QtGui.QFont() font.setPointSize(20) font.setBold(True) font.setWeight(75) self.label.setFont(font) self.label.setAlignment(QtCore.Qt.AlignCenter) self.label.setObjectName(_fromUtf8("label")) self.retranslateUi(WaitScreen) QtCore.QMetaObject.connectSlotsByName(WaitScreen)
def tiles(self): return QtDeclarative.QPyDeclarativeListProperty(self, self._tiles)
t = self._tile(r, c) if t is not None and t.hasMine: hint += 1 return hint def _setPlaying(self, playing): if self._playing != playing: self._playing = playing self.isPlayingChanged.emit() if __name__ == '__main__': import sys app = QtGui.QApplication(sys.argv) canvas = QtDeclarative.QDeclarativeView() engine = canvas.engine() game = MinehuntGame() engine.rootContext().setContextObject(game) canvas.setSource(QtCore.QUrl.fromLocalFile('minehunt.qml')) engine.quit.connect(app.quit) canvas.setGeometry(QtCore.QRect(100, 100, 450, 450)) canvas.show() sys.exit(app.exec_())
def color(self): return self._color @color.setter def color(self, color): if self._color != color: self._color = color self.colorChanged.emit() if __name__ == '__main__': import sys app = QtGui.QApplication(sys.argv) dataList = [ DataObject("Item 1", 'red'), DataObject("Item 2", 'green'), DataObject("Item 3", 'blue'), DataObject("Item 4", 'yellow') ] view = QtDeclarative.QDeclarativeView() ctxt = view.rootContext() ctxt.setContextProperty('myModel', dataList) view.setSource(QtCore.QUrl('qrc:view.qml')) view.show() sys.exit(app.exec_())