pyqt / examples Goto Github PK
View Code? Open in Web Editor NEWLearn to create a desktop app with Python and Qt
Learn to create a desktop app with Python and Qt
.
At least on my linux PyQt6 it just does not run.
instead of QPalette need QPalette.ColorRole
qt.white does not work I settled on QColorConstants.White
QColorConstants.Red etc.
I added QColorConstants, QAction, QKeySequence to the
from PyQt6.QtGui import
I made a video course for Packt on Reactive programming with Python and it included a bunch of code for using PyQt5 as well:
The example is a bit bigger than just showcasing one widget, it would be nice to include a link to https://github.com/rudolfolah/Reactive-Programming-in-Python/blob/master/Section%206/client/
Alternatively, I could create a PR that simplifies that example further but still gives devs an opportunity to see an example of using multiple PyQt widgets with multiple windows/forms/layouts.
Should maybe be mentioned in the README.
See: https://stackoverflow.com/questions/44274151/pyside2-on-windows
(venv) C:\Users\X\Documents\Python Scripts\pyside>pip install PySide2
ERROR: Could not find a version that satisfies the requirement PySide2 (from versions: none)
ERROR: No matching distribution found for PySide2
Followed the instructions, the first example works. Trying the 06 QML Python example returns an error.
(venv) C:\Users\X\Documents\Python Scripts\qtexamples\src\01 PyQt QLabel>cd "C:\Users\User\Documents\Python Scripts\qtexamples\src\06 QML Python example"
(venv) C:\Users\X\Documents\Python Scripts\qtexamples\src\06 QML Python example>python main.py
QQmlApplicationEngine failed to load component
file:///C:/Users/X/Documents/Python Scripts/qtexamples/src/06 QML Python example/main.qml:1 plugin cannot be loaded for module "QtQuick": Cannot load library C:\Users\X\Documents\Python Scripts\qtexamples\venv\lib\site-packages\PyQt5\Qt\qml\QtQuick.2\qtquick2plugin.dll: The specified procedure could not be found.
Hi,
When I tried running Qt Designer on macOs, it gives error saying
macOS cannot verify that this app is free from malware.
This item is on the disk image “Qt Designer.dmg”. Safari downloaded this disk image today at 2:25 pm from build-system.fman.io.
I'm coming from the Book "Python and Qt - The Best Parts". I don't know if this is the right spot for this issue, but it is mainly about the book.
This book uses the examples in this repo. There's one example how to use QML with PyQt. Then later on fbs is being added to the stack. Now I wanted to combine both but fell on my nose doing so.
If you use QML like in the example and add fbs to it, the frozen app won't do anything. It starts a UI process but doesn't open a window. In that situation you have to kill that process, or you can't freeze the project again, because the .exe
is still running in the background. By fiddling around I found what the problem is:
The frozen app has no copy of the .qml
file. So, it can't load it. You need to move it into the src/main/resources/base
folder and load it like so:
engine = QQmlApplicationEngine()
engine.load(app_context.get_resource('window.qml'))
Freezing the project like this makes the frozen executable run as expected.
Yes, you can combine the information from the book to come to this solution. But I think it should be mentioned explicitly that you have to use .get_resource()
for .qml
files, too.
In Pyqt6 QAction was moved to QtGui, QKeySequence requires the StandardKey addition
from PyQt6.QtWidgets import *
from PyQt6.QtGui import QKeySequence, QAction
class MainWindow(QMainWindow):
def closeEvent(self, e):
if not text.document().isModified():
return
answer = QMessageBox.question(
window, None,
"You have unsaved changes. Save before closing?",
QMessageBox.Save | QMessageBox.Discard | QMessageBox.Cancel
)
if answer & QMessageBox.Save:
save()
if text.document().isModified():
# This happens when the user closes the Save As... dialog.
# We do not want to close the window in this case because it
# would throw away unsaved changes.
e.ignore()
elif answer & QMessageBox.Cancel:
e.ignore()
app = QApplication([])
app.setApplicationName("Text Editor")
text = QPlainTextEdit()
window = MainWindow()
window.setCentralWidget(text)
file_path = None
menu = window.menuBar().addMenu("&File")
open_action = QAction("&Open")
def open_file():
global file_path
path = QFileDialog.getOpenFileName(window, "Open")[0]
if path:
text.setPlainText(open(path).read())
file_path = path
open_action.triggered.connect(open_file)
open_action.setShortcut(QKeySequence.StandardKey.Open)
menu.addAction(open_action)
save_action = QAction("&Save")
def save():
if file_path is None:
save_as()
else:
with open(file_path, "w") as f:
f.write(text.toPlainText())
text.document().setModified(False)
save_action.triggered.connect(save)
save_action.setShortcut(QKeySequence.StandardKey.Save)
menu.addAction(save_action)
save_as_action = QAction("Save &As...")
def save_as():
global file_path
path = QFileDialog.getSaveFileName(window, "Save As")[0]
if path:
file_path = path
save()
save_as_action.triggered.connect(save_as)
menu.addAction(save_as_action)
close = QAction("&Close")
close.triggered.connect(window.close)
menu.addAction(close)
help_menu = window.menuBar().addMenu("&Help")
about_action = QAction("&About")
help_menu.addAction(about_action)
def show_about_dialog():
text = "<center>" \
"<h1>Text Editor</h1>" \
"⁣" \
"<img src=icon.svg>" \
"</center>" \
"<p>Version 31.4.159.265358<br/>" \
"Copyright © Company Inc.</p>"
QMessageBox.about(window, "About Text Editor", text)
about_action.triggered.connect(show_about_dialog)
window.show()
app.exec()
I am making a software and gonna distribute it (for free),so still I need to buy a licence from riverbank?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.