Skip to content

Commit 151ba3f

Browse files
committed
update
1 parent b910d43 commit 151ba3f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+184
-7366
lines changed

Donate/README.md

-3
This file was deleted.

菜单/菜单多选不关闭.py renamed to QMenu/MultiSelect.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
@author: Irony
77
@site: https://github.com/892768447
88
@email: 892768447@qq.com
9-
@file: 菜单多选不关闭
9+
@file: MultiSelect
1010
@description:
1111
"""
1212
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QLabel, QPushButton, QMenu,\

菜单/README.md renamed to QMenu/README.md

+7-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
# 菜单 QMenu
1+
# QMenu
22

3-
## [1、菜单设置多选并且不关闭](菜单多选不关闭.py)
3+
## 1、菜单设置多选并且不关闭
4+
[运行 MultiSelect.py](MultiSelect.py)
45

56
有时候会遇到这种需求:在界面某个位置弹出一个菜单,其中里面的菜单项可以多选(类似配置选项),
67
此时用QMenu会遇到点击一个菜单项就会自动关闭,当然可以通过其他方式实现该功能,
@@ -13,9 +14,9 @@
1314
原理:
1415

1516
1. 设置菜单项可勾选:通过`QAction.setCheckable(True)`方法实现
16-
1. 设置菜单不可关闭:通过覆盖`QMenu`的鼠标释放`mouseReleaseEvent`方法(可直接替换或者通过`installEventFilter`安装事件过滤器实现)
17-
1. 在菜单的鼠标释放事件中,当点击菜单项后是通过点击点坐标来查找是否有`QAction`,然后触发对应的`QAction`
18-
1. 故在没有`QAction`的地方则直接交还给`QMenu`自行处理逻辑,在有`QAction`的地方可以根据自己的需求进行处理(如上所提)
17+
2. 设置菜单不可关闭:通过覆盖`QMenu`的鼠标释放`mouseReleaseEvent`方法(可直接替换或者通过`installEventFilter`安装事件过滤器实现)
18+
3. 在菜单的鼠标释放事件中,当点击菜单项后是通过点击点坐标来查找是否有`QAction`,然后触发对应的`QAction`
19+
4. 故在没有`QAction`的地方则直接交还给`QMenu`自行处理逻辑,在有`QAction`的地方可以根据自己的需求进行处理(如上所提)
1920

2021
核心代码:
2122

@@ -31,6 +32,4 @@ def _menu_mouseReleaseEvent(self, event):
3132
action.activate(action.Trigger)
3233
```
3334

34-
效果图:
35-
36-
![截图](ScreenShot/菜单多选不关闭.gif)
35+
![MultiSelect](ScreenShot/MultiSelect.gif)

滑动条/滑动条点击定位.py renamed to QSlider/ClickJumpSlider.py

+11-10
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
@author: Irony
77
@site: https://pyqt5.com https://github.com/892768447
88
@email: 892768447@qq.com
9-
@file: Widgets.JumpSlider
9+
@file: ClickJumpSlider
1010
@description:
1111
"""
1212
from PyQt5.QtCore import Qt
@@ -21,7 +21,7 @@
2121
__Version__ = "Version 1.0"
2222

2323

24-
class JumpSlider(QSlider):
24+
class ClickJumpSlider(QSlider):
2525

2626
def mousePressEvent(self, event):
2727
# 获取上面的拉动块位置
@@ -31,7 +31,7 @@ def mousePressEvent(self, event):
3131
QStyle.CC_Slider, option, QStyle.SC_SliderHandle, self)
3232
if rect.contains(event.pos()):
3333
# 如果鼠标点击的位置在滑块上则交给Qt自行处理
34-
super(JumpSlider, self).mousePressEvent(event)
34+
super(ClickJumpSlider, self).mousePressEvent(event)
3535
return
3636
if self.orientation() == Qt.Horizontal:
3737
# 横向,要考虑invertedAppearance是否反向显示的问题
@@ -47,29 +47,30 @@ def mousePressEvent(self, event):
4747
) else event.y(), self.height()))
4848

4949

50-
class TestWindow(QWidget):
50+
class DemoWindow(QWidget):
5151

5252
def __init__(self, *args, **kwargs):
53-
super(TestWindow, self).__init__(*args, **kwargs)
53+
super(DemoWindow, self).__init__(*args, **kwargs)
54+
self.resize(600, 600)
5455
layout = QFormLayout(self)
5556

