PyQt Learning & Practice

Install

1
2
3
4
5
6
7
8
9
$ pip install PyQt5
Collecting PyQt5
Downloading https://files.pythonhosted.org/packages/43/cf/f89c7e632014cb8725fc30b36292ca709a5b5598e4e99fff09cb677fc898/PyQt5-5.15.1-5.15.1-cp35.cp36.cp37.cp38.cp39-none-win32.whl (51.2MB)
|████████████████████████████████| 51.2MB 117kB/s
Collecting PyQt5-sip<13,>=12.8 (from PyQt5)
Downloading https://files.pythonhosted.org/packages/69/eb/bb296c8a96eadacd5e91df3f5d600d9e4727b90e8b010cb86e146f995ce4/PyQt5_sip-12.8.1-cp37-cp37m-win32.whl (50kB)
|████████████████████████████████| 51kB 233kB/s
Installing collected packages: PyQt5-sip, PyQt5
Successfully installed PyQt5-5.15.1 PyQt5-sip-12.8.1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
$ pip install pyqt5-tools
Collecting pyqt5-tools
Downloading https://files.pythonhosted.org/packages/68/5b/202a0dbe7774f26be5ade0fa42cbd4cc6fc4dc5b19c824dfccf6160f8566/pyqt5_tools-5.15.1.1.7.4-cp37-cp37m-win32.whl (48.1MB)
|█ | 1.7MB 16kB/s eta 0:47:49ERROR: Exception:
Traceback (most recent call last):
File "c:\users\eshibij\appdata\local\programs\python\python37-32\lib\site-packages\pip\_vendor\urllib3\response.py", line 397, in _error_catcher
yield
File "c:\users\eshibij\appdata\local\programs\python\python37-32\lib\site-packages\pip\_vendor\urllib3\response.py", line 479, in read
data = self._fp.read(amt)
File "c:\users\eshibij\appdata\local\programs\python\python37-32\lib\site-packages\pip\_vendor\cachecontrol\filewrapper.py", line 62, in read
data = self.__fp.read(amt)
File "c:\users\eshibij\appdata\local\programs\python\python37-32\lib\http\client.py", line 457, in read
n = self.readinto(b)
File "c:\users\eshibij\appdata\local\programs\python\python37-32\lib\http\client.py", line 501, in readinto
n = self.fp.readinto(b)
File "c:\users\eshibij\appdata\local\programs\python\python37-32\lib\socket.py", line 589, in readinto
return self._sock.recv_into(b)
File "c:\users\eshibij\appdata\local\programs\python\python37-32\lib\ssl.py", line 1071, in recv_into
return self.read(nbytes, buffer)
File "c:\users\eshibij\appdata\local\programs\python\python37-32\lib\ssl.py", line 929, in read
return self._sslobj.read(len, buffer)
socket.timeout: The read operation timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "c:\users\eshibij\appdata\local\programs\python\python37-32\lib\site-packages\pip\_internal\cli\base_command.py", line 188, in main
status = self.run(options, args)
File "c:\users\eshibij\appdata\local\programs\python\python37-32\lib\site-packages\pip\_internal\commands\install.py", line 345, in run
resolver.resolve(requirement_set)
File "c:\users\eshibij\appdata\local\programs\python\python37-32\lib\site-packages\pip\_internal\legacy_resolve.py", line 196, in resolve
self._resolve_one(requirement_set, req)
File "c:\users\eshibij\appdata\local\programs\python\python37-32\lib\site-packages\pip\_internal\legacy_resolve.py", line 359, in _resolve_one
abstract_dist = self._get_abstract_dist_for(req_to_install)
File "c:\users\eshibij\appdata\local\programs\python\python37-32\lib\site-packages\pip\_internal\legacy_resolve.py", line 307, in _get_abstract_dist_for
self.require_hashes
File "c:\users\eshibij\appdata\local\programs\python\python37-32\lib\site-packages\pip\_internal\operations\prepare.py", line 199, in prepare_linked_requirement
progress_bar=self.progress_bar
File "c:\users\eshibij\appdata\local\programs\python\python37-32\lib\site-packages\pip\_internal\download.py", line 1064, in unpack_url
progress_bar=progress_bar
File "c:\users\eshibij\appdata\local\programs\python\python37-32\lib\site-packages\pip\_internal\download.py", line 924, in unpack_http_url
progress_bar)
File "c:\users\eshibij\appdata\local\programs\python\python37-32\lib\site-packages\pip\_internal\download.py", line 1152, in _download_http_url
_download_url(resp, link, content_file, hashes, progress_bar)
File "c:\users\eshibij\appdata\local\programs\python\python37-32\lib\site-packages\pip\_internal\download.py", line 861, in _download_url
hashes.check_against_chunks(downloaded_chunks)
File "c:\users\eshibij\appdata\local\programs\python\python37-32\lib\site-packages\pip\_internal\utils\hashes.py", line 75, in check_against_chunks
for chunk in chunks:
File "c:\users\eshibij\appdata\local\programs\python\python37-32\lib\site-packages\pip\_internal\download.py", line 829, in written_chunks
for chunk in chunks:
File "c:\users\eshibij\appdata\local\programs\python\python37-32\lib\site-packages\pip\_internal\utils\ui.py", line 156, in iter
for x in it:
File "c:\users\eshibij\appdata\local\programs\python\python37-32\lib\site-packages\pip\_internal\download.py", line 818, in resp_read
decode_content=False):
File "c:\users\eshibij\appdata\local\programs\python\python37-32\lib\site-packages\pip\_vendor\urllib3\response.py", line 531, in stream
data = self.read(amt=amt, decode_content=decode_content)
File "c:\users\eshibij\appdata\local\programs\python\python37-32\lib\site-packages\pip\_vendor\urllib3\response.py", line 496, in read
raise IncompleteRead(self._fp_bytes_read, self.length_remaining)
File "c:\users\eshibij\appdata\local\programs\python\python37-32\lib\contextlib.py", line 130, in __exit__
self.gen.throw(type, value, traceback)
File "c:\users\eshibij\appdata\local\programs\python\python37-32\lib\site-packages\pip\_vendor\urllib3\response.py", line 402, in _error_catcher
raise ReadTimeoutError(self._pool, None, 'Read timed out.')
pip._vendor.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Read timed out.
WARNING: You are using pip version 19.2.3, however version 20.2.4 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.

