PyQt5使用QStackedwidget

QListWidget和QStackedWidget在ui文件中.

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
# -*- coding:utf-8 -*-
import os
import functools
from PyQt5 import uic
from PyQt5 import QtWidgets
from utils import loadJson
from page1 import ControlPanel
from utils import loadJson
class ControlPanel2(QtWidgets.QWidget):
def __init__(self, parent=None):
super(ControlPanel2, self).__init__(parent)
self._config = loadJson()
self.ctrlpanelWidth = self._config['controlpanel']['width']
self.ctrlpanelHeight = self._config['controlpanel']['height']
self.ctrl_panel = ControlPanel()
self.initUI()
def initUI(self):
self.ui = uic.loadUi(os.path.join(
os.path.dirname(__file__), "res/ctrlpanel.ui"), self)
self.setFixedSize(self.ctrlpanelWidth, self.ctrlpanelHeight)
for i, key in enumerate(sorted(self._config["panels"].keys())):
item = QtWidgets.QListWidgetItem(self.ui.panellist)
item.setText(key)
self.ui.panellist.insertItem(i, item)
self.ui.stackedWidget.insertWidget(i, QtWidgets.QLabel("{}".format(key)))
# 设置qss
self.setStyleSheet(
"QListWidget::item{width: 65px; height: 35px; text-align: center;}")
self.ui.panellist.setCurrentRow(0)
self.ui.stackedWidget.setCurrentIndex(0)
self.ui.panellist.currentRowChanged.connect(self.on_showPage)
def on_showPage(self, index):
# index = self.ui.panellist.currentIndex()
print("current index =", index)
self.ui.stackedWidget.setCurrentIndex(index)

阅读全文

PyQt5长按按钮循环执行命令

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
66
67
68
# -*- coding:utf-8 -*-
import os
import time
import functools
from PyQt5 import uic
from PyQt5 import QtWidgets
from utils import loadJson
from punggol_rpc import punggol_exec
class ControlPanel(QtWidgets.QWidget):
def __init__(self, parent=None):
super(ControlPanel, self).__init__(parent)
self._config = loadJson()
self.ctrlpanelWidth = self._config['controlpanel']['width']
self.ctrlpanelHeight = self._config['controlpanel']['height']
self.initUI()
def initUI(self):
self.ui = uic.loadUi(os.path.join(
os.path.dirname(__file__), "res/ctrlpanel.ui"), self)
self.setFixedSize(self.ctrlpanelWidth, self.ctrlpanelHeight)
for attr in dir(self.ui):
obj = getattr(self.ui, attr)
if isinstance(obj, QtWidgets.QPushButton) or \
isinstance(obj, QtWidgets.QToolButton):
obj.setAutoRepeat(True)
obj._repeate = False
obj.clicked.connect(
functools.partial(self.on_handleClicked, obj))
def on_handleClicked(self, btn):
if btn.isDown():
if btn._repeate is False:
btn._repeate = True
btn.setAutoRepeatInterval(50)
else:
self.on_pressed(btn)
elif btn._repeate is True:
btn._repeate = False
self.on_released(btn)
else:
self.on_clicked(btn)
def on_clicked(self, btn):
try:
if btn.property("clicked_cmd") is not None:
punggol_exec(btn.property("clicked_cmd"))
except Exception as e:
print(e)
return
def on_pressed(self, btn):
try:
if btn.property("pressed_cmd") is not None:
punggol_exec(btn.property("pressed_cmd"))
except Exception as e:
print(e)
return
def on_released(self, btn):
try:
if btn.property("released_cmd") is not None:
punggol_exec(btn.property("released_cmd"))
except Exception as e:
print(e)
return

阅读全文

Python删除windows下的目录

windows启动目录:C:\Users\aron\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup
在windows下启动目录下添加一个killkingsoft.py脚本,然后每次开机自动执行该脚本.
注意:在windows下启动目录下的脚本或者bat文件都会在开机时自动执行.

阅读全文

Python使用cx_freeze打包应用程序

python应用程序打包

python下应用程序打包有py2exe, pyinstaller和cx_freeze这3个第三方库,

阅读全文

PyQt5添加动态属性及访问

在ui文件中添加动态属性

如下图所示:在属性编辑器中点击”+”按钮, 添加的属性有很多类型,一般选择string或者ByteArray, 最好选择ByteArray,如果选择string还会涉及到需要翻译的问题.

阅读全文