5657
self.label1 = QLabel('0', self)
57-
layout.addRow(self.label1, JumpSlider(
58+
layout.addRow(self.label1, ClickJumpSlider(
5859
Qt.Horizontal, valueChanged=lambda v: self.label1.setText(str(v))))
5960

6061
# 横向-反向显示
6162
self.label2 = QLabel('0', self)
62-
layout.addRow(self.label2, JumpSlider(
63+
layout.addRow(self.label2, ClickJumpSlider(
6364
Qt.Horizontal, invertedAppearance=True,
6465
valueChanged=lambda v: self.label2.setText(str(v))))
6566

6667
self.label3 = QLabel('0', self)
67-
layout.addRow(self.label3, JumpSlider(
68+
layout.addRow(self.label3, ClickJumpSlider(
6869
Qt.Vertical, minimumHeight=200, valueChanged=lambda v: self.label3.setText(str(v))))
6970

7071
# 纵向反向显示
7172
self.label4 = QLabel('0', self)
72-
layout.addRow(self.label4, JumpSlider(
73+
layout.addRow(self.label4, ClickJumpSlider(
7374
Qt.Vertical, invertedAppearance=True,
7475
minimumHeight=200, valueChanged=lambda v: self.label4.setText(str(v))))
7576

@@ -80,6 +81,6 @@ def __init__(self, *args, **kwargs):
8081
sys.excepthook = cgitb.enable(1, None, 5, '')
8182
from PyQt5.QtWidgets import QApplication
8283
app = QApplication(sys.argv)
83-
w = TestWindow()
84+
w = DemoWindow()
8485
w.show()
8586
sys.exit(app.exec_())

QSlider/README.md

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# QSlider
2+
3+
## 1、滑动条点击定位
4+
[运行 ClickJumpSlider.py](ClickJumpSlider.py)
5+
6+
1. `QSlider`对鼠标点击然后跳转到该位置的支持不是很好,通过重写鼠标点击事件`mousePressEvent`来达到效果
7+
2. 通过`style``subControlRect`方法计算得到滑块的区域,当鼠标点击区域在此次时则交给系统自己处理(比如按住不放拖动)
8+
3. 通过`orientation`判断滑动条的方向(横竖)
9+
4. 通过`invertedAppearance`判断滑动条是否反向(左右、上下)
10+
11+
```python
12+
def mousePressEvent(self, event):
13+
# 获取上面的拉动块位置
14+
option = QStyleOptionSlider()
15+
self.initStyleOption(option)
16+
rect = self.style().subControlRect(
17+
QStyle.CC_Slider, option, QStyle.SC_SliderHandle, self)
18+
if rect.contains(event.pos()):
19+
# 如果鼠标点击的位置在滑块上则交给Qt自行处理
20+
super(JumpSlider, self).mousePressEvent(event)
21+
return
22+
if self.orientation() == Qt.Horizontal:
23+
# 横向,要考虑invertedAppearance是否反向显示的问题
24+
self.setValue(self.style().sliderValueFromPosition(
25+
self.minimum(), self.maximum(),
26+
event.x() if not self.invertedAppearance() else (self.width(
27+
) - event.x()), self.width()))
28+
else:
29+
# 纵向
30+
self.setValue(self.style().sliderValueFromPosition(
31+
self.minimum(), self.maximum(),
32+
(self.height() - event.y()) if not self.invertedAppearance(
33+
) else event.y(), self.height()))
34+
```
35+
36+
![ClickJumpSlider](ScreenShot/ClickJumpSlider.gif)
File renamed without changes.

QTableView/CopyContent/__main__.py

-30
This file was deleted.

QTableView/README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
# QTableView
22

3-
## [1、表格内容复制](CopyContent)
3+
## 1、表格内容复制
4+
[运行 CopyContent.py](CopyContent.py)
45

56
1. 通过构造一个和选中区域一样的空数组,然后对数组进行填充形成表格
67
1. 最后循环数组用`\t`进行拼接`join`,换行用`\r\n`
78
1. 把字符串复制到剪切板中
89

9-
![截图](ScreenShot/CopyContent1.png)![截图](ScreenShot/CopyContent2.png)
10+
![CopyContent1](ScreenShot/CopyContent1.png) ![CopyContent2](ScreenShot/CopyContent2.png)
1011

File renamed without changes.
File renamed without changes.

QTableWidget/README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# QTableWidget
22

3-
## [1、Sqlalchemy动态拼接字段查询显示表格](SqlQuery)
3+
## 1、Sqlalchemy动态拼接字段查询显示表格
4+
[运行 SqlQuery.py](SqlQuery.py)
45

56
通过判断界面中选择的条件对`Sqlalchemy``model`进行字段拼接从而实现按条件查询
67

7-
![截图](ScreenShot/SqlQuery.png)
8+
![SqlQuery](ScreenShot/SqlQuery.png)

QTableWidget/SqlQuery/SqlQuery.py renamed to QTableWidget/SqlQuery.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from sqlalchemy.sql.expression import and_
1818
from sqlalchemy.sql.schema import Column
1919
from sqlalchemy.sql.sqltypes import Integer, Text
20-
from mainui import Ui_Form
20+
from Lib.mainui import Ui_Form
2121

2222
__Author__ = """By: Irony
2323
QQ: 892768447
@@ -26,7 +26,7 @@
2626
__Version__ = "Version 1.0"
2727

2828
# engine = create_engine('mysql+mysqldb://root@localhost:3306/tourist?charset=utf8')
29-
engine = create_engine('sqlite:///data.sqlite3', echo=True) # echo 表示开启命令显示
29+
engine = create_engine('sqlite:///Data/data.sqlite3', echo=True) # echo 表示开启命令显示
3030
Base = declarative_base()
3131

3232

QTableWidget/SqlQuery/__main__.py

-29
This file was deleted.

QTableWidget/SqlQuery/mainui.py

-111
This file was deleted.

0 commit comments

Comments
 (0)