rerun the install cmd, then finished with:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
$ pip install pyqt5-tools
Collecting pyqt5-tools
Downloading https://files.pythonhosted.org/packages/68/5b/202a0dbe7774f26be5ade0fa42cbd4cc6fc4dc5b19c824dfccf6160f8566/pyqt5_tools-5.15.1.1.7.4-cp37-cp37m-win32.whl (48.1MB)
|████████████████████████████████| 48.1MB 656kB/s
Collecting python-dotenv (from pyqt5-tools)
Downloading https://files.pythonhosted.org/packages/f2/16/28d434b28c5be29a6af8fd0e3a2bda3bd30500ef0cd17bc79f7a6793a8d4/python_dotenv-0.14.0-py2.py3-none-any.whl
Collecting click (from pyqt5-tools)
Downloading https://files.pythonhosted.org/packages/d2/3d/fa76db83bf75c4f8d338c2fd15c8d33fdd7ad23a9b5e57eb6c5de26b430e/click-7.1.2-py2.py3-none-any.whl (82kB)
|████████████████████████████████| 92kB 590kB/s
Requirement already satisfied: pyqt5==5.15.1 in c:\users\eshibij\appdata\local\programs\python\python37-32\lib\site-packages (from pyqt5-tools) (5.15.1)
Requirement already satisfied: PyQt5-sip<13,>=12.8 in c:\users\eshibij\appdata\local\programs\python\python37-32\lib\site-packages (from pyqt5==5.15.1->pyqt5-tools) (12.8.1)
Installing collected packages: python-dotenv, click, pyqt5-tools
Successfully installed click-7.1.2 pyqt5-tools-5.15.1.1.7.4 python-dotenv-0.14.0
WARNING: You are using pip version 19.2.3, however version 20.2.4 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.

check if successfully installed:
win + s and search with designer, then callout the Qt tool GUI.

ref: https://blog.csdn.net/azuremouse/article/details/90338961

Widget

  1. QtCore.QRect
    (x, y, width, height)
    x, y为widget相对于父widget的左上角坐标,以此点为起点,向右width,向下height

Layout