forked from PyQt5/PyQt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
51 changed files
with
184 additions
and
7,366 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
@author: Irony | ||
@site: https://github.com/892768447 | ||
@email: [email protected] | ||
@file: 菜单多选不关闭 | ||
@file: MultiSelect | ||
@description: | ||
""" | ||
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QLabel, QPushButton, QMenu,\ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
@author: Irony | ||
@site: https://pyqt5.com https://github.com/892768447 | ||
@email: [email protected] | ||
@file: Widgets.JumpSlider | ||
@file: ClickJumpSlider | ||
@description: | ||
""" | ||
from PyQt5.QtCore import Qt | ||
|
@@ -21,7 +21,7 @@ | |
__Version__ = "Version 1.0" | ||
|
||
|
||
class JumpSlider(QSlider): | ||
class ClickJumpSlider(QSlider): | ||
|
||
def mousePressEvent(self, event): | ||
# 获取上面的拉动块位置 | ||
|
@@ -31,7 +31,7 @@ def mousePressEvent(self, event): | |
QStyle.CC_Slider, option, QStyle.SC_SliderHandle, self) | ||
if rect.contains(event.pos()): | ||
# 如果鼠标点击的位置在滑块上则交给Qt自行处理 | ||
super(JumpSlider, self).mousePressEvent(event) | ||
super(ClickJumpSlider, self).mousePressEvent(event) | ||
return | ||
if self.orientation() == Qt.Horizontal: | ||
# 横向,要考虑invertedAppearance是否反向显示的问题 | ||
|
@@ -47,29 +47,30 @@ def mousePressEvent(self, event): | |
) else event.y(), self.height())) | ||
|
||
|
||
class TestWindow(QWidget): | ||
class DemoWindow(QWidget): | ||
|
||
def __init__(self, *args, **kwargs): | ||
super(TestWindow, self).__init__(*args, **kwargs) | ||
super(DemoWindow, self).__init__(*args, **kwargs) | ||
self.resize(600, 600) | ||
layout = QFormLayout(self) | ||
|
||
self.label1 = QLabel('0', self) | ||
layout.addRow(self.label1, JumpSlider( | ||
layout.addRow(self.label1, ClickJumpSlider( | ||
Qt.Horizontal, valueChanged=lambda v: self.label1.setText(str(v)))) | ||
|
||
# 横向-反向显示 | ||
self.label2 = QLabel('0', self) | ||
layout.addRow(self.label2, JumpSlider( | ||
layout.addRow(self.label2, ClickJumpSlider( | ||
Qt.Horizontal, invertedAppearance=True, | ||
valueChanged=lambda v: self.label2.setText(str(v)))) | ||
|
||
self.label3 = QLabel('0', self) | ||
layout.addRow(self.label3, JumpSlider( | ||
layout.addRow(self.label3, ClickJumpSlider( | ||
Qt.Vertical, minimumHeight=200, valueChanged=lambda v: self.label3.setText(str(v)))) | ||
|
||
# 纵向反向显示 | ||
self.label4 = QLabel('0', self) | ||
layout.addRow(self.label4, JumpSlider( | ||
layout.addRow(self.label4, ClickJumpSlider( | ||
Qt.Vertical, invertedAppearance=True, | ||
minimumHeight=200, valueChanged=lambda v: self.label4.setText(str(v)))) | ||
|
||
|
@@ -80,6 +81,6 @@ def __init__(self, *args, **kwargs): | |
sys.excepthook = cgitb.enable(1, None, 5, '') | ||
from PyQt5.QtWidgets import QApplication | ||
app = QApplication(sys.argv) | ||
w = TestWindow() | ||
w = DemoWindow() | ||
w.show() | ||
sys.exit(app.exec_()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# QSlider | ||
|
||
## 1、滑动条点击定位 | ||
[运行 ClickJumpSlider.py](ClickJumpSlider.py) | ||
|
||
1. `QSlider`对鼠标点击然后跳转到该位置的支持不是很好,通过重写鼠标点击事件`mousePressEvent`来达到效果 | ||
2. 通过`style`的`subControlRect`方法计算得到滑块的区域,当鼠标点击区域在此次时则交给系统自己处理(比如按住不放拖动) | ||
3. 通过`orientation`判断滑动条的方向(横竖) | ||
4. 通过`invertedAppearance`判断滑动条是否反向(左右、上下) | ||
|
||
```python | ||
def mousePressEvent(self, event): | ||
# 获取上面的拉动块位置 | ||
option = QStyleOptionSlider() | ||
self.initStyleOption(option) | ||
rect = self.style().subControlRect( | ||
QStyle.CC_Slider, option, QStyle.SC_SliderHandle, self) | ||
if rect.contains(event.pos()): | ||
# 如果鼠标点击的位置在滑块上则交给Qt自行处理 | ||
super(JumpSlider, self).mousePressEvent(event) | ||
return | ||
if self.orientation() == Qt.Horizontal: | ||
# 横向,要考虑invertedAppearance是否反向显示的问题 | ||
self.setValue(self.style().sliderValueFromPosition( | ||
self.minimum(), self.maximum(), | ||
event.x() if not self.invertedAppearance() else (self.width( | ||
) - event.x()), self.width())) | ||
else: | ||
# 纵向 | ||
self.setValue(self.style().sliderValueFromPosition( | ||
self.minimum(), self.maximum(), | ||
(self.height() - event.y()) if not self.invertedAppearance( | ||
) else event.y(), self.height())) | ||
``` | ||
|
||
 |
File renamed without changes
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
# QTableView | ||
|
||
## [1、表格内容复制](CopyContent) | ||
## 1、表格内容复制 | ||
[运行 CopyContent.py](CopyContent.py) | ||
|
||
1. 通过构造一个和选中区域一样的空数组,然后对数组进行填充形成表格 | ||
1. 最后循环数组用`\t`进行拼接`join`,换行用`\r\n` | ||
1. 把字符串复制到剪切板中 | ||
|
||
 | ||
  | ||
|
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
# QTableWidget | ||
|
||
## [1、Sqlalchemy动态拼接字段查询显示表格](SqlQuery) | ||
## 1、Sqlalchemy动态拼接字段查询显示表格 | ||
[运行 SqlQuery.py](SqlQuery.py) | ||
|
||
通过判断界面中选择的条件对`Sqlalchemy`的`model`进行字段拼接从而实现按条件查询 | ||
|
||
 | ||
 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.