-
-
Notifications
You must be signed in to change notification settings - Fork 2k
增加1.20例子 #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
增加1.20例子 #12
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
6daff6b
Merge pull request #1 from 892768447/master
625781186 377e991
Merge remote-tracking branch 'iron/master'
625781186 73376dc
Merge remote-tracking branch 'iron/master'
625781186 d631cb1
动态控件基础例子 - 动态生成按钮
625781186 e3e3169
动态控件基础例子 - 动态生成菜单
625781186 e7bc2ee
增加1.20例子
625781186 da7f446
增加1.20例子
625781186 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
35 changes: 35 additions & 0 deletions
partner_625781186/1.exec动态生成控件/dynamic_Menu/Ui_动态控件.py
This file contains hidden or 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,35 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
# Form implementation generated from reading ui file 'D:\pyPro\dynamic_Menu\动态控件.ui' | ||
# | ||
# Created by: PyQt5 UI code generator 5.9.2 | ||
# | ||
# WARNING! All changes made in this file will be lost! | ||
|
||
from PyQt5 import QtCore, QtGui, QtWidgets | ||
|
||
class Ui_Dialog(object): | ||
def setupUi(self, Dialog): | ||
Dialog.setObjectName("Dialog") | ||
Dialog.resize(370, 403) | ||
Dialog.setSizeGripEnabled(True) | ||
self.verticalLayout = QtWidgets.QVBoxLayout(Dialog) | ||
self.verticalLayout.setObjectName("verticalLayout") | ||
|
||
self.retranslateUi(Dialog) | ||
QtCore.QMetaObject.connectSlotsByName(Dialog) | ||
|
||
def retranslateUi(self, Dialog): | ||
_translate = QtCore.QCoreApplication.translate | ||
Dialog.setWindowTitle(_translate("Dialog", "Dialog")) | ||
|
||
|
||
if __name__ == "__main__": | ||
import sys | ||
app = QtWidgets.QApplication(sys.argv) | ||
Dialog = QtWidgets.QDialog() | ||
ui = Ui_Dialog() | ||
ui.setupUi(Dialog) | ||
Dialog.show() | ||
sys.exit(app.exec_()) | ||
|
Empty file.
47 changes: 47 additions & 0 deletions
partner_625781186/1.exec动态生成控件/dynamic_Menu/dynamic_Controls.e4p
This file contains hidden or 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,47 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE Project SYSTEM "Project-5.1.dtd"> | ||
<!-- eric project file for project dynamic_Controls --> | ||
<!-- Saved: 2018年04月11日, 02:00:19 --> | ||
<!-- Copyright (C) 2018 , --> | ||
<Project version="5.1"> | ||
<Language>en_US</Language> | ||
<Hash>b35a15d37a7cb52779310396c238b2e70ac76888</Hash> | ||
<ProgLanguage mixed="0">Python3</ProgLanguage> | ||
<ProjectType>PyQt5</ProjectType> | ||
<Version>0.1</Version> | ||
<Author></Author> | ||
<Email></Email> | ||
<Eol index="0"/> | ||
<Sources> | ||
<Source>Ui_动态控件.py</Source> | ||
<Source>__init__.py</Source> | ||
<Source>动态控件.py</Source> | ||
</Sources> | ||
<Forms> | ||
<Form>动态控件.ui</Form> | ||
</Forms> | ||
<Translations/> | ||
<Resources/> | ||
<Interfaces/> | ||
<Others/> | ||
<Vcs> | ||
<VcsType>None</VcsType> | ||
</Vcs> | ||
<FiletypeAssociations> | ||
<FiletypeAssociation pattern="*.e4p" type="OTHERS"/> | ||
<FiletypeAssociation pattern="*.idl" type="INTERFACES"/> | ||
<FiletypeAssociation pattern="*.md" type="OTHERS"/> | ||
<FiletypeAssociation pattern="*.py" type="SOURCES"/> | ||
<FiletypeAssociation pattern="*.py3" type="SOURCES"/> | ||
<FiletypeAssociation pattern="*.pyw" type="SOURCES"/> | ||
<FiletypeAssociation pattern="*.pyw3" type="SOURCES"/> | ||
<FiletypeAssociation pattern="*.qm" type="TRANSLATIONS"/> | ||
<FiletypeAssociation pattern="*.qrc" type="RESOURCES"/> | ||
<FiletypeAssociation pattern="*.rst" type="OTHERS"/> | ||
<FiletypeAssociation pattern="*.ts" type="TRANSLATIONS"/> | ||
<FiletypeAssociation pattern="*.txt" type="OTHERS"/> | ||
<FiletypeAssociation pattern="*.ui" type="FORMS"/> | ||
<FiletypeAssociation pattern="README" type="OTHERS"/> | ||
<FiletypeAssociation pattern="README.*" type="OTHERS"/> | ||
</FiletypeAssociations> | ||
</Project> |
103 changes: 103 additions & 0 deletions
partner_625781186/1.exec动态生成控件/dynamic_Menu/动态控件.py
This file contains hidden or 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,103 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
""" | ||
Module implementing Dialog. | ||
""" | ||
|
||
from PyQt5 import QtGui, QtWidgets, QtCore, QtWinExtras | ||
from PyQt5.QtCore import * | ||
from PyQt5.QtGui import * | ||
from PyQt5.QtWidgets import * | ||
|
||
from functools import partial | ||
from Ui_动态控件 import Ui_Dialog | ||
|
||
class Dialog(QDialog, Ui_Dialog): | ||
|
||
def __init__(self, parent=None): | ||
|
||
super(Dialog, self).__init__(parent) | ||
self.setupUi(self) | ||
|
||
self.dynamic1() | ||
|
||
self.dynamic2() | ||
|
||
# 法一 | ||
def dynamic1(self): | ||
for i in range(5): | ||
self.pushButton = QtWidgets.QPushButton(self) | ||
self.pushButton.setText("pushButton%d"%i) | ||
self.pushButton.setObjectName("pushButton%d"%i) | ||
self.verticalLayout.addWidget(self.pushButton) | ||
self.pushButton.setContextMenuPolicy(Qt.CustomContextMenu) | ||
self.pushButton.customContextMenuRequested.connect(lambda:self.helpMenu(i))#右键请求,传入i实际上一直是4 | ||
self.pushButton.clicked.connect(self.pr) | ||
|
||
# 法二 | ||
def dynamic2(self): | ||
for i in range(5, 8): | ||
txt=""" | ||
self.pushButton_{i} = QtWidgets.QPushButton(self); | ||
self.pushButton_{i}.setText("pushButton{i}"); | ||
self.pushButton_{i}.setObjectName("pushButton{i}"); | ||
self.verticalLayout.addWidget(self.pushButton_{i}); | ||
|
||
self.pushButton_{i}.setContextMenuPolicy(Qt.CustomContextMenu) | ||
self.pushButton_{i}.customContextMenuRequested.connect(partial(self.helpMenu,i))#右键请求,用lambda会报错,partial需要import | ||
|
||
self.pushButton_{i}.clicked.connect(self.pr) | ||
""".format(i=i) | ||
exec(txt) | ||
#只能法二可用的方式 | ||
self.pushButton_5.clicked.connect(self.pr2) | ||
self.pushButton_6.clicked.connect(self.pr2) | ||
self.pushButton_7.clicked.connect(self.pr2) | ||
|
||
|
||
def helpMenu(self, *type): | ||
'''帮助按钮的右键菜单''' | ||
print(type) | ||
popMenu =QMenu() | ||
|
||
if type[0]==5 or self.sender().text()== 'pushButton0': | ||
popMenu.addAction(u'关于',self.pr) | ||
popMenu.addSeparator() | ||
|
||
elif type[0]==6 or self.sender().text()== 'pushButton1': | ||
popMenu.addAction(u'清理图片',self.pr) | ||
popMenu.addSeparator() | ||
|
||
elif type[0]==7 or self.sender().text()== 'pushButton2': | ||
gitMenu=QMenu('同步到Git', popMenu) | ||
|
||
self.pushAction=QAction(u'上传', self, triggered=lambda:self.pr) | ||
gitMenu.addAction(self.pushAction) | ||
|
||
self.pullAction=QAction(u'下载', self, triggered=lambda:self.pr) | ||
gitMenu.addAction(self.pullAction) | ||
|
||
gitMenu.addSeparator() | ||
gitMenu.addAction(u'配置仓库',lambda:self.pr) | ||
|
||
popMenu.addAction(gitMenu.menuAction())#!! | ||
popMenu.exec_(QCursor.pos())#鼠标位置 | ||
|
||
def pr(self): | ||
'''法一和法二都可用的调用 | ||
if self.sender().objectName=='XXX': | ||
self.pr2() | ||
''' | ||
print(self.sender().text()) | ||
print(self.sender().objectName()) | ||
print(self.pushButton.text()) | ||
|
||
def pr2(self): | ||
print(2) | ||
|
||
if __name__ == "__main__": | ||
import sys | ||
app = QtWidgets.QApplication(sys.argv) | ||
ui = Dialog() | ||
ui.show() | ||
sys.exit(app.exec_()) |
23 changes: 23 additions & 0 deletions
partner_625781186/1.exec动态生成控件/dynamic_Menu/动态控件.ui
This file contains hidden or 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,23 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ui version="4.0"> | ||
<class>Dialog</class> | ||
<widget class="QDialog" name="Dialog"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>0</x> | ||
<y>0</y> | ||
<width>370</width> | ||
<height>403</height> | ||
</rect> | ||
</property> | ||
<property name="windowTitle"> | ||
<string>Dialog</string> | ||
</property> | ||
<property name="sizeGripEnabled"> | ||
<bool>true</bool> | ||
</property> | ||
<layout class="QVBoxLayout" name="verticalLayout"/> | ||
</widget> | ||
<resources/> | ||
<connections/> | ||
</ui> |
35 changes: 35 additions & 0 deletions
partner_625781186/1.exec动态生成控件/dynamic_button/Ui_动态控件.py
This file contains hidden or 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,35 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
# Form implementation generated from reading ui file 'D:\pyPro\dynamic_button\动态控件.ui' | ||
# | ||
# Created by: PyQt5 UI code generator 5.9.2 | ||
# | ||
# WARNING! All changes made in this file will be lost! | ||
|
||
from PyQt5 import QtCore, QtGui, QtWidgets | ||
|
||
class Ui_Dialog(object): | ||
def setupUi(self, Dialog): | ||
Dialog.setObjectName("Dialog") | ||
Dialog.resize(370, 403) | ||
Dialog.setSizeGripEnabled(True) | ||
self.verticalLayout = QtWidgets.QVBoxLayout(Dialog) | ||
self.verticalLayout.setObjectName("verticalLayout") | ||
|
||
self.retranslateUi(Dialog) | ||
QtCore.QMetaObject.connectSlotsByName(Dialog) | ||
|
||
def retranslateUi(self, Dialog): | ||
_translate = QtCore.QCoreApplication.translate | ||
Dialog.setWindowTitle(_translate("Dialog", "Dialog")) | ||
|
||
|
||
if __name__ == "__main__": | ||
import sys | ||
app = QtWidgets.QApplication(sys.argv) | ||
Dialog = QtWidgets.QDialog() | ||
ui = Ui_Dialog() | ||
ui.setupUi(Dialog) | ||
Dialog.show() | ||
sys.exit(app.exec_()) | ||
|
Empty file added
partner_625781186/1.exec动态生成控件/dynamic_button/__init__.py
Empty file.
47 changes: 47 additions & 0 deletions
partner_625781186/1.exec动态生成控件/dynamic_button/dynamic_Controls.e4p
This file contains hidden or 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,47 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE Project SYSTEM "Project-5.1.dtd"> | ||
<!-- eric project file for project dynamic_Controls --> | ||
<!-- Saved: 2018年04月11日, 02:00:19 --> | ||
<!-- Copyright (C) 2018 , --> | ||
<Project version="5.1"> | ||
<Language>en_US</Language> | ||
<Hash>b35a15d37a7cb52779310396c238b2e70ac76888</Hash> | ||
<ProgLanguage mixed="0">Python3</ProgLanguage> | ||
<ProjectType>PyQt5</ProjectType> | ||
<Version>0.1</Version> | ||
<Author></Author> | ||
<Email></Email> | ||
<Eol index="0"/> | ||
<Sources> | ||
<Source>Ui_动态控件.py</Source> | ||
<Source>__init__.py</Source> | ||
<Source>动态控件.py</Source> | ||
</Sources> | ||
<Forms> | ||
<Form>动态控件.ui</Form> | ||
</Forms> | ||
<Translations/> | ||
<Resources/> | ||
<Interfaces/> | ||
<Others/> | ||
<Vcs> | ||
<VcsType>None</VcsType> | ||
</Vcs> | ||
<FiletypeAssociations> | ||
<FiletypeAssociation pattern="*.e4p" type="OTHERS"/> | ||
<FiletypeAssociation pattern="*.idl" type="INTERFACES"/> | ||
<FiletypeAssociation pattern="*.md" type="OTHERS"/> | ||
<FiletypeAssociation pattern="*.py" type="SOURCES"/> | ||
<FiletypeAssociation pattern="*.py3" type="SOURCES"/> | ||
<FiletypeAssociation pattern="*.pyw" type="SOURCES"/> | ||
<FiletypeAssociation pattern="*.pyw3" type="SOURCES"/> | ||
<FiletypeAssociation pattern="*.qm" type="TRANSLATIONS"/> | ||
<FiletypeAssociation pattern="*.qrc" type="RESOURCES"/> | ||
<FiletypeAssociation pattern="*.rst" type="OTHERS"/> | ||
<FiletypeAssociation pattern="*.ts" type="TRANSLATIONS"/> | ||
<FiletypeAssociation pattern="*.txt" type="OTHERS"/> | ||
<FiletypeAssociation pattern="*.ui" type="FORMS"/> | ||
<FiletypeAssociation pattern="README" type="OTHERS"/> | ||
<FiletypeAssociation pattern="README.*" type="OTHERS"/> | ||
</FiletypeAssociations> | ||
</Project> |
65 changes: 65 additions & 0 deletions
partner_625781186/1.exec动态生成控件/dynamic_button/动态控件.py
This file contains hidden or 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,65 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
""" | ||
Module implementing Dialog. | ||
""" | ||
|
||
from PyQt5 import QtGui, QtWidgets, QtCore, QtWinExtras | ||
from PyQt5.QtCore import * | ||
from PyQt5.QtGui import * | ||
from PyQt5.QtWidgets import * | ||
|
||
from Ui_动态控件 import Ui_Dialog | ||
|
||
|
||
class Dialog(QDialog, Ui_Dialog): | ||
|
||
def __init__(self, parent=None): | ||
|
||
super(Dialog, self).__init__(parent) | ||
self.setupUi(self) | ||
self.dynamic1() | ||
self.dynamic2() | ||
|
||
# 法一 | ||
def dynamic1(self): | ||
for i in range(5): | ||
self.pushButton = QtWidgets.QPushButton(self) | ||
self.pushButton.setText("pushButton%d"%i) | ||
self.pushButton.setObjectName("pushButton%d"%i) | ||
self.verticalLayout.addWidget(self.pushButton) | ||
self.pushButton.clicked.connect(self.pr) | ||
# 法二 | ||
def dynamic2(self): | ||
for i in range(4): | ||
txt=""" | ||
self.pushButton_{i} = QtWidgets.QPushButton(self); | ||
self.pushButton_{i}.setText("pushButton{i}"); | ||
self.pushButton_{i}.setObjectName("pushButton{i}"); | ||
self.verticalLayout.addWidget(self.pushButton_{i}); | ||
self.pushButton_{i}.clicked.connect(self.pr) | ||
""".format(i=i) | ||
exec(txt) | ||
#只能法二可用的方式 | ||
self.pushButton_1.clicked.connect(self.pr2) | ||
self.pushButton_2.clicked.connect(self.pr2) | ||
self.pushButton_3.clicked.connect(self.pr2) | ||
|
||
def pr(self): | ||
'''法一和法二都可用的调用 | ||
if self.sender().objectName=='XXX': | ||
self.pr2() | ||
''' | ||
print(self.sender().text()) | ||
print(self.sender().objectName()) | ||
print(self.pushButton.text()) | ||
|
||
def pr2(self): | ||
print(2) | ||
|
||
if __name__ == "__main__": | ||
import sys | ||
app = QtWidgets.QApplication(sys.argv) | ||
ui = Dialog() | ||
ui.show() | ||
sys.exit(app.exec_()) |
23 changes: 23 additions & 0 deletions
partner_625781186/1.exec动态生成控件/dynamic_button/动态控件.ui
This file contains hidden or 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,23 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ui version="4.0"> | ||
<class>Dialog</class> | ||
<widget class="QDialog" name="Dialog"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>0</x> | ||
<y>0</y> | ||
<width>370</width> | ||
<height>403</height> | ||
</rect> | ||
</property> | ||
<property name="windowTitle"> | ||
<string>Dialog</string> | ||
</property> | ||
<property name="sizeGripEnabled"> | ||
<bool>true</bool> | ||
</property> | ||
<layout class="QVBoxLayout" name="verticalLayout"/> | ||
</widget> | ||
<resources/> | ||
<connections/> | ||
</ui> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.