From c92f425fa401b5b1ca4daac860ab4146c3d3efa6 Mon Sep 17 00:00:00 2001 From: Nathan Hughes Date: Fri, 16 Sep 2016 12:52:03 +0100 Subject: [pyqt/en] I've done a small example for getting started with the QT framework in python (#2364) * Added a pyqt example page * Fixed a spelling mistake on the pyqt examples * Added link to C++ version author * Fixed a truncation of text issue * Ready to submit initial version for PR * Too many new lines --- pyqt.html.markdown | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 pyqt.html.markdown (limited to 'pyqt.html.markdown') diff --git a/pyqt.html.markdown b/pyqt.html.markdown new file mode 100644 index 00000000..cf11ca23 --- /dev/null +++ b/pyqt.html.markdown @@ -0,0 +1,84 @@ +--- +category: tool +tool: Qt Framework +language: pyqt +filename: learnqt.py +contributors: + - ["Nathan Hughes", "https://github.com/sirsharpest"] +lang: en +--- + +**Qt** is a widely-known framework for developing cross-platform software that can be run on various software and hardware platforms with little or no change in the code, while having the power and speed of native applications. Though **Qt** was originally written in *C++*. + + +This is an adaption on the C++ intro to QT by [Aleksey Kholovchuk](https://github.com/vortexxx192 +), some of the code examples should result in the same functionality +this version just having been done using pyqt! + +```Python +import sys +from PyQt4 import QtGui + +def window(): + # Create an application object + app = QtGui.QApplication(sys.argv) + # Create a widget where our label will be placed in + w = QtGui.QWidget() + # Add a label to the widget + b = QtGui.QLabel(w) + # Set some text for the label + b.setText("Hello World!") + # Give some size and placement information + w.setGeometry(100, 100, 200, 50) + b.move(50, 20) + # Give our window a nice title + w.setWindowTitle("PyQt") + # Have everything display + w.show() + # Execute what we have asked for, once all setup + sys.exit(app.exec_()) + +if __name__ == '__main__': + window() + +``` + +In order to get some of the more advanced features in **pyqt** we need to start looking at building additional elements. +Here we show how to introduce a dialog popup box, useful for asking the user to confirm a decision or to provide information. + +```Python +import sys +from PyQt4.QtGui import * +from PyQt4.QtCore import * + + +def window(): + app = QApplication(sys.argv) + w = QWidget() + # Create a button and attach to widget w + b = QPushButton(w) + b.setText("Press me") + b.move(50, 50) + # Tell b to call this function when clicked + # notice the lack of "()" on the function call + b.clicked.connect(showdialog) + w.setWindowTitle("PyQt Dialog") + w.show() + sys.exit(app.exec_()) + +# This function should create a dialog window with a button +# that waits to be clicked and then exits the program +def showdialog(): + d = QDialog() + b1 = QPushButton("ok", d) + b1.move(50, 50) + d.setWindowTitle("Dialog") + # This modality tells the popup to block the parent whilst it's active + d.setWindowModality(Qt.ApplicationModal) + # On click I'd like the entire process to end + b1.clicked.connect(sys.exit) + d.exec_() + +if __name__ == '__main__': + window() +``` -- cgit v1.2.3 From 38ed5c10549cf1b5c99dcabb3a4c3d3b1ae0c0c5 Mon Sep 17 00:00:00 2001 From: Nathan Hughes Date: Fri, 16 Sep 2016 15:02:48 +0100 Subject: Fixed a bad naming which overlapped with C++ version (#2376) --- pyqt.html.markdown | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'pyqt.html.markdown') diff --git a/pyqt.html.markdown b/pyqt.html.markdown index cf11ca23..2158b37f 100644 --- a/pyqt.html.markdown +++ b/pyqt.html.markdown @@ -1,7 +1,7 @@ --- category: tool -tool: Qt Framework -language: pyqt +tool: PyQT +language: Python filename: learnqt.py contributors: - ["Nathan Hughes", "https://github.com/sirsharpest"] -- cgit v1.2.3 From 6977b86db77fb52cf0aed278ff9b543eb2e4e43d Mon Sep 17 00:00:00 2001 From: ven Date: Wed, 5 Oct 2016 09:21:37 +0200 Subject: try to fix #2417 --- pyqt.html.markdown | 1 - 1 file changed, 1 deletion(-) (limited to 'pyqt.html.markdown') diff --git a/pyqt.html.markdown b/pyqt.html.markdown index 2158b37f..7ce71d96 100644 --- a/pyqt.html.markdown +++ b/pyqt.html.markdown @@ -1,7 +1,6 @@ --- category: tool tool: PyQT -language: Python filename: learnqt.py contributors: - ["Nathan Hughes", "https://github.com/sirsharpest"] -- cgit v1.2.3 From 5eda755a8f85c1ccafd1b17b21f485e6869b506e Mon Sep 17 00:00:00 2001 From: Hughes Perreault Date: Sat, 15 Oct 2016 16:09:33 -0400 Subject: useless "lang: en" (#2462) trying to fix #2417 --- pyqt.html.markdown | 1 - 1 file changed, 1 deletion(-) (limited to 'pyqt.html.markdown') diff --git a/pyqt.html.markdown b/pyqt.html.markdown index 7ce71d96..c317db1b 100644 --- a/pyqt.html.markdown +++ b/pyqt.html.markdown @@ -4,7 +4,6 @@ tool: PyQT filename: learnqt.py contributors: - ["Nathan Hughes", "https://github.com/sirsharpest"] -lang: en --- **Qt** is a widely-known framework for developing cross-platform software that can be run on various software and hardware platforms with little or no change in the code, while having the power and speed of native applications. Though **Qt** was originally written in *C++*. -- cgit v1.2.3 From cf2b75018645aaefe586537ef21f9f698986783d Mon Sep 17 00:00:00 2001 From: ven Date: Sun, 23 Oct 2016 14:24:50 +0200 Subject: try to fix (again) #2496 --- pyqt.html.markdown | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'pyqt.html.markdown') diff --git a/pyqt.html.markdown b/pyqt.html.markdown index c317db1b..6bdb6488 100644 --- a/pyqt.html.markdown +++ b/pyqt.html.markdown @@ -1,7 +1,7 @@ --- category: tool tool: PyQT -filename: learnqt.py +filename: learnpyqt.py contributors: - ["Nathan Hughes", "https://github.com/sirsharpest"] --- @@ -13,7 +13,7 @@ This is an adaption on the C++ intro to QT by [Aleksey Kholovchuk](https://githu ), some of the code examples should result in the same functionality this version just having been done using pyqt! -```Python +```python import sys from PyQt4 import QtGui -- cgit v1.2.3