Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Damn ImageViewer by PyQt5 and QtQuick.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
from os.path import (
join,
dirname,
)
from PyQt5.QtCore import QUrl
from PyQt5.QtGui import QGuiApplication
from PyQt5.QtQuick import QQuickView
app = QGuiApplication(sys.argv)
view = QQuickView()
view.engine().quit.connect(app.quit)
view.rootContext().setContextProperty("imageUrl", sys.argv[1]);
url = QUrl(join(dirname(__file__), 'qqimageviewer.qml'))
view.setSource(url)
view.show()
sys.exit(app.exec_())
import QtQuick 2.0
Rectangle {
id: imageViewer
width: 400
height: 300
Image {
id: view
clip: true
sourceSize.width: 0
anchors.fill: parent
source: imageUrl
}
Rectangle {
id: closeButton
width: 100
height: 100
color: 'gray'
anchors.right: parent.right
MouseArea {
anchors.fill: parent
onPressed: {
Qt.quit()
}
}
Text {
text: 'close'
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
wrapMode: Text.NoWrap
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment