├── .gitignore ├── Chapter01 ├── ericProject │ ├── .eric7project │ │ ├── ericPyQt6.eqj │ │ ├── ericPyQt6.etj │ │ ├── ericPySide6.eqj │ │ └── ericPySide6.etj │ ├── .jedi │ │ └── project.json │ ├── Ui_testFirst.py │ ├── __init__.py │ ├── ericPyQt6.epj │ ├── ericPySide6.epj │ ├── images │ │ ├── calc.jpg │ │ ├── close.jpg │ │ ├── new.jpg │ │ ├── notepad.jpg │ │ ├── open.jpg │ │ └── python.jpg │ ├── resource.qrc │ ├── resource_rc.py │ ├── testFirst.py │ └── testFirst.ui ├── runDemo.py ├── runDemo2.py └── testFirst.py ├── Chapter02 ├── MainWinMenuToolbar.py ├── MainWinMenuToolbar.ui ├── MainWinMenuToolbarRun.py ├── MainWinQrc.py ├── MainWinQrc.ui ├── MainWinQrcRun.py ├── MainWinSignalSlog1.py ├── MainWinSignalSlog1.ui ├── MainWinSignalSlog1Run.py ├── apprcc.qrc ├── apprcc_rc.py ├── ericProject │ ├── .eric7project │ │ ├── ericPyQt6.eqj │ │ ├── ericPyQt6.etj │ │ ├── ericPySide6.eqj │ │ └── ericPySide6.etj │ ├── .jedi │ │ └── project.json │ ├── Ui_ericDemo.py │ ├── __init__.py │ ├── ericDemo.py │ ├── ericDemo.ui │ ├── ericPyQt6.epj │ ├── ericPySide6.epj │ ├── images │ │ ├── calc.jpg │ │ ├── close.jpg │ │ ├── new.jpg │ │ ├── notepad.jpg │ │ ├── open.jpg │ │ └── python.jpg │ ├── resource.qrc │ └── resource_rc.py ├── firstMainWin.py ├── firstMainWin.ui ├── firstMainWinRun.py ├── images │ ├── calc.jpg │ ├── close.jpg │ ├── new.jpg │ ├── notepad.jpg │ ├── open.jpg │ └── python.jpg ├── layoutContainer.py ├── layoutContainer.ui ├── layoutFirst.py ├── layoutFirst.ui ├── layoutWin.py ├── layoutWin.ui ├── layoutWin2.py ├── layoutWin2.ui ├── layoutWin2Run.py ├── rc_apprcc.py ├── tool.py ├── ui_MainWinMenuToolbar.py ├── ui_MainWinQrc.py ├── ui_MainWinSignalSlog1.py ├── ui_firstMainWin.py ├── ui_layoutContainer.py ├── ui_layoutFirst.py ├── ui_layoutWin.py └── ui_layoutWin2.py ├── Chapter03 ├── MainWin.py ├── images │ ├── Bold.png │ ├── Italic.png │ ├── boy.png │ ├── cartoon1.ico │ ├── cartoon2.ico │ ├── cartoon3.ico │ ├── cartoon4.ico │ ├── cartoon5.ico │ ├── cartoon6.ico │ ├── cartoon7.ico │ ├── cartoon8.ico │ ├── close.ico │ ├── doc.ico │ ├── new.png │ ├── open.png │ ├── printer.png │ ├── python.jpg │ ├── python.png │ ├── save.png │ └── win.png ├── qt_QCalendarWidget.py ├── qt_QCheckbox.py ├── qt_QComboBox.py ├── qt_QCommandLinkButton.py ├── qt_QDateTimeEdit.py ├── qt_QDial.py ├── qt_QDoubleSpinBox.py ├── qt_QFontComboBox.py ├── qt_QLabel.py ├── qt_QLabel2.py ├── qt_QLineEdit.py ├── qt_QLineEdit_EchoMode.py ├── qt_QLineEdit_InputMask.py ├── qt_QLineEdit_QValidator.py ├── qt_QPlainTextEdit.py ├── qt_QPushButton.py ├── qt_QRadioButton.py ├── qt_QScrollArea.py ├── qt_QScrollBar.py ├── qt_QSlider.py ├── qt_QSpinBox.py ├── qt_QSpinBox2.py ├── qt_QSyntaxHighlighter.py ├── qt_QTextBrowser.py ├── qt_QTextEdit.py ├── qt_QToolButton.py └── support │ ├── myMarkDown.md │ ├── myhtml.html │ └── textBrowser.html ├── Chapter04 ├── images │ ├── Bold.png │ ├── Italic.png │ ├── ajax-loading.gif │ ├── boy.png │ ├── cartoon1.ico │ ├── cartoon2.ico │ ├── cartoon3.ico │ ├── cartoon4.ico │ ├── cartoon5.ico │ ├── cartoon6.ico │ ├── cartoon7.ico │ ├── cartoon8.ico │ ├── close.ico │ ├── doc.ico │ ├── down.png │ ├── left.png │ ├── mask.png │ ├── mask2.png │ ├── new.png │ ├── open.png │ ├── printer.png │ ├── python.jpg │ ├── python.png │ ├── right.png │ ├── save.png │ ├── up.png │ └── win.png ├── painting │ ├── basicdrawing.py │ ├── concentriccircles.py │ ├── images │ │ ├── brick.png │ │ └── qt-logo.png │ ├── painter.py │ └── plot.py ├── qt_QBrush.py ├── qt_QClipboard.py ├── qt_QColorDialog.py ├── qt_QDialog.py ├── qt_QDialog2.py ├── qt_QDialogButtonBox.py ├── qt_QDrag.py ├── qt_QDrag2.py ├── qt_QFileDialog.py ├── qt_QFontDialog.py ├── qt_QInputDialog.py ├── qt_QKeySequenceEdit.py ├── qt_QLCDNumber.py ├── qt_QMenu.py ├── qt_QMessageBox.py ├── qt_QMimeData.py ├── qt_QPainter.py ├── qt_QPen.py ├── qt_QPixmapQImage.py ├── qt_QProgressDialog.py ├── qt_QShortcut.py ├── qt_QStatusBar.py └── qt_QToolBar.py ├── Chapter05 ├── db │ └── database.db ├── images │ ├── IOS.png │ ├── android.png │ ├── bao0.png │ ├── bao1.png │ ├── bao10.png │ ├── bao11.png │ ├── bao12.png │ ├── bao13.png │ ├── bao14.png │ ├── bao3.png │ ├── bao4.png │ ├── bao5.png │ ├── bao6.png │ ├── bao8.png │ ├── bao9.png │ ├── cartoon1.ico │ ├── close.png │ ├── copy.png │ ├── cut.png │ ├── down.png │ ├── down3.png │ ├── dropdown.png │ ├── flower.png │ ├── go-home.png │ ├── go-next.png │ ├── go-previous.png │ ├── hammer.png │ ├── help.jpg │ ├── left.png │ ├── music.png │ ├── new.png │ ├── open.png │ ├── paste.png │ ├── printer.png │ ├── qt-creator.png │ ├── qt-logo.png │ ├── qt-project.png │ ├── qt-quick.png │ ├── right.png │ ├── root.png │ ├── save.png │ ├── screen1.jpg │ ├── undo.png │ ├── up.png │ └── view-refresh.png ├── qt_QDataWidgetMapper.py ├── qt_QListView.py ├── qt_QListWidget.py ├── qt_QSqlCustomModelDelegate.py ├── qt_QSqlQueryModel.py ├── qt_QSqlRelationalTableModel.py ├── qt_QSqlTableModel.py ├── qt_QSqlTableModelError.py ├── qt_QTableDelegate.py ├── qt_QTableModel.py ├── qt_QTableView.py ├── qt_QTableWidget.py ├── qt_QTreeView.py ├── qt_QTreeView2.py ├── qt_QTreeWidget.py └── qt_createSql.py ├── Chapter06 ├── darkstyleDemo.ui ├── darkstyleDemoRun.py ├── darkstyleDemoUI.py ├── images │ ├── IOS.png │ ├── android.png │ ├── bao0.png │ ├── bao1.png │ ├── bao10.png │ ├── bao11.png │ ├── bao12.png │ ├── bao13.png │ ├── bao14.png │ ├── bao2.png │ ├── bao3.png │ ├── bao4.png │ ├── bao5.png │ ├── bao6.png │ ├── bao7.png │ ├── bao8.png │ ├── bao9.png │ ├── cartoon1.ico │ ├── close.png │ ├── copy.png │ ├── cut.png │ ├── down3.png │ ├── dropdown.png │ ├── flower.png │ ├── go-home.png │ ├── go-next.png │ ├── go-previous.png │ ├── hammer.png │ ├── help.jpg │ ├── left.png │ ├── left2.png │ ├── left3.png │ ├── leftHover.png │ ├── leftPressed.png │ ├── leftdown.png │ ├── leftdown2.png │ ├── leftdown3.png │ ├── leftup.png │ ├── leftup2.png │ ├── leftup3.png │ ├── music.png │ ├── new.png │ ├── open.png │ ├── paste.png │ ├── printer.png │ ├── right.png │ ├── right2.png │ ├── right3.png │ ├── rightdown.png │ ├── rightdown2.png │ ├── rightdown3.png │ ├── rightup.png │ ├── rightup2.png │ ├── rightup3.png │ ├── root.png │ ├── save.png │ ├── screen1.jpg │ ├── undo.png │ ├── up.png │ ├── up2.png │ ├── up3.png │ └── view-refresh.png ├── qmlDemo │ ├── basic │ │ ├── basic.py │ │ └── main.qml │ ├── class-context-property │ │ ├── class.py │ │ └── main.qml │ ├── class-registered-type │ │ ├── class.py │ │ └── main.qml │ ├── model │ │ ├── main.qml │ │ └── model.py │ └── property │ │ ├── main.qml │ │ └── property.py ├── qt_QAxWidget.py ├── qt_QBoxLayout.py ├── qt_QDockWidget.py ├── qt_QDockWidget2.py ├── qt_QFormLayout.py ├── qt_QGridLayout.py ├── qt_QLayout.py ├── qt_QMdiAreaQMdiSubWindow.py ├── qt_QMdiAreaQMdiSubWindow2.py ├── qt_QSplitter.py ├── qt_QStackedLayout.py ├── qt_QStackedWidget.py ├── qt_QTabWidget.py ├── qt_QThread.py ├── qt_QThread2.py ├── qt_QTimer.py ├── qt_QToolBox.py ├── qt_QWebEngineView.py ├── qt_QssDemo.py ├── qt_WinStyleDemo.py ├── qt_processEvents.py ├── style.qss ├── tabbedbrowser │ ├── bookmarkwidget.py │ ├── browsertabwidget.py │ ├── doc │ │ ├── tabbedbrowser.png │ │ └── tabbedbrowser.rst │ ├── downloadwidget.py │ ├── findtoolbar.py │ ├── historywindow.py │ ├── main.py │ ├── tabbedbrowser.pyproject │ └── webengineview.py └── ui_darkstyleDemo.py ├── Chapter07 ├── MainWinSignalSlog.py ├── MainWinSignalSlog.ui ├── MainWinSignalSlogRun.py ├── event.py ├── event_filter.py ├── event_filter2.py ├── images │ ├── cartoon1.ico │ ├── cartoon2.ico │ ├── cartoon3.ico │ ├── cartoon4.ico │ └── python.jpg ├── qt_SignalSlot.py ├── qt_SignalSlotParam.py └── ui_MainWinSignalSlog.py ├── Chapter08 ├── install │ └── colorDialog.py ├── matplotlibDemo │ ├── MatplotlibWidget.py │ ├── Ui_matplotlib_pyqt.py │ ├── matplotlibDemo.py │ ├── matplotlib_pyqt.py │ └── matplotlib_pyqt.ui ├── pandasDemo │ ├── BasicExample.py │ ├── Ui_pandas_pyqt.py │ ├── data │ │ ├── fund_data.xlsx │ │ └── fund_data_new.xlsx │ ├── pandas_pyqt.py │ ├── pandas_pyqt.ui │ ├── qtpandas.zip │ ├── qtpandas │ │ ├── __init__.py │ │ ├── _lib │ │ │ └── magic │ │ │ │ ├── db │ │ │ │ └── magic.mgc │ │ │ │ ├── libgcc_s_dw2-1.dll │ │ │ │ ├── libmagic-1.dll │ │ │ │ ├── libregex-1.dll │ │ │ │ ├── magic1.dll │ │ │ │ └── zlib1.dll │ │ ├── compat.py │ │ ├── encoding.py │ │ ├── excepthook.py │ │ ├── i18n │ │ │ └── de.qm │ │ ├── models │ │ │ ├── ColumnDtypeModel.py │ │ │ ├── DataFrameModel.py │ │ │ ├── DataFrameModelManager.py │ │ │ ├── DataSearch.py │ │ │ ├── ProgressThread.py │ │ │ ├── SupportedDtypes.py │ │ │ ├── __init__.py │ │ │ └── mime.py │ │ ├── ui │ │ │ ├── __init__.py │ │ │ └── fallback │ │ │ │ ├── __init__.py │ │ │ │ └── easygui │ │ │ │ ├── __init__.py │ │ │ │ ├── boxes │ │ │ │ ├── __init__.py │ │ │ │ ├── about.py │ │ │ │ ├── base_boxes.py │ │ │ │ ├── derived_boxes.py │ │ │ │ ├── egstore.py │ │ │ │ ├── state.py │ │ │ │ ├── text_box.py │ │ │ │ ├── updatable_text_box.py │ │ │ │ └── utils.py │ │ │ │ └── easygui.py │ │ ├── utils.py │ │ └── views │ │ │ ├── BigIntSpinbox.py │ │ │ ├── CSVDialogs.py │ │ │ ├── CustomDelegates.py │ │ │ ├── DataTableView.py │ │ │ ├── EditDialogs.py │ │ │ ├── MultiFileDialogs.py │ │ │ ├── OverlayProgressView.py │ │ │ ├── __init__.py │ │ │ └── _ui │ │ │ ├── __init__.py │ │ │ └── icons_rc.py │ └── qtpandasDemo.py ├── plotlyDemo │ ├── PyQt_plotly_setHtml.py │ ├── Ui_plotly_pyqt.py │ ├── dashDemo.py │ ├── demo_plotly_pyqt.py │ ├── plotlyDemo.py │ ├── plotly_html │ │ ├── bWLwgP.css │ │ ├── country_indicators.csv │ │ ├── if_hs300_bais.html │ │ └── if_index_bais.xlsx │ ├── plotly_pyqt.py │ └── plotly_pyqt.ui └── pyqtgraphDemo │ ├── Ui_pyqtgraph_pyqt.py │ ├── pyqtgraphDemo.py │ ├── pyqtgraph_pyqt.py │ └── pyqtgraph_pyqt.ui ├── Chapter09 ├── juchao │ ├── Ui_run.py │ ├── craw.py │ ├── run.py │ └── run.ui └── myQuant │ ├── data │ └── TF.CFE_15.csv │ ├── out │ ├── 下影线策略_posValDF.csv │ └── 下影线策略_tradeFlow.csv │ ├── plotDataList.pkl │ ├── quant │ ├── __init__.py │ ├── my_talib.py │ ├── rhPlot │ │ ├── Ui_rhQuant_matplotlib_show.py │ │ ├── __init__.py │ │ ├── plotDataList.pkl │ │ ├── rhMatplotlibWidget.py │ │ ├── rhQuant_matplotlib_show.py │ │ ├── rhQuant_matplotlib_show.ui │ │ └── rhQuant_plotly_show.py │ └── rhQuant.py │ └── runDemo.py ├── LICENSE ├── README.md └── appendix ├── B-CtoPyhtonDemo ├── CMakeLists.txt ├── extension.pro ├── finddialog.cpp ├── finddialog.h ├── main.cpp └── qt_QDialog2.py ├── X ├── MultiWindow.py ├── MultiWindow2.py ├── fundDemo │ ├── Plotly_Qt.py │ ├── combination.py │ ├── combination.ui │ ├── combinationRun.py │ ├── data │ │ ├── fund_data.xlsx │ │ ├── fund_data_new.xlsx │ │ ├── 和聚光明1号_hs300_merge.xlsx │ │ ├── 时时安稳健1号.csv │ │ ├── 昆仑信托-昆仑三十六号.csv │ │ ├── 组合.xlsx │ │ └── 长城国瑞证券恒通23号.csv │ ├── fundFOF.py │ ├── fundFOF.ui │ ├── fundFOFRun.py │ ├── mypyqtgraph.py │ ├── ui_combination.py │ └── ui_fundFOF.py ├── images │ ├── boy.png │ ├── down.png │ ├── left.png │ ├── mask.png │ ├── mask2.png │ ├── right.png │ └── up.png ├── qt_setMask1.py ├── qt_setMask2.py └── testCase │ ├── 2022-03-20-19_43_54HTMLtemplate.html │ ├── HTMLTestRunner.py │ ├── MatrixWinTest.py │ ├── MatrixWinUi.py │ ├── MatrixWinUi.ui │ ├── MatrixWinUiRun.py │ ├── RunTestCase.py │ ├── reportLog.txt │ └── ui_MatrixWinUi.py └── 《PySide6-PyQt6快速开发与实战》附赠电子版.pdf /.gitignore: -------------------------------------------------------------------------------- 1 | # pycharm and vscode 2 | .idea 3 | .vscode 4 | 5 | # plotly_html文件,里面的html文件可以由程序生成 6 | plotly_html/ 7 | 8 | # Byte-compiled / optimized / DLL files 9 | __pycache__/ 10 | *.py[cod] 11 | *$py.class 12 | 13 | # C extensions 14 | *.so 15 | 16 | # Distribution / packaging 17 | .Python 18 | build/ 19 | develop-eggs/ 20 | dist/ 21 | downloads/ 22 | eggs/ 23 | .eggs/ 24 | lib/ 25 | lib64/ 26 | parts/ 27 | sdist/ 28 | var/ 29 | wheels/ 30 | pip-wheel-metadata/ 31 | share/python-wheels/ 32 | *.egg-info/ 33 | .installed.cfg 34 | *.egg 35 | MANIFEST 36 | 37 | # PyInstaller 38 | # Usually these files are written by a python script from a template 39 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 40 | *.manifest 41 | *.spec 42 | 43 | # Installer logs 44 | pip-log.txt 45 | pip-delete-this-directory.txt 46 | 47 | # Unit test / coverage reports 48 | htmlcov/ 49 | .tox/ 50 | .nox/ 51 | .coverage 52 | .coverage.* 53 | .cache 54 | nosetests.xml 55 | coverage.xml 56 | *.cover 57 | *.py,cover 58 | .hypothesis/ 59 | .pytest_cache/ 60 | 61 | # Translations 62 | *.mo 63 | *.pot 64 | 65 | # Django stuff: 66 | *.log 67 | local_settings.py 68 | db.sqlite3 69 | db.sqlite3-journal 70 | 71 | # Flask stuff: 72 | instance/ 73 | .webassets-cache 74 | 75 | # Scrapy stuff: 76 | .scrapy 77 | 78 | # Sphinx documentation 79 | docs/_build/ 80 | 81 | # PyBuilder 82 | target/ 83 | 84 | # Jupyter Notebook 85 | .ipynb_checkpoints 86 | 87 | # IPython 88 | profile_default/ 89 | ipython_config.py 90 | 91 | # pyenv 92 | .python-version 93 | 94 | # pipenv 95 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 96 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 97 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 98 | # install all needed dependencies. 99 | #Pipfile.lock 100 | 101 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow 102 | __pypackages__/ 103 | 104 | # Celery stuff 105 | celerybeat-schedule 106 | celerybeat.pid 107 | 108 | # SageMath parsed files 109 | *.sage.py 110 | 111 | # Environments 112 | .env 113 | .venv 114 | env/ 115 | venv/ 116 | ENV/ 117 | env.bak/ 118 | venv.bak/ 119 | 120 | # Spyder project settings 121 | .spyderproject 122 | .spyproject 123 | 124 | # Rope project settings 125 | .ropeproject 126 | 127 | # mkdocs documentation 128 | /site 129 | 130 | # mypy 131 | .mypy_cache/ 132 | .dmypy.json 133 | dmypy.json 134 | 135 | # Pyre type checker 136 | .pyre/ 137 | -------------------------------------------------------------------------------- /Chapter01/ericProject/.eric7project/ericPyQt6.eqj: -------------------------------------------------------------------------------- 1 | { 2 | "header": { 3 | "comment": "eric user project file for project ericPyQt6", 4 | "saved": "2022-03-03, 14:12:13" 5 | }, 6 | "user_data": { 7 | "VCSOVERRIDE": "", 8 | "VCSSTATUSMONITORINTERVAL": 0 9 | } 10 | } -------------------------------------------------------------------------------- /Chapter01/ericProject/.eric7project/ericPyQt6.etj: -------------------------------------------------------------------------------- 1 | { 2 | "header": { 3 | "comment": "eric tasks file for project ericPyQt6", 4 | "warning": "This file was generated automatically, do not edit.", 5 | "saved": "2022-03-03, 14:12:13" 6 | }, 7 | "ProjectScanFilter": "", 8 | "Tasks": [ 9 | { 10 | "summary": "WARNING: Any manual changes made to this file will be lost when pyuic6 is", 11 | "description": "", 12 | "priority": 1, 13 | "lineno": 5, 14 | "completed": false, 15 | "created": 1646287868.31291, 16 | "type": 2, 17 | "uid": "{78816698-410a-48f3-b39f-4012e3525713}", 18 | "parent_uid": "", 19 | "expanded": false, 20 | "filename": "D:\\zw_own\\PyQt\\my_pyqt_book\\PySide6-codes\\Chapter01\\ericProject\\Ui_testFirst.py" 21 | }, 22 | { 23 | "summary": "TODO: not implemented yet", 24 | "description": "", 25 | "priority": 1, 26 | "lineno": 36, 27 | "completed": false, 28 | "created": 1646287912.3282888, 29 | "type": 1, 30 | "uid": "{e0aded9c-8ac1-4268-bf8c-dcba9a2819bd}", 31 | "parent_uid": "", 32 | "expanded": false, 33 | "filename": "D:\\zw_own\\PyQt\\my_pyqt_book\\PySide6-codes\\Chapter01\\ericProject\\testFirst.py" 34 | } 35 | ] 36 | } -------------------------------------------------------------------------------- /Chapter01/ericProject/.eric7project/ericPySide6.eqj: -------------------------------------------------------------------------------- 1 | { 2 | "header": { 3 | "comment": "eric user project file for project ericPySide6", 4 | "saved": "2022-03-03, 14:35:37" 5 | }, 6 | "user_data": { 7 | "VCSOVERRIDE": "", 8 | "VCSSTATUSMONITORINTERVAL": 0 9 | } 10 | } -------------------------------------------------------------------------------- /Chapter01/ericProject/.eric7project/ericPySide6.etj: -------------------------------------------------------------------------------- 1 | { 2 | "header": { 3 | "comment": "eric tasks file for project ericPySide6", 4 | "warning": "This file was generated automatically, do not edit.", 5 | "saved": "2022-03-03, 14:35:37" 6 | }, 7 | "ProjectScanFilter": "", 8 | "Tasks": [ 9 | { 10 | "summary": "TODO: not implemented yet", 11 | "description": "", 12 | "priority": 1, 13 | "lineno": 36, 14 | "completed": false, 15 | "created": 1646289285.4025612, 16 | "type": 1, 17 | "uid": "{5e93d31c-8f96-431a-861e-1048d6b5724b}", 18 | "parent_uid": "", 19 | "expanded": false, 20 | "filename": "D:\\zw_own\\PyQt\\my_pyqt_book\\PySide6-codes\\Chapter01\\ericProject\\testFirst.py" 21 | } 22 | ] 23 | } -------------------------------------------------------------------------------- /Chapter01/ericProject/.jedi/project.json: -------------------------------------------------------------------------------- 1 | [1, {"path": "D:\\zw_own\\PyQt\\my_pyqt_book\\PySide6-codes\\Chapter01\\ericProject", "environment_path": null, "sys_path": null, "smart_sys_path": true, "load_unsafe_extensions": false, "added_sys_path": []}] -------------------------------------------------------------------------------- /Chapter01/ericProject/Ui_testFirst.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | ################################################################################ 4 | ## Form generated from reading UI file 'testFirst.ui' 5 | ## 6 | ## Created by: Qt User Interface Compiler version 6.2.3 7 | ## 8 | ## WARNING! All changes made in this file will be lost when recompiling UI file! 9 | ################################################################################ 10 | 11 | from PySide6.QtCore import (QCoreApplication, QDate, QDateTime, QLocale, 12 | QMetaObject, QObject, QPoint, QRect, 13 | QSize, QTime, QUrl, Qt) 14 | from PySide6.QtGui import (QBrush, QColor, QConicalGradient, QCursor, 15 | QFont, QFontDatabase, QGradient, QIcon, 16 | QImage, QKeySequence, QLinearGradient, QPainter, 17 | QPalette, QPixmap, QRadialGradient, QTransform) 18 | from PySide6.QtWidgets import (QApplication, QLabel, QLineEdit, QPushButton, 19 | QSizePolicy, QWidget) 20 | import resource_rc 21 | 22 | class Ui_Form(object): 23 | def setupUi(self, Form): 24 | if not Form.objectName(): 25 | Form.setObjectName(u"Form") 26 | Form.resize(400, 300) 27 | self.pushButton = QPushButton(Form) 28 | self.pushButton.setObjectName(u"pushButton") 29 | self.pushButton.setGeometry(QRect(30, 80, 141, 61)) 30 | self.pushButton.setStyleSheet(u"image: url(:/pic1/images/open.jpg);") 31 | self.lineEdit = QLineEdit(Form) 32 | self.lineEdit.setObjectName(u"lineEdit") 33 | self.lineEdit.setGeometry(QRect(220, 60, 113, 20)) 34 | self.label = QLabel(Form) 35 | self.label.setObjectName(u"label") 36 | self.label.setGeometry(QRect(170, 200, 141, 31)) 37 | self.label.setStyleSheet(u"image: url(:/pic1/images/close.jpg);") 38 | 39 | self.retranslateUi(Form) 40 | self.pushButton.toggled.connect(self.label.setEnabled) 41 | 42 | QMetaObject.connectSlotsByName(Form) 43 | # setupUi 44 | 45 | def retranslateUi(self, Form): 46 | Form.setWindowTitle(QCoreApplication.translate("Form", u"Form", None)) 47 | self.pushButton.setText(QCoreApplication.translate("Form", u"PushButton", None)) 48 | self.label.setText(QCoreApplication.translate("Form", u"TextLabel", None)) 49 | # retranslateUi 50 | 51 | -------------------------------------------------------------------------------- /Chapter01/ericProject/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter01/ericProject/__init__.py -------------------------------------------------------------------------------- /Chapter01/ericProject/ericPyQt6.epj: -------------------------------------------------------------------------------- 1 | { 2 | "header": { 3 | "comment": "eric project file for project ericPyQt6", 4 | "copyright": "Copyright (C) 2022 , ", 5 | "saved": "2022-03-03, 14:12:13" 6 | }, 7 | "project": { 8 | "AUTHOR": "", 9 | "CHECKERSPARMS": {}, 10 | "DESCRIPTION": "", 11 | "DOCSTRING": "", 12 | "DOCUMENTATIONPARMS": {}, 13 | "EMAIL": "", 14 | "EOL": 0, 15 | "FILETYPES": { 16 | "*.e4p": "OTHERS", 17 | "*.epj": "OTHERS", 18 | "*.idl": "INTERFACES", 19 | "*.md": "OTHERS", 20 | "*.proto": "PROTOCOLS", 21 | "*.py": "SOURCES", 22 | "*.py3": "SOURCES", 23 | "*.pyw": "SOURCES", 24 | "*.pyw3": "SOURCES", 25 | "*.qm": "TRANSLATIONS", 26 | "*.rst": "OTHERS", 27 | "*.ts": "TRANSLATIONS", 28 | "*.txt": "OTHERS", 29 | "*.ui": "FORMS", 30 | "GNUmakefile": "OTHERS", 31 | "Makefile": "OTHERS", 32 | "README": "OTHERS", 33 | "README.*": "OTHERS", 34 | "makefile": "OTHERS" 35 | }, 36 | "FORMS": [ 37 | "testFirst.ui" 38 | ], 39 | "HASH": "2b7da992a3f214565003e70979adeeef1798a242", 40 | "IDLPARAMS": { 41 | "DefinedNames": [], 42 | "IncludeDirs": [], 43 | "UndefinedNames": [] 44 | }, 45 | "INTERFACES": [], 46 | "LEXERASSOCS": {}, 47 | "MAINSCRIPT": "", 48 | "MAKEPARAMS": { 49 | "MakeEnabled": false, 50 | "MakeExecutable": "", 51 | "MakeFile": "", 52 | "MakeParameters": "", 53 | "MakeTarget": "", 54 | "MakeTestOnly": true 55 | }, 56 | "MIXEDLANGUAGE": false, 57 | "OTHERS": [], 58 | "OTHERTOOLSPARMS": {}, 59 | "PACKAGERSPARMS": {}, 60 | "PROGLANGUAGE": "Python3", 61 | "PROJECTTYPE": "PyQt6", 62 | "PROJECTTYPESPECIFICDATA": {}, 63 | "PROTOCOLS": [], 64 | "RCCPARAMS": { 65 | "CompressLevel": 0, 66 | "CompressionDisable": false, 67 | "CompressionThreshold": 70, 68 | "PathPrefix": "" 69 | }, 70 | "RESOURCES": [], 71 | "SOURCES": [ 72 | "__init__.py", 73 | "Ui_testFirst.py", 74 | "testFirst.py" 75 | ], 76 | "SPELLEXCLUDES": "", 77 | "SPELLLANGUAGE": "en_US", 78 | "SPELLWORDS": "", 79 | "TRANSLATIONEXCEPTIONS": [], 80 | "TRANSLATIONPATTERN": "", 81 | "TRANSLATIONS": [], 82 | "TRANSLATIONSBINPATH": "", 83 | "UICPARAMS": { 84 | "Package": "", 85 | "PackagesRoot": "", 86 | "RcSuffix": "" 87 | }, 88 | "VCS": "None", 89 | "VCSOPTIONS": {}, 90 | "VCSOTHERDATA": {}, 91 | "VERSION": "0.1" 92 | } 93 | } -------------------------------------------------------------------------------- /Chapter01/ericProject/images/calc.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter01/ericProject/images/calc.jpg -------------------------------------------------------------------------------- /Chapter01/ericProject/images/close.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter01/ericProject/images/close.jpg -------------------------------------------------------------------------------- /Chapter01/ericProject/images/new.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter01/ericProject/images/new.jpg -------------------------------------------------------------------------------- /Chapter01/ericProject/images/notepad.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter01/ericProject/images/notepad.jpg -------------------------------------------------------------------------------- /Chapter01/ericProject/images/open.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter01/ericProject/images/open.jpg -------------------------------------------------------------------------------- /Chapter01/ericProject/images/python.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter01/ericProject/images/python.jpg -------------------------------------------------------------------------------- /Chapter01/ericProject/resource.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | images/close.jpg 4 | images/new.jpg 5 | images/notepad.jpg 6 | images/open.jpg 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /Chapter01/ericProject/testFirst.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Module implementing Form. 5 | """ 6 | 7 | from PySide6.QtCore import Slot 8 | from PySide6.QtWidgets import QWidget, QApplication, QMessageBox 9 | 10 | 11 | from Ui_testFirst import Ui_Form 12 | 13 | 14 | class Form(QWidget, Ui_Form): 15 | """ 16 | Class documentation goes here. 17 | """ 18 | def __init__(self, parent=None): 19 | """ 20 | Constructor 21 | 22 | @param parent reference to the parent widget (defaults to None) 23 | @type QWidget (optional) 24 | """ 25 | super().__init__(parent) 26 | self.setupUi(self) 27 | 28 | @Slot(bool) 29 | def on_pushButton_clicked(self, checked): 30 | """ 31 | Slot documentation goes here. 32 | 33 | @param checked DESCRIPTION 34 | @type bool 35 | """ 36 | # TODO: not implemented yet 37 | print('测试消息') 38 | QMessageBox.information(self, "标题", "测试消息") 39 | 40 | if __name__ == '__main__': 41 | import sys 42 | app = QApplication(sys.argv) 43 | demo = Form() 44 | demo.show() 45 | sys.exit(app.exec()) 46 | -------------------------------------------------------------------------------- /Chapter01/ericProject/testFirst.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | Form 4 | 5 | 6 | 7 | 0 8 | 0 9 | 400 10 | 300 11 | 12 | 13 | 14 | Form 15 | 16 | 17 | 18 | 19 | 30 20 | 80 21 | 141 22 | 61 23 | 24 | 25 | 26 | image: url(:/pic1/images/open.jpg); 27 | 28 | 29 | PushButton 30 | 31 | 32 | 33 | 34 | 35 | 220 36 | 60 37 | 113 38 | 20 39 | 40 | 41 | 42 | 43 | 44 | 45 | 170 46 | 200 47 | 141 48 | 31 49 | 50 | 51 | 52 | image: url(:/pic1/images/close.jpg); 53 | 54 | 55 | TextLabel 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | pushButton 65 | toggled(bool) 66 | label 67 | setEnabled(bool) 68 | 69 | 70 | 117 71 | 71 72 | 73 | 74 | 187 75 | 177 76 | 77 | 78 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /Chapter01/runDemo.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | import sys 4 | from PySide6.QtWidgets import QPushButton, QApplication, QWidget 5 | 6 | 7 | class WinForm(QWidget): 8 | def __init__(self, parent=None): 9 | super(WinForm, self).__init__(parent) 10 | self.setGeometry(300, 300, 250, 150) 11 | self.setWindowTitle('启动方式1') 12 | button = QPushButton('Close', self) 13 | button.clicked.connect(self.close) 14 | 15 | 16 | if __name__ == "__main__": 17 | app = QApplication(sys.argv) 18 | win = WinForm() 19 | win.show() 20 | sys.exit(app.exec()) 21 | -------------------------------------------------------------------------------- /Chapter01/runDemo2.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | import sys 4 | from PySide6.QtWidgets import QPushButton, QApplication, QWidget 5 | 6 | 7 | class WinForm(QWidget): 8 | def __init__(self, parent=None): 9 | super(WinForm, self).__init__(parent) 10 | self.setGeometry(300, 300, 250, 150) 11 | self.setWindowTitle('启动方式2') 12 | button = QPushButton('Close', self) 13 | button.clicked.connect(self.close) 14 | 15 | 16 | if __name__ == "__main__": 17 | 18 | app = QApplication.instance() 19 | if app == None: 20 | app = QApplication(sys.argv) 21 | 22 | # 下面两行代码根据需要进行开启。 23 | # app.aboutToQuit.connect(app.deleteLater) 24 | # QApplication.setQuitOnLastWindowClosed(True) 25 | 26 | win = WinForm() 27 | win.show() 28 | app.exec() 29 | -------------------------------------------------------------------------------- /Chapter01/testFirst.py: -------------------------------------------------------------------------------- 1 | import sys 2 | from PySide6 import QtWidgets 3 | 4 | ''' 5 | 【简介】 6 | 第一个PyQt例子 7 | 8 | 9 | ''' 10 | 11 | app = QtWidgets.QApplication(sys.argv) 12 | widget = QtWidgets.QWidget() 13 | widget.resize(360, 360) 14 | widget.setWindowTitle("hello, PySide6") 15 | widget.show() 16 | sys.exit(app.exec()) 17 | -------------------------------------------------------------------------------- /Chapter02/MainWinMenuToolbarRun.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | import sys 4 | from PySide6.QtWidgets import QApplication , QMainWindow, QWidget , QFileDialog 5 | from MainWinMenuToolbar import Ui_MainWindow 6 | from PySide6.QtCore import QCoreApplication 7 | import os 8 | 9 | class MainForm( QMainWindow , Ui_MainWindow): 10 | def __init__(self): 11 | super(MainForm,self).__init__() 12 | self.setupUi(self) 13 | # 菜单的点击事件,当点击关闭菜单时连接槽函数 close() 14 | self.fileCloseAction.triggered.connect(self.close) 15 | # 菜单的点击事件,当点击打开菜单时连接槽函数 openMsg() 16 | self.fileOpenAction.triggered.connect(self.openFile) 17 | 18 | # 打开计算器 19 | self.openCalc.triggered.connect(lambda :os.system('calc')) 20 | 21 | # 打开记事本 22 | self.openNotepad.triggered.connect(lambda :os.system('notepad')) 23 | 24 | 25 | 26 | def openFile(self): 27 | file,ok= QFileDialog.getOpenFileName(self,"打开","C:/","All Files (*);;Text Files (*.txt)") 28 | # 在状态栏显示文件地址 29 | self.statusbar.showMessage(file) 30 | 31 | if __name__=="__main__": 32 | app = QApplication(sys.argv) 33 | win = MainForm() 34 | win.show() 35 | sys.exit(app.exec()) 36 | -------------------------------------------------------------------------------- /Chapter02/MainWinQrcRun.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | import sys 4 | from PySide6.QtWidgets import QApplication, QMainWindow, QWidget, QFileDialog 5 | from MainWinQrc import Ui_MainWindow 6 | from PySide6.QtCore import QCoreApplication 7 | import os 8 | os.chdir(os.path.dirname(__file__)) 9 | class MainForm(QMainWindow, Ui_MainWindow): 10 | def __init__(self): 11 | super(MainForm, self).__init__() 12 | self.setupUi(self) 13 | # 菜单的点击事件,当点击关闭菜单时连接槽函数 close() 14 | self.fileCloseAction.triggered.connect(self.close) 15 | # 菜单的点击事件,当点击打开菜单时连接槽函数 openMsg() 16 | self.fileOpenAction.triggered.connect(self.openFile) 17 | 18 | # 打开计算器 19 | self.openCalc.triggered.connect(lambda: os.system('calc')) 20 | 21 | # 打开记事本 22 | self.openNotepad.triggered.connect(lambda: os.system('notepad')) 23 | 24 | def openFile(self): 25 | file, ok = QFileDialog.getOpenFileName(self, "打开", "C:/", "All Files (*);;Text Files (*.txt)") 26 | # 在状态栏显示文件地址 27 | self.statusbar.showMessage(file) 28 | 29 | 30 | if __name__ == "__main__": 31 | app = QApplication(sys.argv) 32 | win = MainForm() 33 | win.show() 34 | sys.exit(app.exec()) 35 | -------------------------------------------------------------------------------- /Chapter02/MainWinSignalSlog1.py: -------------------------------------------------------------------------------- 1 | 2 | from PySide6 import QtCore, QtGui, QtWidgets 3 | 4 | class Ui_Form(object): 5 | def setupUi(self, Form): 6 | Form.setObjectName("Form") 7 | Form.resize(452, 296) 8 | self.closeWinBtn = QtWidgets.QPushButton(Form) 9 | self.closeWinBtn.setGeometry(QtCore.QRect(150, 80, 121, 31)) 10 | self.closeWinBtn.setObjectName("closeWinBtn") 11 | 12 | self.retranslateUi(Form) 13 | self.closeWinBtn.clicked.connect(Form.close) # type: ignore 14 | self.closeWinBtn.pressed.connect(Form.testSlot) # type: ignore 15 | QtCore.QMetaObject.connectSlotsByName(Form) 16 | 17 | def retranslateUi(self, Form): 18 | _translate = QtCore.QCoreApplication.translate 19 | Form.setWindowTitle(_translate("Form", "Form")) 20 | self.closeWinBtn.setText(_translate("Form", "关闭窗口")) 21 | -------------------------------------------------------------------------------- /Chapter02/MainWinSignalSlog1.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | Form 4 | 5 | 6 | 7 | 0 8 | 0 9 | 452 10 | 296 11 | 12 | 13 | 14 | Form 15 | 16 | 17 | 18 | 19 | 150 20 | 80 21 | 121 22 | 31 23 | 24 | 25 | 26 | 关闭窗口 27 | 28 | 29 | 30 | 31 | 32 | 33 | closeWinBtn 34 | clicked() 35 | Form 36 | close() 37 | 38 | 39 | 205 40 | 89 41 | 42 | 43 | 224 44 | 199 45 | 46 | 47 | 48 | 49 | closeWinBtn 50 | pressed() 51 | Form 52 | testSlot() 53 | 54 | 55 | 226 56 | 96 57 | 58 | 59 | 355 60 | 164 61 | 62 | 63 | 64 | 65 | 66 | signal1() 67 | testSlot() 68 | 69 | 70 | -------------------------------------------------------------------------------- /Chapter02/MainWinSignalSlog1Run.py: -------------------------------------------------------------------------------- 1 | import sys 2 | from PySide6.QtWidgets import QApplication, QMainWindow 3 | from MainWinSignalSlog1 import Ui_Form 4 | 5 | 6 | class MyMainWindow(QMainWindow, Ui_Form): 7 | def __init__(self, parent=None): 8 | super(MyMainWindow, self).__init__(parent) 9 | self.setupUi(self) 10 | 11 | def testSlot(self): 12 | print('这是一个自定义槽函数,你成功了') 13 | 14 | 15 | if __name__ == "__main__": 16 | app = QApplication(sys.argv) 17 | myWin = MyMainWindow() 18 | myWin.show() 19 | sys.exit(app.exec()) 20 | -------------------------------------------------------------------------------- /Chapter02/apprcc.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | images/close.jpg 4 | images/new.jpg 5 | images/open.jpg 6 | images/python.jpg 7 | images/calc.jpg 8 | images/notepad.jpg 9 | 10 | 11 | -------------------------------------------------------------------------------- /Chapter02/ericProject/.eric7project/ericPyQt6.eqj: -------------------------------------------------------------------------------- 1 | { 2 | "header": { 3 | "comment": "eric user project file for project ericPyQt6", 4 | "saved": "2022-03-03, 14:06:15" 5 | }, 6 | "user_data": { 7 | "VCSOVERRIDE": "", 8 | "VCSSTATUSMONITORINTERVAL": 0 9 | } 10 | } -------------------------------------------------------------------------------- /Chapter02/ericProject/.eric7project/ericPyQt6.etj: -------------------------------------------------------------------------------- 1 | { 2 | "header": { 3 | "comment": "eric tasks file for project ericPyQt6", 4 | "warning": "This file was generated automatically, do not edit.", 5 | "saved": "2022-03-03, 14:06:15" 6 | }, 7 | "ProjectScanFilter": "", 8 | "Tasks": [] 9 | } -------------------------------------------------------------------------------- /Chapter02/ericProject/.eric7project/ericPySide6.eqj: -------------------------------------------------------------------------------- 1 | { 2 | "header": { 3 | "comment": "eric user project file for project ericPySide6", 4 | "saved": "2022-03-03, 14:45:51" 5 | }, 6 | "user_data": { 7 | "VCSOVERRIDE": "", 8 | "VCSSTATUSMONITORINTERVAL": 0 9 | } 10 | } -------------------------------------------------------------------------------- /Chapter02/ericProject/.eric7project/ericPySide6.etj: -------------------------------------------------------------------------------- 1 | { 2 | "header": { 3 | "comment": "eric tasks file for project ericPySide6", 4 | "warning": "This file was generated automatically, do not edit.", 5 | "saved": "2022-03-03, 14:45:51" 6 | }, 7 | "ProjectScanFilter": "", 8 | "Tasks": [] 9 | } -------------------------------------------------------------------------------- /Chapter02/ericProject/.jedi/project.json: -------------------------------------------------------------------------------- 1 | [1, {"path": "D:\\zw_own\\PyQt\\my_pyqt_book\\PySide6-codes\\Chapter02\\ericProject", "environment_path": null, "sys_path": null, "smart_sys_path": true, "load_unsafe_extensions": false, "added_sys_path": []}] -------------------------------------------------------------------------------- /Chapter02/ericProject/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter02/ericProject/__init__.py -------------------------------------------------------------------------------- /Chapter02/ericProject/ericDemo.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Module implementing Dialog. 5 | """ 6 | 7 | from PySide6.QtCore import Slot 8 | from PySide6.QtWidgets import QDialog, QApplication, QMessageBox 9 | 10 | from Ui_ericDemo import Ui_Dialog 11 | 12 | 13 | class Dialog(QDialog, Ui_Dialog): 14 | """ 15 | Class documentation goes here. 16 | """ 17 | def __init__(self, parent=None): 18 | """ 19 | Constructor 20 | 21 | @param parent reference to the parent widget (defaults to None) 22 | @type QWidget (optional) 23 | """ 24 | super().__init__(parent) 25 | self.setupUi(self) 26 | 27 | @Slot(bool) 28 | def on_pushButton_clicked(self, checked): 29 | """ 30 | Slot documentation goes here. 31 | 32 | @param checked DESCRIPTION 33 | @type bool 34 | """ 35 | print('测试消息') 36 | QMessageBox.information(self, "标题", "测试消息") 37 | 38 | 39 | 40 | if __name__ == '__main__': 41 | import sys 42 | app = QApplication(sys.argv) 43 | demo = Dialog() 44 | demo.show() 45 | sys.exit(app.exec()) 46 | -------------------------------------------------------------------------------- /Chapter02/ericProject/images/calc.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter02/ericProject/images/calc.jpg -------------------------------------------------------------------------------- /Chapter02/ericProject/images/close.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter02/ericProject/images/close.jpg -------------------------------------------------------------------------------- /Chapter02/ericProject/images/new.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter02/ericProject/images/new.jpg -------------------------------------------------------------------------------- /Chapter02/ericProject/images/notepad.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter02/ericProject/images/notepad.jpg -------------------------------------------------------------------------------- /Chapter02/ericProject/images/open.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter02/ericProject/images/open.jpg -------------------------------------------------------------------------------- /Chapter02/ericProject/images/python.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter02/ericProject/images/python.jpg -------------------------------------------------------------------------------- /Chapter02/ericProject/resource.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | images/close.jpg 4 | images/new.jpg 5 | images/notepad.jpg 6 | images/open.jpg 7 | 8 | 9 | images/python.jpg 10 | 11 | 12 | -------------------------------------------------------------------------------- /Chapter02/firstMainWin.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | ################################################################################ 4 | ## Form generated from reading UI file 'firstMainWin.ui' 5 | ## 6 | ## Created by: Qt User Interface Compiler version 6.2.3 7 | ## 8 | ## WARNING! All changes made in this file will be lost when recompiling UI file! 9 | ################################################################################ 10 | 11 | from PySide6.QtCore import (QCoreApplication, QDate, QDateTime, QLocale, 12 | QMetaObject, QObject, QPoint, QRect, 13 | QSize, QTime, QUrl, Qt) 14 | from PySide6.QtGui import (QBrush, QColor, QConicalGradient, QCursor, 15 | QFont, QFontDatabase, QGradient, QIcon, 16 | QImage, QKeySequence, QLinearGradient, QPainter, 17 | QPalette, QPixmap, QRadialGradient, QTransform) 18 | from PySide6.QtWidgets import (QApplication, QMainWindow, QMenuBar, QPushButton, 19 | QSizePolicy, QStatusBar, QWidget) 20 | 21 | class Ui_MainWindow(object): 22 | def setupUi(self, MainWindow): 23 | if not MainWindow.objectName(): 24 | MainWindow.setObjectName(u"MainWindow") 25 | MainWindow.resize(726, 592) 26 | self.centralwidget = QWidget(MainWindow) 27 | self.centralwidget.setObjectName(u"centralwidget") 28 | self.pushButton = QPushButton(self.centralwidget) 29 | self.pushButton.setObjectName(u"pushButton") 30 | self.pushButton.setGeometry(QRect(490, 110, 93, 28)) 31 | MainWindow.setCentralWidget(self.centralwidget) 32 | self.menubar = QMenuBar(MainWindow) 33 | self.menubar.setObjectName(u"menubar") 34 | self.menubar.setGeometry(QRect(0, 0, 726, 26)) 35 | MainWindow.setMenuBar(self.menubar) 36 | self.statusbar = QStatusBar(MainWindow) 37 | self.statusbar.setObjectName(u"statusbar") 38 | MainWindow.setStatusBar(self.statusbar) 39 | 40 | self.retranslateUi(MainWindow) 41 | 42 | QMetaObject.connectSlotsByName(MainWindow) 43 | # setupUi 44 | 45 | def retranslateUi(self, MainWindow): 46 | MainWindow.setWindowTitle(QCoreApplication.translate("MainWindow", u"MainWindow", None)) 47 | self.pushButton.setText(QCoreApplication.translate("MainWindow", u"\u6309\u94ae", None)) 48 | # retranslateUi 49 | 50 | -------------------------------------------------------------------------------- /Chapter02/firstMainWin.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | MainWindow 4 | 5 | 6 | 7 | 0 8 | 0 9 | 726 10 | 592 11 | 12 | 13 | 14 | MainWindow 15 | 16 | 17 | 18 | 19 | 20 | 490 21 | 110 22 | 93 23 | 28 24 | 25 | 26 | 27 | 按钮 28 | 29 | 30 | 31 | 32 | 33 | 34 | 0 35 | 0 36 | 726 37 | 26 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /Chapter02/firstMainWinRun.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | import sys 4 | from PySide6.QtWidgets import QApplication, QMainWindow,QWidget 5 | from firstMainWin import * 6 | 7 | 8 | class MyMainWindow(QMainWindow, Ui_MainWindow): 9 | def __init__(self, parent=None): 10 | super(MyMainWindow, self).__init__(parent) 11 | self.setupUi(self) 12 | 13 | 14 | if __name__ == "__main__": 15 | app = QApplication(sys.argv) 16 | myWin = MyMainWindow() 17 | myWin.show() 18 | sys.exit(app.exec()) 19 | -------------------------------------------------------------------------------- /Chapter02/images/calc.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter02/images/calc.jpg -------------------------------------------------------------------------------- /Chapter02/images/close.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter02/images/close.jpg -------------------------------------------------------------------------------- /Chapter02/images/new.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter02/images/new.jpg -------------------------------------------------------------------------------- /Chapter02/images/notepad.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter02/images/notepad.jpg -------------------------------------------------------------------------------- /Chapter02/images/open.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter02/images/open.jpg -------------------------------------------------------------------------------- /Chapter02/images/python.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter02/images/python.jpg -------------------------------------------------------------------------------- /Chapter02/layoutFirst.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | ################################################################################ 4 | ## Form generated from reading UI file 'layoutFirst.ui' 5 | ## 6 | ## Created by: Qt User Interface Compiler version 6.2.3 7 | ## 8 | ## WARNING! All changes made in this file will be lost when recompiling UI file! 9 | ################################################################################ 10 | 11 | from PySide6.QtCore import (QCoreApplication, QDate, QDateTime, QLocale, 12 | QMetaObject, QObject, QPoint, QRect, 13 | QSize, QTime, QUrl, Qt) 14 | from PySide6.QtGui import (QBrush, QColor, QConicalGradient, QCursor, 15 | QFont, QFontDatabase, QGradient, QIcon, 16 | QImage, QKeySequence, QLinearGradient, QPainter, 17 | QPalette, QPixmap, QRadialGradient, QTransform) 18 | from PySide6.QtWidgets import (QApplication, QHBoxLayout, QLineEdit, QPushButton, 19 | QSizePolicy, QWidget) 20 | 21 | class Ui_Form(object): 22 | def setupUi(self, Form): 23 | if not Form.objectName(): 24 | Form.setObjectName(u"Form") 25 | Form.resize(511, 458) 26 | self.widget = QWidget(Form) 27 | self.widget.setObjectName(u"widget") 28 | self.widget.setGeometry(QRect(51, 43, 215, 26)) 29 | self.horizontalLayout = QHBoxLayout(self.widget) 30 | self.horizontalLayout.setObjectName(u"horizontalLayout") 31 | self.horizontalLayout.setContentsMargins(0, 0, 0, 0) 32 | self.lineEdit_2 = QLineEdit(self.widget) 33 | self.lineEdit_2.setObjectName(u"lineEdit_2") 34 | 35 | self.horizontalLayout.addWidget(self.lineEdit_2) 36 | 37 | self.pushButton_2 = QPushButton(self.widget) 38 | self.pushButton_2.setObjectName(u"pushButton_2") 39 | 40 | self.horizontalLayout.addWidget(self.pushButton_2) 41 | 42 | 43 | self.retranslateUi(Form) 44 | 45 | QMetaObject.connectSlotsByName(Form) 46 | # setupUi 47 | 48 | def retranslateUi(self, Form): 49 | Form.setWindowTitle(QCoreApplication.translate("Form", u"Form", None)) 50 | self.pushButton_2.setText(QCoreApplication.translate("Form", u"\u786e\u5b9a", None)) 51 | # retranslateUi 52 | 53 | -------------------------------------------------------------------------------- /Chapter02/layoutFirst.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | Form 4 | 5 | 6 | 7 | 0 8 | 0 9 | 511 10 | 458 11 | 12 | 13 | 14 | Form 15 | 16 | 17 | 18 | 19 | 51 20 | 43 21 | 215 22 | 26 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 确定 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /Chapter02/layoutWin2Run.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Module implementing LayoutDemo. 5 | """ 6 | 7 | from PySide6.QtCore import Slot 8 | from PySide6.QtWidgets import QMainWindow, QApplication 9 | from layoutWin2 import Ui_LayoutDemo 10 | 11 | 12 | class LayoutDemo(QMainWindow, Ui_LayoutDemo): 13 | """ 14 | Class documentation goes here. 15 | """ 16 | 17 | def __init__(self, parent=None): 18 | """ 19 | Constructor 20 | 21 | @param parent reference to the parent widget 22 | @type QWidget 23 | """ 24 | super(LayoutDemo, self).__init__(parent) 25 | self.setupUi(self) 26 | 27 | @Slot() 28 | def on_pushButton_clicked(self): 29 | """ 30 | Slot documentation goes here. 31 | """ 32 | print('收益_min:', self.doubleSpinBox_returns_min.text()) 33 | print('收益_max:', self.doubleSpinBox_returns_max.text()) 34 | print('最大回撤_min:', self.doubleSpinBox_maxdrawdown_min.text()) 35 | print('最大回撤_max:', self.doubleSpinBox_maxdrawdown_max.text()) 36 | print('sharp比_min:', self.doubleSpinBox_sharp_min.text()) 37 | print('sharp比_max:', self.doubleSpinBox_sharp_max.text()) 38 | 39 | 40 | if __name__ == "__main__": 41 | import sys 42 | 43 | app = QApplication(sys.argv) 44 | ui = LayoutDemo() 45 | ui.show() 46 | sys.exit(app.exec()) 47 | -------------------------------------------------------------------------------- /Chapter02/tool.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | ''' 4 | 【简介】 5 | ui转换成py的转换工具 6 | 7 | ''' 8 | 9 | import os 10 | import os.path 11 | import os 12 | os.chdir(os.path.dirname(__file__)) 13 | 14 | # UI文件所在的路径 15 | dir = './' 16 | 17 | 18 | # 列出目录下的所有ui文件 19 | def listUiFile(): 20 | list = [] 21 | files = os.listdir(dir) 22 | for filename in files: 23 | # print( dir + os.sep + f ) 24 | # print(filename) 25 | if os.path.splitext(filename)[1] == '.ui': 26 | list.append(filename) 27 | 28 | return list 29 | 30 | 31 | # 把后缀为ui的文件改成后缀为py的文件名 32 | def transPyFile(filename): 33 | return os.path.splitext(filename)[0] + '.py' 34 | 35 | 36 | # 调用系统命令把ui转换成py 37 | def runMain(): 38 | list = listUiFile() 39 | for uifile in list: 40 | pyfile = transPyFile(uifile) 41 | # pyqt6适用 42 | # cmd = 'pyuic6 -o {pyfile} {uifile}'.format(pyfile=pyfile, uifile=uifile) 43 | # pyside6适用 44 | cmd = 'pyside6-uic -o {pyfile} {uifile}'.format(pyfile=pyfile, uifile=uifile) 45 | # print(cmd) 46 | os.system(cmd) 47 | 48 | 49 | ###### 程序的主入口 50 | if __name__ == "__main__": 51 | runMain() 52 | -------------------------------------------------------------------------------- /Chapter02/ui_MainWinSignalSlog1.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | ################################################################################ 4 | ## Form generated from reading UI file 'MainWinSignalSlog1.ui' 5 | ## 6 | ## Created by: Qt User Interface Compiler version 6.2.3 7 | ## 8 | ## WARNING! All changes made in this file will be lost when recompiling UI file! 9 | ################################################################################ 10 | 11 | from PySide6.QtCore import (QCoreApplication, QDate, QDateTime, QLocale, 12 | QMetaObject, QObject, QPoint, QRect, 13 | QSize, QTime, QUrl, Qt) 14 | from PySide6.QtGui import (QBrush, QColor, QConicalGradient, QCursor, 15 | QFont, QFontDatabase, QGradient, QIcon, 16 | QImage, QKeySequence, QLinearGradient, QPainter, 17 | QPalette, QPixmap, QRadialGradient, QTransform) 18 | from PySide6.QtWidgets import (QApplication, QPushButton, QSizePolicy, QWidget) 19 | 20 | class Ui_Form(object): 21 | def setupUi(self, Form): 22 | if not Form.objectName(): 23 | Form.setObjectName(u"Form") 24 | Form.resize(452, 296) 25 | self.closeWinBtn = QPushButton(Form) 26 | self.closeWinBtn.setObjectName(u"closeWinBtn") 27 | self.closeWinBtn.setGeometry(QRect(150, 80, 121, 31)) 28 | 29 | self.retranslateUi(Form) 30 | self.closeWinBtn.clicked.connect(Form.close) 31 | self.closeWinBtn.pressed.connect(Form.testSlot) 32 | 33 | QMetaObject.connectSlotsByName(Form) 34 | # setupUi 35 | 36 | def retranslateUi(self, Form): 37 | Form.setWindowTitle(QCoreApplication.translate("Form", u"Form", None)) 38 | self.closeWinBtn.setText(QCoreApplication.translate("Form", u"\u5173\u95ed\u7a97\u53e3", None)) 39 | # retranslateUi 40 | 41 | -------------------------------------------------------------------------------- /Chapter02/ui_firstMainWin.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | ################################################################################ 4 | ## Form generated from reading UI file 'firstMainWin.ui' 5 | ## 6 | ## Created by: Qt User Interface Compiler version 6.2.3 7 | ## 8 | ## WARNING! All changes made in this file will be lost when recompiling UI file! 9 | ################################################################################ 10 | 11 | from PySide6.QtCore import (QCoreApplication, QDate, QDateTime, QLocale, 12 | QMetaObject, QObject, QPoint, QRect, 13 | QSize, QTime, QUrl, Qt) 14 | from PySide6.QtGui import (QBrush, QColor, QConicalGradient, QCursor, 15 | QFont, QFontDatabase, QGradient, QIcon, 16 | QImage, QKeySequence, QLinearGradient, QPainter, 17 | QPalette, QPixmap, QRadialGradient, QTransform) 18 | from PySide6.QtWidgets import (QApplication, QMainWindow, QMenuBar, QPushButton, 19 | QSizePolicy, QStatusBar, QWidget) 20 | 21 | class Ui_MainWindow(object): 22 | def setupUi(self, MainWindow): 23 | if not MainWindow.objectName(): 24 | MainWindow.setObjectName(u"MainWindow") 25 | MainWindow.resize(726, 592) 26 | self.centralwidget = QWidget(MainWindow) 27 | self.centralwidget.setObjectName(u"centralwidget") 28 | self.pushButton = QPushButton(self.centralwidget) 29 | self.pushButton.setObjectName(u"pushButton") 30 | self.pushButton.setGeometry(QRect(490, 110, 93, 28)) 31 | MainWindow.setCentralWidget(self.centralwidget) 32 | self.menubar = QMenuBar(MainWindow) 33 | self.menubar.setObjectName(u"menubar") 34 | self.menubar.setGeometry(QRect(0, 0, 726, 26)) 35 | MainWindow.setMenuBar(self.menubar) 36 | self.statusbar = QStatusBar(MainWindow) 37 | self.statusbar.setObjectName(u"statusbar") 38 | MainWindow.setStatusBar(self.statusbar) 39 | 40 | self.retranslateUi(MainWindow) 41 | 42 | QMetaObject.connectSlotsByName(MainWindow) 43 | # setupUi 44 | 45 | def retranslateUi(self, MainWindow): 46 | MainWindow.setWindowTitle(QCoreApplication.translate("MainWindow", u"MainWindow", None)) 47 | self.pushButton.setText(QCoreApplication.translate("MainWindow", u"\u6309\u94ae", None)) 48 | # retranslateUi 49 | 50 | -------------------------------------------------------------------------------- /Chapter02/ui_layoutFirst.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | ################################################################################ 4 | ## Form generated from reading UI file 'layoutFirst.ui' 5 | ## 6 | ## Created by: Qt User Interface Compiler version 6.2.3 7 | ## 8 | ## WARNING! All changes made in this file will be lost when recompiling UI file! 9 | ################################################################################ 10 | 11 | from PySide6.QtCore import (QCoreApplication, QDate, QDateTime, QLocale, 12 | QMetaObject, QObject, QPoint, QRect, 13 | QSize, QTime, QUrl, Qt) 14 | from PySide6.QtGui import (QBrush, QColor, QConicalGradient, QCursor, 15 | QFont, QFontDatabase, QGradient, QIcon, 16 | QImage, QKeySequence, QLinearGradient, QPainter, 17 | QPalette, QPixmap, QRadialGradient, QTransform) 18 | from PySide6.QtWidgets import (QApplication, QHBoxLayout, QLineEdit, QPushButton, 19 | QSizePolicy, QWidget) 20 | 21 | class Ui_Form(object): 22 | def setupUi(self, Form): 23 | if not Form.objectName(): 24 | Form.setObjectName(u"Form") 25 | Form.resize(511, 458) 26 | self.widget = QWidget(Form) 27 | self.widget.setObjectName(u"widget") 28 | self.widget.setGeometry(QRect(51, 43, 215, 26)) 29 | self.horizontalLayout = QHBoxLayout(self.widget) 30 | self.horizontalLayout.setObjectName(u"horizontalLayout") 31 | self.horizontalLayout.setContentsMargins(0, 0, 0, 0) 32 | self.lineEdit_2 = QLineEdit(self.widget) 33 | self.lineEdit_2.setObjectName(u"lineEdit_2") 34 | 35 | self.horizontalLayout.addWidget(self.lineEdit_2) 36 | 37 | self.pushButton_2 = QPushButton(self.widget) 38 | self.pushButton_2.setObjectName(u"pushButton_2") 39 | 40 | self.horizontalLayout.addWidget(self.pushButton_2) 41 | 42 | 43 | self.retranslateUi(Form) 44 | 45 | QMetaObject.connectSlotsByName(Form) 46 | # setupUi 47 | 48 | def retranslateUi(self, Form): 49 | Form.setWindowTitle(QCoreApplication.translate("Form", u"Form", None)) 50 | self.pushButton_2.setText(QCoreApplication.translate("Form", u"\u786e\u5b9a", None)) 51 | # retranslateUi 52 | 53 | -------------------------------------------------------------------------------- /Chapter03/images/Bold.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter03/images/Bold.png -------------------------------------------------------------------------------- /Chapter03/images/Italic.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter03/images/Italic.png -------------------------------------------------------------------------------- /Chapter03/images/boy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter03/images/boy.png -------------------------------------------------------------------------------- /Chapter03/images/cartoon1.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter03/images/cartoon1.ico -------------------------------------------------------------------------------- /Chapter03/images/cartoon2.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter03/images/cartoon2.ico -------------------------------------------------------------------------------- /Chapter03/images/cartoon3.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter03/images/cartoon3.ico -------------------------------------------------------------------------------- /Chapter03/images/cartoon4.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter03/images/cartoon4.ico -------------------------------------------------------------------------------- /Chapter03/images/cartoon5.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter03/images/cartoon5.ico -------------------------------------------------------------------------------- /Chapter03/images/cartoon6.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter03/images/cartoon6.ico -------------------------------------------------------------------------------- /Chapter03/images/cartoon7.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter03/images/cartoon7.ico -------------------------------------------------------------------------------- /Chapter03/images/cartoon8.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter03/images/cartoon8.ico -------------------------------------------------------------------------------- /Chapter03/images/close.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter03/images/close.ico -------------------------------------------------------------------------------- /Chapter03/images/doc.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter03/images/doc.ico -------------------------------------------------------------------------------- /Chapter03/images/new.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter03/images/new.png -------------------------------------------------------------------------------- /Chapter03/images/open.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter03/images/open.png -------------------------------------------------------------------------------- /Chapter03/images/printer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter03/images/printer.png -------------------------------------------------------------------------------- /Chapter03/images/python.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter03/images/python.jpg -------------------------------------------------------------------------------- /Chapter03/images/python.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter03/images/python.png -------------------------------------------------------------------------------- /Chapter03/images/save.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter03/images/save.png -------------------------------------------------------------------------------- /Chapter03/images/win.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter03/images/win.png -------------------------------------------------------------------------------- /Chapter03/qt_QCalendarWidget.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | ''' 4 | 【简介】 5 | PySide6中 QCalendarWidget 例子 6 | 7 | 8 | ''' 9 | 10 | import sys 11 | from PySide6 import QtCore 12 | from PySide6.QtGui import * 13 | from PySide6.QtWidgets import * 14 | from PySide6.QtCore import QDate 15 | 16 | 17 | class CalendarExample(QWidget): 18 | def __init__(self): 19 | super(CalendarExample, self).__init__() 20 | self.setGeometry(100, 100, 400, 350) 21 | self.setWindowTitle('Calendar 例子') 22 | layout = QVBoxLayout() 23 | self.dateTimeEdit = QDateTimeEdit(self) 24 | self.dateTimeEdit.setCalendarPopup(True) 25 | 26 | 27 | self.cal = QCalendarWidget(self) 28 | self.cal.setMinimumDate(QDate(1980, 1, 1)) 29 | self.cal.setMaximumDate(QDate(3000, 1, 1)) 30 | self.cal.setGridVisible(True) 31 | self.cal.setSelectedDate(QDate(2010, 1, 30)) 32 | self.cal.setHorizontalHeaderFormat(QCalendarWidget.LongDayNames) 33 | # self.cal.setFirstDayOfWeek(Qt.Wednesday) 34 | self.cal.setFirstDayOfWeek(Qt.Wednesday) 35 | self.cal.move(20, 20) 36 | 37 | 38 | self.label = QLabel('此处会显示选择日期信息') 39 | 40 | 41 | self.cal.clicked.connect(lambda :self.showDate(self.cal)) 42 | self.dateTimeEdit.dateChanged.connect(lambda x: self.cal.setSelectedDate(x)) 43 | self.cal.clicked.connect(lambda x: self.dateTimeEdit.setDate(x)) 44 | 45 | layout.addWidget(self.dateTimeEdit) 46 | layout.addWidget(self.cal) 47 | layout.addWidget(self.label) 48 | self.setLayout(layout) 49 | 50 | 51 | 52 | def showDate(self, cal): 53 | date = cal.selectedDate().toString("yyyy-MM-dd dddd") 54 | month = cal.monthShown() 55 | year = cal.yearShown() 56 | _str = '当前选择日期: %s;\n当前选择月份: %s;\n当前选择年份: %s;'%(date,month,year) 57 | self.label.setText(_str) 58 | 59 | 60 | if __name__ == '__main__': 61 | app = QApplication(sys.argv) 62 | demo = CalendarExample() 63 | demo.show() 64 | sys.exit(app.exec()) 65 | -------------------------------------------------------------------------------- /Chapter03/qt_QCommandLinkButton.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | ''' 4 | 【简介】 5 | PySide6中QButton例子 6 | 7 | 8 | ''' 9 | 10 | import sys 11 | from PySide6.QtCore import * 12 | from PySide6.QtGui import * 13 | from PySide6.QtWidgets import * 14 | import os 15 | os.chdir(os.path.dirname(__file__)) 16 | 17 | class CommandLinkButtonDemo(QDialog): 18 | def __init__(self, parent=None): 19 | super(CommandLinkButtonDemo, self).__init__(parent) 20 | layout = QVBoxLayout() 21 | self.label_show = QLabel('显示按钮信息') 22 | layout.addWidget(self.label_show) 23 | 24 | self.button1 = QCommandLinkButton("默认按钮") 25 | self.button1.setCheckable(True) 26 | self.button1.toggle() 27 | self.button1.clicked.connect(lambda: self.button_click(self.button1)) 28 | layout.addWidget(self.button1) 29 | 30 | self.button_descript = QCommandLinkButton("描述按钮",'描述信息') 31 | self.button_descript.clicked.connect(lambda: self.button_click(self.button_descript)) 32 | layout.addWidget(self.button_descript) 33 | 34 | self.button_image = QCommandLinkButton('图片按钮') 35 | self.button_image.setCheckable(True) 36 | self.button_image.setDescription('设置自定义图片') 37 | self.button_image.setIcon(QIcon("./images/python.png")) 38 | self.button_image.clicked.connect(lambda: self.button_click(self.button_image)) 39 | layout.addWidget(self.button_image) 40 | 41 | 42 | self.setWindowTitle("QCommandLinkButton demo") 43 | self.setLayout(layout) 44 | 45 | 46 | def button_click(self, button): 47 | if button.isChecked(): 48 | self.label_show.setText('你按下了 ' + button.text() + " isChecked=True") 49 | else: 50 | self.label_show.setText('你按下了 ' + button.text() + " isChecked=False") 51 | 52 | 53 | if __name__ == '__main__': 54 | app = QApplication(sys.argv) 55 | btnDemo = CommandLinkButtonDemo() 56 | btnDemo.show() 57 | sys.exit(app.exec()) 58 | -------------------------------------------------------------------------------- /Chapter03/qt_QDial.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | ''' 4 | 【简介】 5 | PySide6中 QDial 例子 6 | ''' 7 | 8 | import sys 9 | from PySide6.QtCore import * 10 | from PySide6.QtGui import * 11 | from PySide6.QtWidgets import * 12 | 13 | 14 | class dialDemo(QWidget): 15 | def __init__(self, parent=None): 16 | super(dialDemo, self).__init__(parent) 17 | self.setWindowTitle("QDial 例子") 18 | self.resize(300, 100) 19 | 20 | layout = QVBoxLayout() 21 | self.label = QLabel("Hello Qt for Python") 22 | self.label.setAlignment(Qt.AlignCenter) 23 | layout.addWidget(self.label) 24 | 25 | # 普通qdial 26 | self.dial1 = QDial() 27 | self.dial1.setMinimum(10) 28 | self.dial1.setMaximum(50) 29 | self.dial1.setSingleStep(3) 30 | self.dial1.setPageStep(5) 31 | self.dial1.setValue(20) 32 | layout.addWidget(self.dial1) 33 | 34 | # 开启循环 35 | self.dial_wrap = QDial() 36 | self.dial_wrap.setMinimum(5) 37 | self.dial_wrap.setMaximum(25) 38 | self.dial_wrap.setSingleStep(1) 39 | self.dial_wrap.setPageStep(5) 40 | self.dial_wrap.setValue(15) 41 | self.dial_wrap.setWrapping(True) 42 | self.dial_wrap.setMinimumHeight(100) 43 | layout.addWidget(self.dial_wrap) 44 | 45 | # 连接信号槽 46 | self.dial1.valueChanged.connect(lambda :self.valuechange(self.dial1)) 47 | self.dial_wrap.valueChanged.connect(lambda :self.valuechange(self.dial_wrap)) 48 | 49 | self.setLayout(layout) 50 | 51 | def valuechange(self,dial): 52 | size = dial.value() 53 | self.label.setText('选中大小:%d'%size) 54 | self.label.setFont(QFont("Arial", size)) 55 | 56 | 57 | if __name__ == '__main__': 58 | app = QApplication(sys.argv) 59 | app.setWheelScrollLines(2) 60 | demo = dialDemo() 61 | demo.show() 62 | sys.exit(app.exec()) 63 | -------------------------------------------------------------------------------- /Chapter03/qt_QLabel2.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | ''' 4 | 【简介】 5 | PySide6中Qlabel例子 6 | 按住 Alt + N , Alt + P , Alt + O , Alt + C 切换组件控件 7 | 8 | ''' 9 | 10 | from PySide6.QtWidgets import * 11 | import sys 12 | 13 | 14 | class QLabelDemo(QDialog): 15 | def __init__(self): 16 | super().__init__() 17 | 18 | self.setWindowTitle('Qlabel 例子') 19 | nameLb1 = QLabel('&Name', self) 20 | nameEd1 = QLineEdit(self) 21 | nameLb1.setBuddy(nameEd1) 22 | 23 | nameLb2 = QLabel('&Password', self) 24 | nameEd2 = QLineEdit(self) 25 | nameLb2.setBuddy(nameEd2) 26 | 27 | btnOk = QPushButton('&OK') 28 | btnCancel = QPushButton('&Cancel') 29 | mainLayout = QGridLayout(self) 30 | mainLayout.addWidget(nameLb1, 0, 0) 31 | mainLayout.addWidget(nameEd1, 0, 1, 1, 2) 32 | 33 | mainLayout.addWidget(nameLb2, 1, 0) 34 | mainLayout.addWidget(nameEd2, 1, 1, 1, 2) 35 | 36 | mainLayout.addWidget(btnOk, 2, 1) 37 | mainLayout.addWidget(btnCancel, 2, 2) 38 | 39 | 40 | 41 | if __name__ == "__main__": 42 | app = QApplication(sys.argv) 43 | labelDemo = QLabelDemo() 44 | labelDemo.show() 45 | sys.exit(app.exec()) 46 | -------------------------------------------------------------------------------- /Chapter03/qt_QLineEdit_EchoMode.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | ''' 4 | 【简介】 5 | PySide6中 QLineEdit.EchoMode效果例子 6 | 7 | ''' 8 | 9 | from PySide6.QtWidgets import QApplication, QLineEdit, QWidget, QFormLayout 10 | import sys 11 | 12 | 13 | class lineEditDemo(QWidget): 14 | def __init__(self, parent=None): 15 | super(lineEditDemo, self).__init__(parent) 16 | self.setWindowTitle("QLineEdit_EchoMode例子") 17 | 18 | flo = QFormLayout() 19 | pNormalLineEdit = QLineEdit() 20 | pNoEchoLineEdit = QLineEdit() 21 | pPasswordLineEdit = QLineEdit() 22 | pPasswordEchoOnEditLineEdit = QLineEdit() 23 | 24 | flo.addRow("Normal", pNormalLineEdit) 25 | flo.addRow("NoEcho", pNoEchoLineEdit) 26 | flo.addRow("Password", pPasswordLineEdit) 27 | flo.addRow("PasswordEchoOnEdit", pPasswordEchoOnEditLineEdit) 28 | 29 | pNormalLineEdit.setPlaceholderText("Normal") 30 | pNoEchoLineEdit.setPlaceholderText("NoEcho") 31 | pPasswordLineEdit.setPlaceholderText("Password") 32 | pPasswordEchoOnEditLineEdit.setPlaceholderText("PasswordEchoOnEdit") 33 | 34 | # 设置显示效果 35 | pNormalLineEdit.setEchoMode(QLineEdit.Normal) 36 | pNoEchoLineEdit.setEchoMode(QLineEdit.NoEcho) 37 | pPasswordLineEdit.setEchoMode(QLineEdit.Password) 38 | pPasswordEchoOnEditLineEdit.setEchoMode(QLineEdit.PasswordEchoOnEdit) 39 | 40 | self.setLayout(flo) 41 | 42 | 43 | if __name__ == "__main__": 44 | app = QApplication(sys.argv) 45 | win = lineEditDemo() 46 | win.show() 47 | sys.exit(app.exec()) 48 | -------------------------------------------------------------------------------- /Chapter03/qt_QLineEdit_InputMask.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | ''' 4 | 【简介】 5 | PySide6中 QLineEdit的输入掩码例子 6 | 7 | ''' 8 | 9 | from PySide6.QtWidgets import QApplication, QLineEdit, QWidget, QFormLayout 10 | import sys 11 | 12 | 13 | class lineEditDemo(QWidget): 14 | def __init__(self, parent=None): 15 | super(lineEditDemo, self).__init__(parent) 16 | self.setWindowTitle("QLineEdit的输入掩码例子") 17 | 18 | flo = QFormLayout() 19 | pIPLineEdit = QLineEdit() 20 | pMACLineEdit = QLineEdit() 21 | pDateLineEdit = QLineEdit() 22 | pLicenseLineEdit = QLineEdit() 23 | 24 | pIPLineEdit.setInputMask("000.000.000.000_") 25 | pMACLineEdit.setInputMask("HH:HH:HH:HH:HH:HH_") 26 | pDateLineEdit.setInputMask("0000-00-00") 27 | pLicenseLineEdit.setInputMask(">AAAAA-AAAAA-AAAAA-AAAAA-AAAAA#") 28 | 29 | flo.addRow("数字掩码", pIPLineEdit) 30 | flo.addRow("Mac掩码", pMACLineEdit) 31 | flo.addRow("日期掩码", pDateLineEdit) 32 | flo.addRow("许可证掩码", pLicenseLineEdit) 33 | 34 | pIPLineEdit.setToolTip("ip: 192.168.*") 35 | pMACLineEdit.setToolTip("mac: ac:be:ad:*") 36 | pDateLineEdit.setToolTip("date: 2020-01-01") 37 | pLicenseLineEdit.setToolTip("许可证: HDFG-ADDB-*") 38 | 39 | self.setLayout(flo) 40 | 41 | 42 | if __name__ == "__main__": 43 | app = QApplication(sys.argv) 44 | win = lineEditDemo() 45 | win.show() 46 | sys.exit(app.exec()) 47 | -------------------------------------------------------------------------------- /Chapter03/qt_QLineEdit_QValidator.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | ''' 4 | 【简介】 5 | PySide6中 QLineEdit的验证器QValidator例子 6 | 7 | ''' 8 | 9 | from PySide6.QtWidgets import QApplication, QLineEdit, QWidget, QFormLayout 10 | from PySide6.QtGui import QIntValidator, QDoubleValidator, QRegularExpressionValidator 11 | from PySide6.QtCore import QRegularExpression 12 | import sys 13 | 14 | 15 | class lineEditDemo(QWidget): 16 | def __init__(self, parent=None): 17 | super(lineEditDemo, self).__init__(parent) 18 | self.setWindowTitle("QLineEdit例子QValidator") 19 | 20 | flo = QFormLayout() 21 | pIntLineEdit = QLineEdit() 22 | pDoubleLineEdit = QLineEdit() 23 | pValidatorLineEdit = QLineEdit() 24 | 25 | flo.addRow("整形", pIntLineEdit) 26 | flo.addRow("浮点型", pDoubleLineEdit) 27 | flo.addRow("字母和数字", pValidatorLineEdit) 28 | 29 | pIntLineEdit.setPlaceholderText("整形") 30 | pDoubleLineEdit.setPlaceholderText("浮点型") 31 | pValidatorLineEdit.setPlaceholderText("字母和数字") 32 | 33 | # 整形 范围:[1, 99] 34 | pIntValidator = QIntValidator(self) 35 | pIntValidator.setRange(1, 99) 36 | 37 | # 浮点型 范围:[-360, 360] 精度:小数点后2位 38 | pDoubleValidator = QDoubleValidator(self) 39 | pDoubleValidator.setRange(-360.0, 360.0) 40 | pDoubleValidator.setNotation(QDoubleValidator.StandardNotation) 41 | pDoubleValidator.setDecimals(2) 42 | 43 | 44 | # 字符和数字 45 | reg = QRegularExpression("[a-zA-Z0-9]+$") 46 | pValidator = QRegularExpressionValidator(self) 47 | pValidator.setRegularExpression(reg) 48 | 49 | # 设置验证器 50 | pIntLineEdit.setValidator(pIntValidator) 51 | pDoubleLineEdit.setValidator(pDoubleValidator) 52 | pValidatorLineEdit.setValidator(pValidator) 53 | 54 | # QDoubleValidator无法限制QLineEdit数据输入大小,因此这里手动添加限制。 55 | pDoubleLineEdit.textChanged[str].connect( 56 | lambda x: self.input_validate(x,pDoubleValidator, pDoubleLineEdit)) 57 | self.last_text = '' 58 | 59 | self.setLayout(flo) 60 | 61 | 62 | 63 | def input_validate(self,text, pDoubleValidator, pDoubleLineEdit): 64 | if float(text) > pDoubleValidator.top() or float(text) < pDoubleValidator.bottom(): 65 | pDoubleLineEdit.setText(self.last_text) 66 | else: 67 | self.last_text =text 68 | 69 | 70 | 71 | if __name__ == "__main__": 72 | app = QApplication(sys.argv) 73 | win = lineEditDemo() 74 | win.show() 75 | sys.exit(app.exec()) 76 | -------------------------------------------------------------------------------- /Chapter03/qt_QPlainTextEdit.py: -------------------------------------------------------------------------------- 1 | from PySide6.QtWidgets import QApplication, QWidget, QTextEdit,QPlainTextEdit, QVBoxLayout, QPushButton 2 | from PySide6.QtGui import QFont 3 | import sys 4 | 5 | 6 | class TextEditDemo(QWidget): 7 | def __init__(self, parent=None): 8 | super(TextEditDemo, self).__init__(parent) 9 | self.setWindowTitle("QPlainTextEdit 例子") 10 | self.resize(300, 270) 11 | self.textEdit = QPlainTextEdit() 12 | # 布局管理 13 | layout = QVBoxLayout() 14 | layout.addWidget(self.textEdit) 15 | 16 | # 显示文本 17 | self.btn_plain = QPushButton("显示纯文本") 18 | self.btn_plain.clicked.connect(self.btn_plain_Clicked) 19 | layout.addWidget(self.btn_plain) 20 | 21 | self.setLayout(layout) 22 | 23 | def btn_plain_Clicked(self): 24 | font = QFont() 25 | font.setFamily("Courier") 26 | font.setFixedPitch(True) 27 | font.setPointSize(14) 28 | self.textEdit.setFont(font) 29 | self.textEdit.setPlainText("Hello Qt for Python!\n单击按钮") 30 | 31 | if __name__ == "__main__": 32 | app = QApplication(sys.argv) 33 | win = TextEditDemo() 34 | win.show() 35 | sys.exit(app.exec()) 36 | -------------------------------------------------------------------------------- /Chapter03/qt_QPushButton.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | ''' 4 | 【简介】 5 | PySide6中QButton例子 6 | 7 | 8 | ''' 9 | 10 | import sys 11 | from PySide6.QtCore import * 12 | from PySide6.QtGui import * 13 | from PySide6.QtWidgets import * 14 | import os 15 | os.chdir(os.path.dirname(__file__)) 16 | 17 | class Form(QDialog): 18 | def __init__(self, parent=None): 19 | super(Form, self).__init__(parent) 20 | layout = QVBoxLayout() 21 | self.label_show = QLabel('显示按钮信息') 22 | layout.addWidget(self.label_show) 23 | 24 | self.button1 = QPushButton("Button1") 25 | self.button1.setCheckable(True) 26 | self.button1.toggle() 27 | self.button1.clicked.connect(lambda: self.button_click(self.button1)) 28 | layout.addWidget(self.button1) 29 | 30 | self.button_image = QPushButton('image') 31 | self.button_image.setCheckable(True) 32 | self.button_image.setIcon(QIcon(QPixmap("./images/python.png"))) 33 | self.button_image.clicked.connect(lambda: self.button_click(self.button_image)) 34 | layout.addWidget(self.button_image) 35 | 36 | self.button_disabled = QPushButton("Disabled") 37 | self.button_disabled.setEnabled(False) 38 | layout.addWidget(self.button_disabled) 39 | 40 | self.button_shortcut = QPushButton("&Shortcut_Key") 41 | self.button_shortcut.setDefault(True) 42 | self.button_shortcut.setCheckable(True) 43 | self.button_shortcut.clicked.connect(lambda: self.button_click(self.button_shortcut)) 44 | layout.addWidget(self.button_shortcut) 45 | 46 | self.setWindowTitle("Button demo") 47 | self.setLayout(layout) 48 | 49 | 50 | def button_click(self, button): 51 | if button.isChecked(): 52 | self.label_show.setText('你按下了' + button.text() + " isChecked=True") 53 | else: 54 | self.label_show.setText('你按下了' + button.text() + " isChecked=False") 55 | 56 | 57 | if __name__ == '__main__': 58 | app = QApplication(sys.argv) 59 | btnDemo = Form() 60 | btnDemo.show() 61 | sys.exit(app.exec()) 62 | -------------------------------------------------------------------------------- /Chapter03/qt_QScrollBar.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | ''' 4 | 【简介】 5 | PySide6中 QScrollBar 例子 6 | 7 | 8 | ''' 9 | 10 | import sys 11 | from PySide6.QtCore import * 12 | from PySide6.QtGui import * 13 | from PySide6.QtWidgets import * 14 | 15 | 16 | class Example(QWidget): 17 | def __init__(self): 18 | super(Example, self).__init__() 19 | self.initUI() 20 | 21 | def initUI(self): 22 | hbox = QHBoxLayout() 23 | self.label = QLabel("拖动滑动条去改变颜色") 24 | self.label.setFont(QFont("Arial", 16)) 25 | hbox.addWidget(self.label) 26 | 27 | self.scrollbar1 = QScrollBar() 28 | self.scrollbar1.setMaximum(255) 29 | self.scrollbar1.sliderMoved.connect(self.sliderval) 30 | hbox.addWidget(self.scrollbar1) 31 | 32 | self.scrollbar2 = QScrollBar() 33 | self.scrollbar2.setMaximum(255) 34 | self.scrollbar2.setSingleStep(5) 35 | self.scrollbar2.setPageStep(50) 36 | self.scrollbar2.setValue(150) 37 | self.scrollbar2.setFocusPolicy(Qt.StrongFocus) 38 | self.scrollbar2.valueChanged.connect(self.sliderval) 39 | hbox.addWidget(self.scrollbar2) 40 | 41 | self.scrollbar3 = QScrollBar() 42 | self.scrollbar3.setMaximum(255) 43 | self.scrollbar3.setSingleStep(5) 44 | self.scrollbar3.setPageStep(50) 45 | self.scrollbar3.setValue(100) 46 | self.scrollbar3.setFocusPolicy(Qt.TabFocus) 47 | self.scrollbar3.valueChanged.connect(self.sliderval) 48 | hbox.addWidget(self.scrollbar3) 49 | 50 | self.setGeometry(300, 300, 300, 200) 51 | self.setWindowTitle('QScrollBar 例子') 52 | self.setLayout(hbox) 53 | 54 | def sliderval(self): 55 | value_tup = (self.scrollbar1.value(), self.scrollbar2.value(), self.scrollbar3.value()) 56 | _str = "拖动滑动条去改变颜色:\n左边不支持键盘,\n中间通过tab键or点击获取焦点,\n右边只能通过tab键获取焦点。\n当前选中(%d,%d,%d)"%value_tup 57 | palette = QPalette() 58 | palette.setColor(QPalette.WindowText, QColor(*value_tup, 255)) 59 | self.label.setPalette(palette) 60 | self.label.setText(_str) 61 | 62 | 63 | if __name__ == '__main__': 64 | app = QApplication(sys.argv) 65 | demo = Example() 66 | demo.show() 67 | sys.exit(app.exec()) 68 | -------------------------------------------------------------------------------- /Chapter03/qt_QSlider.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | ''' 4 | 【简介】 5 | PySide6中 QSlider 例子 6 | ''' 7 | 8 | import sys 9 | from PySide6.QtCore import * 10 | from PySide6.QtGui import * 11 | from PySide6.QtWidgets import * 12 | 13 | 14 | class SliderDemo(QWidget): 15 | def __init__(self, parent=None): 16 | super(SliderDemo, self).__init__(parent) 17 | self.setWindowTitle("QSlider 例子") 18 | self.resize(300, 100) 19 | 20 | layout = QVBoxLayout() 21 | self.label = QLabel("Hello Qt for Python") 22 | self.label.setAlignment(Qt.AlignCenter) 23 | layout.addWidget(self.label) 24 | 25 | # 水平滑块 26 | self.slider_horizon = QSlider(Qt.Horizontal) 27 | self.slider_horizon.setMinimum(10) 28 | self.slider_horizon.setMaximum(50) 29 | self.slider_horizon.setSingleStep(3) 30 | self.slider_horizon.setPageStep(10) 31 | self.slider_horizon.setValue(20) 32 | self.slider_horizon.setTickPosition(QSlider.TicksBelow) 33 | self.slider_horizon.setTickInterval(5) 34 | layout.addWidget(self.slider_horizon) 35 | 36 | # 垂直滑块 37 | self.slider_vertical = QSlider(Qt.Vertical) 38 | self.slider_vertical.setMinimum(5) 39 | self.slider_vertical.setMaximum(25) 40 | self.slider_vertical.setSingleStep(1) 41 | self.slider_vertical.setPageStep(5) 42 | self.slider_vertical.setValue(15) 43 | self.slider_vertical.setTickPosition(QSlider.TicksRight) 44 | self.slider_vertical.setTickInterval(5) 45 | self.slider_vertical.setMinimumHeight(100) 46 | layout.addWidget(self.slider_vertical) 47 | 48 | # 连接信号槽 49 | self.slider_horizon.valueChanged.connect(lambda :self.valuechange(self.slider_horizon)) 50 | self.slider_vertical.valueChanged.connect(lambda :self.valuechange(self.slider_vertical)) 51 | 52 | self.setLayout(layout) 53 | 54 | def valuechange(self,slider): 55 | size = slider.value() 56 | self.label.setText('选中大小:%d'%size) 57 | self.label.setFont(QFont("Arial", size)) 58 | 59 | 60 | if __name__ == '__main__': 61 | app = QApplication(sys.argv) 62 | demo = SliderDemo() 63 | demo.show() 64 | sys.exit(app.exec()) 65 | -------------------------------------------------------------------------------- /Chapter03/qt_QSpinBox2.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | ''' 4 | 【简介】 5 | PySide6中 QSpinBox 例子 6 | 7 | 8 | ''' 9 | 10 | import sys 11 | from PySide6.QtCore import * 12 | from PySide6.QtGui import * 13 | from PySide6.QtWidgets import * 14 | 15 | 16 | class myQSpinBox(QSpinBox): 17 | def __init__(self, parent=None): 18 | super(myQSpinBox, self).__init__(parent) 19 | 20 | def valueFromText(self, text): 21 | regExp = QRegularExpression("(\\d+)(\\s*[xx]\\s*\\d+)?") 22 | match = regExp.match(text) 23 | if match.isValid(): 24 | return match.captured(1).toInt() 25 | return 0 26 | 27 | def textFromValue(self, val): 28 | return ('%s x %s' % (val, val)) 29 | 30 | 31 | class spindemo(QWidget): 32 | def __init__(self, parent=None): 33 | super(spindemo, self).__init__(parent) 34 | self.setWindowTitle("SpinBox 例子") 35 | self.resize(300, 100) 36 | 37 | layout = QFormLayout() 38 | 39 | self.label = QLabel("current value:") 40 | # self.label.setAlignment(Qt.AlignCenter) 41 | self.label.setAlignment(Qt.AlignLeft) 42 | layout.addWidget(self.label) 43 | 44 | self.spinbox = myQSpinBox() 45 | layout.addRow(QLabel('自定义显示:'), self.spinbox) 46 | self.spinbox.valueChanged.connect(lambda: self.on_valuechange(self.spinbox)) 47 | 48 | 49 | self.setLayout(layout) 50 | 51 | def on_valuechange(self, spinbox): 52 | self.label.setText("current value:" + str(spinbox.value())) 53 | 54 | 55 | if __name__ == '__main__': 56 | app = QApplication(sys.argv) 57 | ex = spindemo() 58 | ex.show() 59 | sys.exit(app.exec()) 60 | -------------------------------------------------------------------------------- /Chapter03/qt_QTextEdit.py: -------------------------------------------------------------------------------- 1 | from PySide6.QtWidgets import QApplication, QWidget, QTextEdit, QVBoxLayout, QPushButton 2 | from PySide6.QtGui import QColor,QFont 3 | import sys 4 | import os 5 | os.chdir(os.path.dirname(__file__)) 6 | 7 | class TextEditDemo(QWidget): 8 | def __init__(self, parent=None): 9 | super(TextEditDemo, self).__init__(parent) 10 | self.setWindowTitle("QTextEdit 例子") 11 | self.resize(300, 270) 12 | self.textEdit = QTextEdit() 13 | # 布局管理 14 | layout = QVBoxLayout() 15 | layout.addWidget(self.textEdit) 16 | 17 | # 显示文本 18 | self.btn_plain = QPushButton("显示纯文本") 19 | self.btn_plain.clicked.connect(self.btn_plain_Clicked) 20 | layout.addWidget(self.btn_plain) 21 | 22 | # 显示html 23 | self.btn_html = QPushButton("显示HTML") 24 | self.btn_html.clicked.connect(self.btn_html_Clicked) 25 | layout.addWidget(self.btn_html) 26 | 27 | # 显示markdown 28 | self.btn_markdown = QPushButton("显示markdown") 29 | self.btn_markdown.clicked.connect(self.btn_markdown_Clicked) 30 | layout.addWidget(self.btn_markdown) 31 | 32 | 33 | self.setLayout(layout) 34 | 35 | def btn_plain_Clicked(self): 36 | self.textEdit.setFontItalic(True) 37 | self.textEdit.setFontWeight(QFont.ExtraBold) 38 | self.textEdit.setFontUnderline(True) 39 | self.textEdit.setFontFamily('宋体') 40 | self.textEdit.setFontPointSize(15) 41 | self.textEdit.setTextColor(QColor(200,75,75)) 42 | # self.textEdit.setText('Hello Qt for Python!\n单击按钮') 43 | self.textEdit.setPlainText("Hello Qt for Python!\n单击按钮") 44 | 45 | 46 | def btn_html_Clicked(self): 47 | a = '' 48 | 49 | dirname = _path = os.path.dirname(__file__) 50 | with open(dirname+'\support\myhtml.html', 'r', encoding='utf8') as f: 51 | a = f.read() 52 | self.textEdit.setHtml(a) 53 | 54 | 55 | 56 | def btn_markdown_Clicked(self): 57 | a = '' 58 | dirname = _path = os.path.dirname(__file__) 59 | with open(dirname+'\support\myMarkDown.md', 'r', encoding='utf8') as f: 60 | a = f.read() 61 | self.textEdit.setMarkdown(a) 62 | 63 | 64 | 65 | if __name__ == "__main__": 66 | app = QApplication(sys.argv) 67 | win = TextEditDemo() 68 | win.show() 69 | sys.exit(app.exec()) 70 | -------------------------------------------------------------------------------- /Chapter03/support/myMarkDown.md: -------------------------------------------------------------------------------- 1 | # 一级标题 2 | ## 二级标题 3 | ### 三级标题 4 | 正文 5 | 6 | **显示图片** 7 | 8 | ![加载图片](images\cartoon1.ico) 9 | 10 | **显示表格** 11 | 12 | | 一个普通标题 | 一个普通标题 | 一个普通标题 | 13 | | ------ | ------ | ------ | 14 | | 短文本 | 中等文本 | 稍微长一点的文本 | 15 | | 稍微长一点的文本 | 短文本 | 中等文本 | -------------------------------------------------------------------------------- /Chapter03/support/myhtml.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Title 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 |
ID名称年龄
1zekai18
2zekai218
3zekai318
59 | 60 | 61 | -------------------------------------------------------------------------------- /Chapter03/support/textBrowser.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Title 6 | 7 | 8 |

1、页外跳转

9 |
10 | Bold
11 | Italic
12 | 内连接:进入其他html页面
13 | 内连接:进入其他md页面
14 | 内连接:进入初始html页面
15 | 外连接:百度
16 | Red
17 | 10px
18 |

2、页内跳转

19 |
20 | 这里是顶部的锚,显示美国历届总统
21 | 第1任
22 | 第2任
23 | 第3任
24 | 第4任
25 | 第5任
26 | 第6任
27 | 28 | 美国历届总统:
29 | ●第1任(1789-1797)这里是第1任的锚
30 | 姓名:乔治·华盛顿
31 | George Washington
32 | 生卒:1732-1799
33 | 政党::联邦
34 | ●第2任(1797-1801)这里是第2任的锚
35 | 姓名:约翰·亚当斯
36 | John Adams
37 | 生卒:1735-1826
38 | 政党::联邦
39 | ●第3任(1801-1809)这里是第3任的锚
40 | 姓名:托马斯·杰斐逊
41 | Thomas Jefferson
42 | 生卒:1743-1826
43 | 政党::民共
44 | ●第4任(1809-1817)这里是第4任的锚
45 | 姓名:詹姆斯·麦迪逊
46 | James Madison
47 | 生卒:1751-1836
48 | 政党:民共
49 | ●第5任(1817-1825)这里是第5任的锚
50 | 姓名:詹姆斯·门罗
51 | James Monroe
52 | 生卒:1758-1831
53 | 政党:民共
54 | 55 | -------------------------------------------------------------------------------- /Chapter04/images/Bold.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter04/images/Bold.png -------------------------------------------------------------------------------- /Chapter04/images/Italic.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter04/images/Italic.png -------------------------------------------------------------------------------- /Chapter04/images/ajax-loading.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter04/images/ajax-loading.gif -------------------------------------------------------------------------------- /Chapter04/images/boy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter04/images/boy.png -------------------------------------------------------------------------------- /Chapter04/images/cartoon1.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter04/images/cartoon1.ico -------------------------------------------------------------------------------- /Chapter04/images/cartoon2.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter04/images/cartoon2.ico -------------------------------------------------------------------------------- /Chapter04/images/cartoon3.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter04/images/cartoon3.ico -------------------------------------------------------------------------------- /Chapter04/images/cartoon4.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter04/images/cartoon4.ico -------------------------------------------------------------------------------- /Chapter04/images/cartoon5.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter04/images/cartoon5.ico -------------------------------------------------------------------------------- /Chapter04/images/cartoon6.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter04/images/cartoon6.ico -------------------------------------------------------------------------------- /Chapter04/images/cartoon7.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter04/images/cartoon7.ico -------------------------------------------------------------------------------- /Chapter04/images/cartoon8.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter04/images/cartoon8.ico -------------------------------------------------------------------------------- /Chapter04/images/close.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter04/images/close.ico -------------------------------------------------------------------------------- /Chapter04/images/doc.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter04/images/doc.ico -------------------------------------------------------------------------------- /Chapter04/images/down.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter04/images/down.png -------------------------------------------------------------------------------- /Chapter04/images/left.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter04/images/left.png -------------------------------------------------------------------------------- /Chapter04/images/mask.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter04/images/mask.png -------------------------------------------------------------------------------- /Chapter04/images/mask2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter04/images/mask2.png -------------------------------------------------------------------------------- /Chapter04/images/new.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter04/images/new.png -------------------------------------------------------------------------------- /Chapter04/images/open.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter04/images/open.png -------------------------------------------------------------------------------- /Chapter04/images/printer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter04/images/printer.png -------------------------------------------------------------------------------- /Chapter04/images/python.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter04/images/python.jpg -------------------------------------------------------------------------------- /Chapter04/images/python.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter04/images/python.png -------------------------------------------------------------------------------- /Chapter04/images/right.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter04/images/right.png -------------------------------------------------------------------------------- /Chapter04/images/save.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter04/images/save.png -------------------------------------------------------------------------------- /Chapter04/images/up.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter04/images/up.png -------------------------------------------------------------------------------- /Chapter04/images/win.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter04/images/win.png -------------------------------------------------------------------------------- /Chapter04/painting/images/brick.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter04/painting/images/brick.png -------------------------------------------------------------------------------- /Chapter04/painting/images/qt-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter04/painting/images/qt-logo.png -------------------------------------------------------------------------------- /Chapter04/qt_QFontDialog.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | ''' 4 | 【简介】 5 | PySide6中 QFontDialog 例子 6 | 7 | 8 | ''' 9 | 10 | import sys 11 | from PySide6.QtCore import * 12 | from PySide6.QtGui import * 13 | from PySide6.QtWidgets import * 14 | 15 | 16 | class FontDialogDemo(QWidget): 17 | def __init__(self, parent=None): 18 | super(FontDialogDemo, self).__init__(parent) 19 | layout = QVBoxLayout() 20 | 21 | self.fontLabel = QLabel("Hello,我来显示字体效果") 22 | layout.addWidget(self.fontLabel) 23 | 24 | self.fontButton1 = QPushButton("设置QLabel字体") 25 | self.fontButton1.clicked.connect(self.set_label_font) 26 | layout.addWidget(self.fontButton1) 27 | 28 | self.fontButton2 = QPushButton("设置Qwidget字体") 29 | self.fontButton2.clicked.connect(lambda:self.setFont(QFontDialog.getFont(self.font(),self)[1])) 30 | layout.addWidget(self.fontButton2) 31 | 32 | self.setLayout(layout) 33 | self.setWindowTitle("Font Dialog 例子") 34 | # self.setFont(QFontDialog.getFont(self.font(),self)[1]) 35 | 36 | def set_label_font(self): 37 | ok, font = QFontDialog.getFont() 38 | if ok: 39 | self.fontLabel.setFont(font) 40 | 41 | 42 | if __name__ == '__main__': 43 | app = QApplication(sys.argv) 44 | demo = FontDialogDemo() 45 | demo.show() 46 | sys.exit(app.exec()) 47 | -------------------------------------------------------------------------------- /Chapter04/qt_QLCDNumber.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import time 3 | 4 | from PySide6.QtCore import * 5 | from PySide6.QtGui import * 6 | from PySide6.QtWidgets import * 7 | 8 | 9 | class LCDNumberDemo(QWidget): 10 | def __init__(self, parent=None): 11 | super(LCDNumberDemo, self).__init__(parent) 12 | layout = QFormLayout() 13 | self.setLayout(layout) 14 | 15 | # 标准lcd 16 | self.lcd = QLCDNumber(self) 17 | self.lcd.display(time.strftime('%Y/%m-%d', time.localtime())) 18 | layout.addRow('标准lcd:', self.lcd) 19 | 20 | # 修改可显示数字长度 21 | self.lcd_count = QLCDNumber(self) 22 | self.lcd_count.setDigitCount(10) 23 | self.lcd_count.display(time.strftime('%Y/%m-%d', time.localtime())) 24 | layout.addRow('修改显示长度:', self.lcd_count) 25 | 26 | # 修改可显示类型 27 | self.lcd_style = QLCDNumber(self) 28 | self.lcd_style.setDigitCount(8) 29 | self.lcd_style.setSegmentStyle(self.lcd_style.Flat) 30 | layout.addRow('修改显示类型:', self.lcd_style) 31 | 32 | # 修改可显示模式 33 | self.lcd_mode = QLCDNumber(self) 34 | self.lcd_mode.setMode(QLCDNumber.Mode.Bin) 35 | self.lcd_mode.setDigitCount(8) 36 | self.lcd_mode.display(18) 37 | layout.addRow('18以2进制形式显示:', self.lcd_mode) 38 | 39 | # 定时器 40 | timer = QTimer(self) 41 | timer.timeout.connect(self.showTime) 42 | timer.start(1000) 43 | 44 | self.showTime() 45 | 46 | self.setWindowTitle("QLCDNumber demo") 47 | self.resize(150, 60) 48 | 49 | def showTime(self): 50 | text = time.strftime('%H:%M:%S', time.localtime()) 51 | self.lcd_style.display(text) 52 | 53 | 54 | if __name__ == "__main__": 55 | app = QApplication(sys.argv) 56 | window = LCDNumberDemo() 57 | window.show() 58 | sys.exit(app.exec()) 59 | -------------------------------------------------------------------------------- /Chapter04/qt_QShortcut.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | ''' 4 | 【简介】 5 | PySide6中 QShortcut和QKeySequence案例。 6 | 7 | 8 | ''' 9 | 10 | import sys 11 | from PySide6.QtCore import * 12 | from PySide6.QtGui import * 13 | from PySide6.QtWidgets import * 14 | 15 | 16 | class QShortcutDemo(QMainWindow): 17 | def __init__(self, parent=None): 18 | super(QShortcutDemo, self).__init__(parent) 19 | widget = QWidget(self) 20 | self.setCentralWidget(widget) 21 | layout = QVBoxLayout() 22 | widget.setLayout(layout) 23 | _label = QLabel('既可以触发菜单快捷键,也可以通过Ctrl+E触发自定义快捷键') 24 | self.label = QLabel('显示信息') 25 | layout.addWidget(_label) 26 | layout.addWidget(self.label) 27 | 28 | bar = self.menuBar() 29 | file = bar.addMenu("File") 30 | file.addAction("New") 31 | 32 | # 快捷键1 33 | save = QAction("Save", self) 34 | save.setShortcut("Ctrl+S") 35 | file.addAction(save) 36 | 37 | # 快捷键2 38 | copy = QAction('Copy',self) 39 | copy.setShortcuts(QKeySequence.Copy) 40 | file.addAction(copy) 41 | 42 | # 快捷键3 43 | paste = QAction('Paste',self) 44 | # paste.setShortcuts(Qt.CTRL|Qt.Key_P) 45 | paste.setShortcut(QKeySequence(Qt.CTRL|Qt.Key_P)) 46 | # paste.setShortcuts(QKeySequence(Qt.CTRL|Qt.Key_P)) 47 | file.addAction(paste) 48 | 49 | quit = QAction("Quit", self) 50 | file.addAction(quit) 51 | file.triggered[QAction].connect(self.action_trigger) 52 | 53 | # 自定义快捷键 54 | custom_shortcut = QShortcut(QKeySequence("Ctrl+E"), self) 55 | custom_shortcut.activated.connect(lambda :self.customShortcut(custom_shortcut)) 56 | 57 | self.setWindowTitle("QShortcut 例子") 58 | self.resize(450, 200) 59 | 60 | def customShortcut(self,key): 61 | self.label.setText('触发自定义快捷键:%s'%key.keys()) 62 | 63 | def action_trigger(self, q): 64 | self.label.setText('触发菜单:%s;快捷键:%s'%(q.text(),q.shortcuts())) 65 | 66 | 67 | if __name__ == '__main__': 68 | app = QApplication(sys.argv) 69 | demo = QShortcutDemo() 70 | demo.show() 71 | sys.exit(app.exec()) 72 | -------------------------------------------------------------------------------- /Chapter04/qt_QStatusBar.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | ''' 4 | 【简介】 5 | PySide6中 QStatusBar 例子 6 | 7 | 8 | ''' 9 | 10 | import sys 11 | from PySide6.QtCore import * 12 | from PySide6.QtGui import * 13 | from PySide6.QtWidgets import * 14 | import time 15 | import os 16 | os.chdir(os.path.dirname(__file__)) 17 | 18 | class StatusDemo(QMainWindow): 19 | def __init__(self, parent=None): 20 | super(StatusDemo, self).__init__(parent) 21 | self.resize(300,200) 22 | 23 | bar = self.menuBar() 24 | file = bar.addMenu("File") 25 | new = QAction(QIcon("./images/new.png"), "new", self) 26 | new.setStatusTip('select menu: new') 27 | open_ = QAction(QIcon("./images/open.png"), "open", self) 28 | open_.setStatusTip('select menu: open') 29 | save = QAction(QIcon("./images/save.png"), "save", self) 30 | save.setStatusTip('select menu: save') 31 | file.addActions([new,open_,save]) 32 | file.triggered[QAction].connect(self.processTrigger) 33 | self.init_statusBar() 34 | 35 | self.timer = QTimer(self) 36 | self.timer.timeout.connect(lambda:self.label.setText(time.strftime("%Y-%m-%d %a %H:%M:%S"))) 37 | self.timer.start(1000) 38 | 39 | def init_statusBar(self): 40 | self.status_bar = QStatusBar() 41 | self.status_bar2 = QStatusBar() 42 | self.status_bar2.setMinimumWidth(150) 43 | self.label = QLabel('显示永久信息:时间') 44 | self.button = QPushButton('清除时间') 45 | 46 | self.status_bar.addWidget(self.status_bar2) 47 | self.status_bar.addWidget(self.label) 48 | self.status_bar.addWidget(self.button) 49 | 50 | self.setWindowTitle("QStatusBar 例子") 51 | self.setStatusBar(self.status_bar) 52 | self.button.clicked.connect(lambda :self.status_bar.removeWidget(self.label)) 53 | 54 | 55 | 56 | def processTrigger(self, q): 57 | self.status_bar2.showMessage('点击了menu: '+q.text(), 5000) 58 | 59 | 60 | if __name__ == '__main__': 61 | app = QApplication(sys.argv) 62 | demo = StatusDemo() 63 | demo.show() 64 | sys.exit(app.exec()) 65 | -------------------------------------------------------------------------------- /Chapter05/db/database.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter05/db/database.db -------------------------------------------------------------------------------- /Chapter05/images/IOS.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter05/images/IOS.png -------------------------------------------------------------------------------- /Chapter05/images/android.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter05/images/android.png -------------------------------------------------------------------------------- /Chapter05/images/bao0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter05/images/bao0.png -------------------------------------------------------------------------------- /Chapter05/images/bao1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter05/images/bao1.png -------------------------------------------------------------------------------- /Chapter05/images/bao10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter05/images/bao10.png -------------------------------------------------------------------------------- /Chapter05/images/bao11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter05/images/bao11.png -------------------------------------------------------------------------------- /Chapter05/images/bao12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter05/images/bao12.png -------------------------------------------------------------------------------- /Chapter05/images/bao13.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter05/images/bao13.png -------------------------------------------------------------------------------- /Chapter05/images/bao14.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter05/images/bao14.png -------------------------------------------------------------------------------- /Chapter05/images/bao3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter05/images/bao3.png -------------------------------------------------------------------------------- /Chapter05/images/bao4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter05/images/bao4.png -------------------------------------------------------------------------------- /Chapter05/images/bao5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter05/images/bao5.png -------------------------------------------------------------------------------- /Chapter05/images/bao6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter05/images/bao6.png -------------------------------------------------------------------------------- /Chapter05/images/bao8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter05/images/bao8.png -------------------------------------------------------------------------------- /Chapter05/images/bao9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter05/images/bao9.png -------------------------------------------------------------------------------- /Chapter05/images/cartoon1.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter05/images/cartoon1.ico -------------------------------------------------------------------------------- /Chapter05/images/close.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter05/images/close.png -------------------------------------------------------------------------------- /Chapter05/images/copy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter05/images/copy.png -------------------------------------------------------------------------------- /Chapter05/images/cut.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter05/images/cut.png -------------------------------------------------------------------------------- /Chapter05/images/down.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter05/images/down.png -------------------------------------------------------------------------------- /Chapter05/images/down3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter05/images/down3.png -------------------------------------------------------------------------------- /Chapter05/images/dropdown.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter05/images/dropdown.png -------------------------------------------------------------------------------- /Chapter05/images/flower.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter05/images/flower.png -------------------------------------------------------------------------------- /Chapter05/images/go-home.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter05/images/go-home.png -------------------------------------------------------------------------------- /Chapter05/images/go-next.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter05/images/go-next.png -------------------------------------------------------------------------------- /Chapter05/images/go-previous.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter05/images/go-previous.png -------------------------------------------------------------------------------- /Chapter05/images/hammer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter05/images/hammer.png -------------------------------------------------------------------------------- /Chapter05/images/help.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter05/images/help.jpg -------------------------------------------------------------------------------- /Chapter05/images/left.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter05/images/left.png -------------------------------------------------------------------------------- /Chapter05/images/music.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter05/images/music.png -------------------------------------------------------------------------------- /Chapter05/images/new.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter05/images/new.png -------------------------------------------------------------------------------- /Chapter05/images/open.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter05/images/open.png -------------------------------------------------------------------------------- /Chapter05/images/paste.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter05/images/paste.png -------------------------------------------------------------------------------- /Chapter05/images/printer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter05/images/printer.png -------------------------------------------------------------------------------- /Chapter05/images/qt-creator.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter05/images/qt-creator.png -------------------------------------------------------------------------------- /Chapter05/images/qt-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter05/images/qt-logo.png -------------------------------------------------------------------------------- /Chapter05/images/qt-project.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter05/images/qt-project.png -------------------------------------------------------------------------------- /Chapter05/images/qt-quick.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter05/images/qt-quick.png -------------------------------------------------------------------------------- /Chapter05/images/right.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter05/images/right.png -------------------------------------------------------------------------------- /Chapter05/images/root.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter05/images/root.png -------------------------------------------------------------------------------- /Chapter05/images/save.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter05/images/save.png -------------------------------------------------------------------------------- /Chapter05/images/screen1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter05/images/screen1.jpg -------------------------------------------------------------------------------- /Chapter05/images/undo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter05/images/undo.png -------------------------------------------------------------------------------- /Chapter05/images/up.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter05/images/up.png -------------------------------------------------------------------------------- /Chapter05/images/view-refresh.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter05/images/view-refresh.png -------------------------------------------------------------------------------- /Chapter05/qt_QTreeView2.py: -------------------------------------------------------------------------------- 1 | from PySide6.QtWidgets import * 2 | from PySide6.QtGui import * 3 | from PySide6.QtCore import * 4 | import sys 5 | import random 6 | import os 7 | os.chdir(os.path.dirname(__file__)) 8 | 9 | class QTreeViewDemo(QMainWindow): 10 | 11 | def __init__(self, parent=None): 12 | super(QTreeViewDemo, self).__init__(parent) 13 | self.setWindowTitle("QTreeView2案例") 14 | self.resize(600, 800) 15 | self.text = QPlainTextEdit('用来显示QTreeView2相关信息:') 16 | self.treeView = QTreeView() 17 | self.model = QFileSystemModel() 18 | self.treeView.setModel(self.model) 19 | self.selectModel = QItemSelectionModel() 20 | self.model.setRootPath(QDir.currentPath()) 21 | self.treeView.setSelectionModel(self.selectModel) 22 | 23 | self.listView = QListView() 24 | self.tableView = QTableView() 25 | self.listView.setModel(self.model) 26 | self.tableView.setModel(self.model) 27 | 28 | layoutV = QVBoxLayout(self) 29 | layoutV.addWidget(self.listView) 30 | layoutV.addWidget(self.tableView) 31 | 32 | layout = QHBoxLayout(self) 33 | layout.addWidget(self.treeView) 34 | layout.addLayout(layoutV) 35 | 36 | widget = QWidget() 37 | self.setCentralWidget(widget) 38 | widget.setLayout(layout) 39 | 40 | # 信号与槽 41 | self.treeView.clicked.connect(self.onClicked) 42 | 43 | def onClicked(self, index): 44 | self.listView.setRootIndex(index) 45 | self.tableView.setRootIndex(index) 46 | 47 | 48 | if __name__ == "__main__": 49 | app = QApplication(sys.argv) 50 | demo = QTreeViewDemo() 51 | demo.show() 52 | sys.exit(app.exec()) 53 | -------------------------------------------------------------------------------- /Chapter06/images/IOS.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter06/images/IOS.png -------------------------------------------------------------------------------- /Chapter06/images/android.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter06/images/android.png -------------------------------------------------------------------------------- /Chapter06/images/bao0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter06/images/bao0.png -------------------------------------------------------------------------------- /Chapter06/images/bao1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter06/images/bao1.png -------------------------------------------------------------------------------- /Chapter06/images/bao10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter06/images/bao10.png -------------------------------------------------------------------------------- /Chapter06/images/bao11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter06/images/bao11.png -------------------------------------------------------------------------------- /Chapter06/images/bao12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter06/images/bao12.png -------------------------------------------------------------------------------- /Chapter06/images/bao13.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter06/images/bao13.png -------------------------------------------------------------------------------- /Chapter06/images/bao14.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter06/images/bao14.png -------------------------------------------------------------------------------- /Chapter06/images/bao2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter06/images/bao2.png -------------------------------------------------------------------------------- /Chapter06/images/bao3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter06/images/bao3.png -------------------------------------------------------------------------------- /Chapter06/images/bao4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter06/images/bao4.png -------------------------------------------------------------------------------- /Chapter06/images/bao5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter06/images/bao5.png -------------------------------------------------------------------------------- /Chapter06/images/bao6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter06/images/bao6.png -------------------------------------------------------------------------------- /Chapter06/images/bao7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter06/images/bao7.png -------------------------------------------------------------------------------- /Chapter06/images/bao8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter06/images/bao8.png -------------------------------------------------------------------------------- /Chapter06/images/bao9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter06/images/bao9.png -------------------------------------------------------------------------------- /Chapter06/images/cartoon1.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter06/images/cartoon1.ico -------------------------------------------------------------------------------- /Chapter06/images/close.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter06/images/close.png -------------------------------------------------------------------------------- /Chapter06/images/copy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter06/images/copy.png -------------------------------------------------------------------------------- /Chapter06/images/cut.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter06/images/cut.png -------------------------------------------------------------------------------- /Chapter06/images/down3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter06/images/down3.png -------------------------------------------------------------------------------- /Chapter06/images/dropdown.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter06/images/dropdown.png -------------------------------------------------------------------------------- /Chapter06/images/flower.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter06/images/flower.png -------------------------------------------------------------------------------- /Chapter06/images/go-home.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter06/images/go-home.png -------------------------------------------------------------------------------- /Chapter06/images/go-next.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter06/images/go-next.png -------------------------------------------------------------------------------- /Chapter06/images/go-previous.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter06/images/go-previous.png -------------------------------------------------------------------------------- /Chapter06/images/hammer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter06/images/hammer.png -------------------------------------------------------------------------------- /Chapter06/images/help.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter06/images/help.jpg -------------------------------------------------------------------------------- /Chapter06/images/left.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter06/images/left.png -------------------------------------------------------------------------------- /Chapter06/images/left2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter06/images/left2.png -------------------------------------------------------------------------------- /Chapter06/images/left3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter06/images/left3.png -------------------------------------------------------------------------------- /Chapter06/images/leftHover.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter06/images/leftHover.png -------------------------------------------------------------------------------- /Chapter06/images/leftPressed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter06/images/leftPressed.png -------------------------------------------------------------------------------- /Chapter06/images/leftdown.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter06/images/leftdown.png -------------------------------------------------------------------------------- /Chapter06/images/leftdown2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter06/images/leftdown2.png -------------------------------------------------------------------------------- /Chapter06/images/leftdown3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter06/images/leftdown3.png -------------------------------------------------------------------------------- /Chapter06/images/leftup.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter06/images/leftup.png -------------------------------------------------------------------------------- /Chapter06/images/leftup2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter06/images/leftup2.png -------------------------------------------------------------------------------- /Chapter06/images/leftup3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter06/images/leftup3.png -------------------------------------------------------------------------------- /Chapter06/images/music.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter06/images/music.png -------------------------------------------------------------------------------- /Chapter06/images/new.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter06/images/new.png -------------------------------------------------------------------------------- /Chapter06/images/open.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter06/images/open.png -------------------------------------------------------------------------------- /Chapter06/images/paste.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter06/images/paste.png -------------------------------------------------------------------------------- /Chapter06/images/printer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter06/images/printer.png -------------------------------------------------------------------------------- /Chapter06/images/right.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter06/images/right.png -------------------------------------------------------------------------------- /Chapter06/images/right2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter06/images/right2.png -------------------------------------------------------------------------------- /Chapter06/images/right3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter06/images/right3.png -------------------------------------------------------------------------------- /Chapter06/images/rightdown.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter06/images/rightdown.png -------------------------------------------------------------------------------- /Chapter06/images/rightdown2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter06/images/rightdown2.png -------------------------------------------------------------------------------- /Chapter06/images/rightdown3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter06/images/rightdown3.png -------------------------------------------------------------------------------- /Chapter06/images/rightup.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter06/images/rightup.png -------------------------------------------------------------------------------- /Chapter06/images/rightup2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter06/images/rightup2.png -------------------------------------------------------------------------------- /Chapter06/images/rightup3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter06/images/rightup3.png -------------------------------------------------------------------------------- /Chapter06/images/root.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter06/images/root.png -------------------------------------------------------------------------------- /Chapter06/images/save.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter06/images/save.png -------------------------------------------------------------------------------- /Chapter06/images/screen1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter06/images/screen1.jpg -------------------------------------------------------------------------------- /Chapter06/images/undo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter06/images/undo.png -------------------------------------------------------------------------------- /Chapter06/images/up.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter06/images/up.png -------------------------------------------------------------------------------- /Chapter06/images/up2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter06/images/up2.png -------------------------------------------------------------------------------- /Chapter06/images/up3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter06/images/up3.png -------------------------------------------------------------------------------- /Chapter06/images/view-refresh.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter06/images/view-refresh.png -------------------------------------------------------------------------------- /Chapter06/qmlDemo/basic/basic.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2012-2021, Juergen Bocklage Ryannel and Johan Thelin 2 | # All rights reserved. 3 | # 4 | # Redistribution and use in source and binary forms, with or without 5 | # modification, are permitted provided that the following conditions are met: 6 | # 7 | # 1. Redistributions of source code must retain the above copyright notice, this 8 | # list of conditions and the following disclaimer. 9 | # 10 | # 2. Redistributions in binary form must reproduce the above copyright notice, 11 | # this list of conditions and the following disclaimer in the documentation 12 | # and/or other materials provided with the distribution. 13 | # 14 | # 3. Neither the name of the copyright holder nor the names of its contributors 15 | # may be used to endorse or promote products derived from this software 16 | # without specific prior written permission. 17 | # 18 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 22 | # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | #region global 30 | import sys 31 | from PySide6.QtGui import QGuiApplication 32 | from PySide6.QtQml import QQmlApplicationEngine 33 | from PySide6.QtCore import QUrl 34 | 35 | if __name__ == '__main__': 36 | app = QGuiApplication(sys.argv) 37 | engine = QQmlApplicationEngine() 38 | import os 39 | path = os.path.dirname(__file__) + os.sep + 'main.qml' 40 | engine.load(path) 41 | # engine.load(QUrl("main.qml")) 42 | 43 | if not engine.rootObjects(): 44 | sys.exit(-1) 45 | 46 | sys.exit(app.exec()) 47 | #endregion global 48 | -------------------------------------------------------------------------------- /Chapter06/qmlDemo/basic/main.qml: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012-2021, Juergen Bocklage Ryannel and Johan Thelin 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, this 9 | list of conditions and the following disclaimer. 10 | 11 | 2. Redistributions in binary form must reproduce the above copyright notice, 12 | this list of conditions and the following disclaimer in the documentation 13 | and/or other materials provided with the distribution. 14 | 15 | 3. Neither the name of the copyright holder nor the names of its contributors 16 | may be used to endorse or promote products derived from this software 17 | without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 23 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 25 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 26 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 27 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | import QtQuick 32 | import QtQuick.Window 33 | import QtQuick.Controls 34 | 35 | Window { 36 | width: 640 37 | height: 480 38 | visible: true 39 | title: qsTr("Hello Python World!") 40 | Column { 41 | Button { 42 | text: qsTr("我是QButton") 43 | onClicked: console.log('you clicked a button: ' + text) 44 | } 45 | Label { 46 | id: numberLabel 47 | text: qsTr("我是QLable") 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Chapter06/qmlDemo/class-context-property/main.qml: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012-2021, Juergen Bocklage Ryannel and Johan Thelin 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, this 9 | list of conditions and the following disclaimer. 10 | 11 | 2. Redistributions in binary form must reproduce the above copyright notice, 12 | this list of conditions and the following disclaimer in the documentation 13 | and/or other materials provided with the distribution. 14 | 15 | 3. Neither the name of the copyright holder nor the names of its contributors 16 | may be used to endorse or promote products derived from this software 17 | without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 23 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 25 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 26 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 27 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | // #region global 32 | import QtQuick 33 | import QtQuick.Window 34 | import QtQuick.Controls 35 | 36 | Window { 37 | id: root 38 | 39 | width: 640 40 | height: 480 41 | visible: true 42 | title: qsTr("Hello Python World!") 43 | 44 | Flow { 45 | Button { 46 | text: qsTr("Give me a number!") 47 | onClicked: numberGenerator.giveNumber() 48 | } 49 | Label { 50 | id: numberLabel 51 | text: qsTr("no number") 52 | } 53 | } 54 | 55 | Connections { 56 | target: numberGenerator 57 | function onNextNumber(number) { 58 | numberLabel.text = number 59 | } 60 | } 61 | } 62 | // #endregion global 63 | -------------------------------------------------------------------------------- /Chapter06/qmlDemo/class-registered-type/main.qml: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012-2021, Juergen Bocklage Ryannel and Johan Thelin 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, this 9 | list of conditions and the following disclaimer. 10 | 11 | 2. Redistributions in binary form must reproduce the above copyright notice, 12 | this list of conditions and the following disclaimer in the documentation 13 | and/or other materials provided with the distribution. 14 | 15 | 3. Neither the name of the copyright holder nor the names of its contributors 16 | may be used to endorse or promote products derived from this software 17 | without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 23 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 25 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 26 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 27 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | // #region global 32 | import QtQuick 33 | import QtQuick.Window 34 | import QtQuick.Controls 35 | 36 | import Generators 37 | 38 | Window { 39 | id: root 40 | 41 | width: 640 42 | height: 480 43 | visible: true 44 | title: qsTr("Hello Python World!") 45 | 46 | Flow { 47 | Button { 48 | text: qsTr("Give me a number!") 49 | onClicked: numberGenerator.giveNumber() 50 | } 51 | Label { 52 | id: numberLabel 53 | text: qsTr("no number") 54 | } 55 | } 56 | 57 | NumberGenerator { 58 | id: numberGenerator 59 | } 60 | 61 | Connections { 62 | target: numberGenerator 63 | function onNextNumber(number) { 64 | numberLabel.text = number 65 | } 66 | } 67 | } 68 | // #endregion global 69 | -------------------------------------------------------------------------------- /Chapter06/qt_QFormLayout.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | 4 | import sys 5 | from PySide6.QtWidgets import * 6 | from PySide6.QtGui import Qt 7 | 8 | 9 | class FormLayoutDemo(QWidget): 10 | def __init__(self, parent=None): 11 | super(FormLayoutDemo, self).__init__(parent) 12 | self.setWindowTitle("QFormLayout布局管理例子") 13 | self.resize(400, 100) 14 | 15 | formLayout = QFormLayout() 16 | 17 | nameLineEdit = QLineEdit() 18 | emailLineEdit = QLineEdit() 19 | ageSpinBox = QSpinBox() 20 | formLayout.addRow("&Name:", nameLineEdit) 21 | formLayout.addRow("&Email:", emailLineEdit) 22 | formLayout.addRow("&Age:", ageSpinBox) 23 | 24 | # 模拟macStyle表单布局外观,但使用左对齐的标签 25 | formLayout.setRowWrapPolicy(QFormLayout.DontWrapRows) 26 | formLayout.setFieldGrowthPolicy(QFormLayout.FieldsStayAtSizeHint) 27 | formLayout.setFormAlignment(Qt.AlignHCenter | Qt.AlignTop) 28 | formLayout.setLabelAlignment(Qt.AlignLeft) 29 | 30 | formLayout.addItem(QSpacerItem(30,30)) 31 | formLayout.addRow(QPushButton('确认'),QPushButton('取消')) 32 | 33 | self.setLayout(formLayout) 34 | 35 | 36 | if __name__ == "__main__": 37 | app = QApplication(sys.argv) 38 | form = FormLayoutDemo() 39 | form.show() 40 | sys.exit(app.exec()) 41 | -------------------------------------------------------------------------------- /Chapter06/qt_QGridLayout.py: -------------------------------------------------------------------------------- 1 | import sys 2 | from PySide6.QtWidgets import QApplication, QWidget, QGridLayout, QPushButton, QLayoutItem, QSpacerItem, QSizePolicy, \ 3 | QLabel, QHBoxLayout, QLineEdit,QTextBrowser,QPlainTextEdit 4 | 5 | 6 | class GridLayoutDemo(QWidget): 7 | def __init__(self, parent=None): 8 | super(GridLayoutDemo, self).__init__(parent) 9 | grid = QGridLayout() 10 | self.setLayout(grid) 11 | 12 | # 添加行列标识 13 | for i in range(1, 8): 14 | rowEdit = QLineEdit('row%d' % (i)) 15 | rowEdit.setReadOnly(True) 16 | grid.addWidget(rowEdit, i, 0) 17 | colEdit = QLineEdit('col%d' % (i)) 18 | colEdit.setReadOnly(True) 19 | grid.addWidget(colEdit, 0, i) 20 | col_rol_Edit = QLineEdit('rol0_col0') 21 | col_rol_Edit.setReadOnly(True) 22 | grid.addWidget(col_rol_Edit, 0, 0, 1, 1) 23 | 24 | # 开始表演 25 | spacer = QSpacerItem(100, 70, QSizePolicy.Maximum) 26 | grid.addItem(spacer,0,0,1,1) 27 | grid.addWidget(QPushButton('row1_col2_1_1'), 1, 2, 1, 1) 28 | grid.addWidget(QPushButton('row1_col3_1_1'), 1, 3, 1, 1) 29 | grid.addWidget(QPlainTextEdit('row2_col4_2_2'), 2, 4, 2, 2) 30 | grid.addWidget(QPlainTextEdit('row3_col2_2_2'), 3, 2, 2, 2) 31 | grid.addWidget(QPushButton('row5_col5_1_1'), 5, 5, 1, 1) 32 | spacer2 = QSpacerItem(100, 100, QSizePolicy.Maximum) 33 | grid.addItem(spacer2, 6, 5, 1, 2) 34 | grid.addWidget(QPushButton('row7_col6_1_1'), 7, 6, 1, 1) 35 | 36 | 37 | hlayout = QHBoxLayout() 38 | hlayout.addWidget(QPushButton('button_h1')) 39 | hlayout.addWidget(QPushButton('button_h2')) 40 | grid.addLayout(hlayout, 7, 1, 1, 2) 41 | 42 | grid.setColumnStretch(5, 1) 43 | grid.setColumnStretch(2, 1) 44 | grid.setColumnMinimumWidth(0, 80) 45 | 46 | self.move(300, 150) 47 | self.setWindowTitle('QGridLayout例子') 48 | 49 | 50 | if __name__ == "__main__": 51 | app = QApplication(sys.argv) 52 | demo = GridLayoutDemo() 53 | demo.show() 54 | sys.exit(app.exec()) 55 | -------------------------------------------------------------------------------- /Chapter06/qt_QStackedLayout.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | 4 | import sys 5 | from PySide6.QtWidgets import * 6 | 7 | 8 | class StackedLayoutDemo(QWidget): 9 | def __init__(self, parent=None): 10 | super(StackedLayoutDemo, self).__init__(parent) 11 | self.setWindowTitle("QStackedLayout布局管理例子") 12 | self.resize(400, 100) 13 | layout = QVBoxLayout() 14 | self.setLayout(layout) 15 | 16 | # 添加页面导航 17 | pageComboBox = QComboBox() 18 | pageComboBox.addItem("Page 1") 19 | pageComboBox.addItem("Page 2") 20 | pageComboBox.addItem("Page 3") 21 | layout.addWidget(pageComboBox) 22 | 23 | # 添加QStackedLayout 24 | stackedLayout = QStackedLayout() 25 | layout.addLayout(stackedLayout) 26 | 27 | # 添加页面1-3 28 | pageWidget1 = QWidget() 29 | layout1 = QHBoxLayout() 30 | pageWidget1.setLayout(layout1) 31 | stackedLayout.addWidget(pageWidget1) 32 | pageWidget2 = QWidget() 33 | layout2 = QVBoxLayout() 34 | pageWidget2.setLayout(layout2) 35 | stackedLayout.addWidget(pageWidget2) 36 | pageWidget3 = QWidget() 37 | layout3 = QFormLayout() 38 | pageWidget3.setLayout(layout3) 39 | stackedLayout.addWidget(pageWidget3) 40 | 41 | # 设置页面1-3 42 | for i in range(5): 43 | layout1.addWidget(QPushButton('button%d' % i)) 44 | layout2.addWidget(QPushButton('button%d' % i)) 45 | layout3.addRow('row%d' % i, QPushButton('button%d' % i)) 46 | 47 | # 导航与页面链接 48 | pageComboBox.activated.connect(stackedLayout.setCurrentIndex) 49 | 50 | # 添加按钮切换导航页1-3 51 | buttonLayout = QHBoxLayout() 52 | layout.addLayout(buttonLayout) 53 | button1 = QPushButton('页面1') 54 | button2 = QPushButton('页面2') 55 | button3 = QPushButton('页面3') 56 | buttonLayout.addWidget(button1) 57 | buttonLayout.addWidget(button2) 58 | buttonLayout.addWidget(button3) 59 | button1.clicked.connect(lambda: stackedLayout.setCurrentIndex(0)) 60 | button2.clicked.connect(lambda: stackedLayout.setCurrentWidget(pageWidget2)) 61 | button3.clicked.connect(lambda: stackedLayout.setCurrentIndex(2)) 62 | 63 | label = QLabel('显示信息') 64 | layout.addWidget(label) 65 | stackedLayout.currentChanged.connect(lambda x: label.setText('切换到页面%d' % (x + 1))) 66 | 67 | 68 | if __name__ == "__main__": 69 | app = QApplication(sys.argv) 70 | form = StackedLayoutDemo() 71 | form.show() 72 | sys.exit(app.exec()) 73 | -------------------------------------------------------------------------------- /Chapter06/qt_QThread.py: -------------------------------------------------------------------------------- 1 | from PySide6.QtCore import Signal, QThread, Qt 2 | from PySide6.QtWidgets import QMainWindow, QWidget, QLabel, QApplication, QPushButton, QHBoxLayout 3 | from PySide6.QtGui import QFont 4 | import sys 5 | import time 6 | 7 | 8 | class WorkThread(QThread): 9 | count = int(0) 10 | countSignal = Signal(int) 11 | 12 | def __init__(self): 13 | super(WorkThread, self).__init__() 14 | 15 | def run(self): 16 | self.flag = True 17 | while self.flag: 18 | self.count += 1 19 | self.countSignal.emit(self.count) 20 | time.sleep(1) 21 | 22 | 23 | class MainWindow(QMainWindow): 24 | 25 | def __init__(self): 26 | super(MainWindow, self).__init__() 27 | self.setWindowTitle('QThread demo') 28 | self.resize(515, 208) 29 | self.widget = QWidget() 30 | self.buttonStart = QPushButton('开始') 31 | self.buttonStop = QPushButton('结束') 32 | self.label = QLabel('0') 33 | self.label.setFont(QFont("Adobe Arabic", 28)) 34 | self.label.setAlignment(Qt.AlignCenter) 35 | 36 | layout = QHBoxLayout() 37 | layout.addWidget(self.label) 38 | layout.addWidget(self.buttonStart) 39 | layout.addWidget(self.buttonStop) 40 | self.widget.setLayout(layout) 41 | self.setCentralWidget(self.widget) 42 | 43 | self.buttonStart.clicked.connect(self.onStart) 44 | self.buttonStop.clicked.connect(self.onStop) 45 | 46 | self.thread = WorkThread() 47 | self.thread.countSignal.connect(self.flush) 48 | 49 | self.thread.started.connect(lambda: self.statusBar().showMessage('多线程started信号')) 50 | self.thread.finished.connect(self.finished) 51 | 52 | def flush(self, count): 53 | self.label.setText(str(count)) 54 | 55 | def onStart(self): 56 | self.statusBar().showMessage('button start.') 57 | print('button start.') 58 | self.buttonStart.setEnabled(False) 59 | self.thread.start() 60 | 61 | def onStop(self): 62 | self.statusBar().showMessage('button stop.') 63 | self.thread.flag = False 64 | self.thread.quit() 65 | 66 | def finished(self): 67 | self.statusBar().showMessage('多线程finish信号') 68 | self.buttonStart.setEnabled(True) 69 | 70 | 71 | if __name__ == "__main__": 72 | app = QApplication(sys.argv) 73 | demo = MainWindow() 74 | demo.show() 75 | sys.exit(app.exec()) 76 | -------------------------------------------------------------------------------- /Chapter06/qt_QThread2.py: -------------------------------------------------------------------------------- 1 | from PySide6.QtCore import Signal, QObject, QThread, Qt 2 | from PySide6.QtWidgets import QMainWindow, QWidget, QLabel, QApplication, QPushButton, QHBoxLayout 3 | from PySide6.QtGui import QFont 4 | import sys 5 | import time 6 | 7 | 8 | class Work(QObject): 9 | count = int(0) 10 | countSignal = Signal(int) 11 | 12 | def __init__(self): 13 | super(Work, self).__init__() 14 | 15 | def work(self): 16 | self.flag = True 17 | while self.flag: 18 | self.count += 1 19 | self.countSignal.emit(self.count) 20 | time.sleep(1) 21 | 22 | 23 | class MainWindow(QMainWindow): 24 | 25 | def __init__(self): 26 | super(MainWindow, self).__init__() 27 | self.setWindowTitle('QThread demo') 28 | self.resize(515, 208) 29 | self.widget = QWidget() 30 | self.buttonStart = QPushButton('开始') 31 | self.buttonStop = QPushButton('结束') 32 | self.label = QLabel('0') 33 | self.label.setFont(QFont("Adobe Arabic", 28)) 34 | self.label.setAlignment(Qt.AlignCenter) 35 | 36 | layout = QHBoxLayout() 37 | layout.addWidget(self.label) 38 | layout.addWidget(self.buttonStart) 39 | layout.addWidget(self.buttonStop) 40 | self.widget.setLayout(layout) 41 | self.setCentralWidget(self.widget) 42 | 43 | self.buttonStart.clicked.connect(self.onStart) 44 | self.buttonStop.clicked.connect(self.onStop) 45 | 46 | self.thread = QThread() 47 | self.worker = Work() 48 | self.worker.countSignal.connect(self.flush) 49 | 50 | self.worker.moveToThread(self.thread) 51 | self.thread.started.connect(self.worker.work) 52 | self.thread.finished.connect(self.finished) 53 | 54 | def flush(self, count): 55 | self.label.setText(str(count)) 56 | 57 | def onStart(self): 58 | self.statusBar().showMessage('button start.') 59 | self.buttonStart.setEnabled(False) 60 | self.thread.start() 61 | 62 | def onStop(self): 63 | self.statusBar().showMessage('button stop.') 64 | self.worker.flag = False 65 | self.thread.quit() 66 | 67 | def finished(self): 68 | self.statusBar().showMessage('多线程finish.') 69 | self.buttonStart.setEnabled(True) 70 | 71 | 72 | if __name__ == "__main__": 73 | app = QApplication(sys.argv) 74 | demo = MainWindow() 75 | demo.show() 76 | sys.exit(app.exec()) 77 | -------------------------------------------------------------------------------- /Chapter06/qt_QTimer.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | ''' 3 | 【简介】 4 | PySide6中 QTimer例子 5 | 6 | 7 | ''' 8 | 9 | from PySide6.QtWidgets import QWidget, QPushButton, QApplication, QListWidget, QGridLayout, QLabel, QCheckBox, \ 10 | QMessageBox 11 | from PySide6.QtCore import QTimer, QDateTime, Qt 12 | import sys 13 | 14 | 15 | class WinForm(QWidget): 16 | 17 | def __init__(self, parent=None): 18 | super(WinForm, self).__init__(parent) 19 | self.setWindowTitle("QTimer demo") 20 | self.listFile = QListWidget() 21 | self.label = QLabel('显示当前时间') 22 | self.startBtn = QPushButton('开始') 23 | self.endBtn = QPushButton('结束') 24 | self.autoButon = QPushButton('延迟计时') 25 | layout = QGridLayout(self) 26 | 27 | # 初始化定时器 28 | self.timer = QTimer(self) 29 | self.timer2 = QTimer() 30 | self.timer2.setSingleShot(True) 31 | 32 | # showTime()方法 33 | self.timer.timeout.connect(self.showTime) 34 | 35 | self.checkBox = QCheckBox("单次计时") 36 | self.checkBox.stateChanged.connect(self.timer.setSingleShot) 37 | 38 | layout.addWidget(self.label, 0, 0, 1, 2) 39 | layout.addWidget(self.startBtn, 1, 0) 40 | layout.addWidget(self.endBtn, 1, 1) 41 | layout.addWidget(self.checkBox, 1, 2) 42 | layout.addWidget(self.autoButon, 2, 0, 1, 2) 43 | 44 | self.startBtn.clicked.connect(self.startTimer) 45 | self.endBtn.clicked.connect(self.endTimer) 46 | self.autoButon.clicked.connect(self.laterTimer) 47 | 48 | self.setLayout(layout) 49 | 50 | def showTime(self): 51 | # 获取系统现在的时间 52 | time = QDateTime.currentDateTime() 53 | # 设置系统时间显示格式 54 | timeDisplay = time.toString("yyyy-MM-dd hh:mm:ss dddd") 55 | # 在标签上显示时间 56 | self.label.setText(timeDisplay) 57 | 58 | def startTimer(self): 59 | # 设置计时间隔并启动 60 | self.timer.start(1000) 61 | self.startBtn.setEnabled(False) 62 | self.endBtn.setEnabled(True) 63 | 64 | def endTimer(self): 65 | self.timer.stop() 66 | self.startBtn.setEnabled(True) 67 | self.endBtn.setEnabled(False) 68 | 69 | def laterTimer(self): 70 | self.label.setText("延迟任务会在5秒后启动!") 71 | self.timer2.singleShot(5000, lambda: QMessageBox.information(self, '延迟任务标题', '执行延迟任务')) 72 | 73 | 74 | if __name__ == "__main__": 75 | app = QApplication(sys.argv) 76 | form = WinForm() 77 | form.show() 78 | sys.exit(app.exec()) 79 | -------------------------------------------------------------------------------- /Chapter06/qt_QssDemo.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | 【简介】 4 | 加载QSS文件 5 | 6 | """ 7 | import sys 8 | from PySide6.QtWidgets import * 9 | import os 10 | os.chdir(os.path.dirname(__file__)) 11 | 12 | 13 | class MainWindow(QMainWindow): 14 | def __init__(self, parent=None): 15 | super(MainWindow, self).__init__(parent) 16 | self.resize(477, 258) 17 | self.setWindowTitle("QssDemo") 18 | layout = QFormLayout() 19 | 20 | button1 = QPushButton('button1') 21 | button1.setToolTip('类型选择器,最一般的使用方式') 22 | layout.addRow('类型选择器',button1) 23 | 24 | buttonProperty = QPushButton('buttonProperty') 25 | buttonProperty.setProperty('name','btnProperty') 26 | buttonProperty.setToolTip('属性选择器,根据属性定位') 27 | layout.addRow('属性选择器',buttonProperty) 28 | 29 | buttonID = QPushButton('buttonID') 30 | # button1.setMaximumSize(64, 64) 31 | buttonID.setMinimumSize(64, 64) 32 | buttonID.setObjectName('btnID') 33 | buttonID.setToolTip('id选择器,点击会触发伪状态') 34 | layout.addRow('id选择器+伪状态',buttonID) 35 | 36 | comboBox = QComboBox() 37 | comboBox.addItems(['张三','李四','王五','赵六']) 38 | layout.addRow('子控件',comboBox) 39 | 40 | buttonOwn = QPushButton('控件自定义qss') 41 | buttonOwn.setStyleSheet('''* { 42 | border: 2px solid #8f8f91; 43 | border-radius: 6px; 44 | background-color: gray; 45 | color: yellow }''') 46 | buttonOwn.setToolTip('子控件的Qss会覆盖父控件的设置') 47 | layout.addRow('控件自定义qss',buttonOwn) 48 | 49 | # 后代选择器 50 | glayout = QHBoxLayout() 51 | group = QGroupBox() 52 | group.setTitle('groupBox') 53 | group.setLayout(glayout) 54 | glayout.addWidget(QPushButton('button')) 55 | glayout.addWidget(QCheckBox('check')) 56 | checkBox2 = QCheckBox('check2') 57 | checkBox2.setObjectName('btnID') 58 | checkBox2.setMinimumSize(40,40) 59 | glayout.addWidget(checkBox2) 60 | layout.addRow('后代选择器',group) 61 | 62 | widget = QWidget() 63 | self.setCentralWidget(widget) 64 | widget.setLayout(layout) 65 | 66 | 67 | if __name__ == "__main__": 68 | app = QApplication(sys.argv) 69 | win = MainWindow() 70 | 71 | styleFile = './style.qss' 72 | with open(styleFile, 'r') as f: 73 | qssStyle = f.read() 74 | win.setStyleSheet(qssStyle) 75 | win.show() 76 | 77 | sys.exit(app.exec()) 78 | -------------------------------------------------------------------------------- /Chapter06/qt_processEvents.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | ''' 3 | 【简介】 4 | PySide6中实时刷新界面例子 5 | 6 | 7 | ''' 8 | 9 | from PySide6.QtWidgets import QWidget, QPushButton , QApplication ,QListWidget, QGridLayout 10 | import sys 11 | import time 12 | 13 | class WinForm(QWidget): 14 | 15 | def __init__(self,parent=None): 16 | super(WinForm,self).__init__(parent) 17 | self.setWindowTitle("实时刷新界面例子") 18 | self.listFile= QListWidget() 19 | self.btnStart = QPushButton('开始') 20 | layout = QGridLayout(self) 21 | layout.addWidget(self.listFile,0,0,1,2) 22 | layout.addWidget(self.btnStart,1,1) 23 | self.btnStart.clicked.connect( self.slotAdd) 24 | self.setLayout(layout) 25 | 26 | def slotAdd(self): 27 | for n in range(10): 28 | str_n='File index {0}'.format(n) 29 | self.listFile.addItem(str_n) 30 | QApplication.processEvents() 31 | time.sleep(1) 32 | 33 | if __name__ == "__main__": 34 | app = QApplication(sys.argv) 35 | form = WinForm() 36 | form.show() 37 | sys.exit(app.exec()) 38 | -------------------------------------------------------------------------------- /Chapter06/tabbedbrowser/doc/tabbedbrowser.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter06/tabbedbrowser/doc/tabbedbrowser.png -------------------------------------------------------------------------------- /Chapter06/tabbedbrowser/doc/tabbedbrowser.rst: -------------------------------------------------------------------------------- 1 | ********************** 2 | Web Browser Example 3 | ********************** 4 | 5 | The example demonstrates the power and simplicity offered by |project| to developers. 6 | It uses several |pymodname| submodules to offer a fluid and modern-looking UI that 7 | is apt for a web browser. The application offers the following features: 8 | 9 | * Tab-based browsing experience using QTabWidget. 10 | * Download manager using a QProgressBar and QWebEngineDownloadItem. 11 | * Bookmark manager using QTreeView. 12 | 13 | .. image:: tabbedbrowser.png 14 | 15 | The application's code is organized in several parts for ease of maintenance. For example, 16 | :code:`DownloadWidget` provides a widget to track progress of a download item. In the following 17 | sections, these different parts are discussed briefly to help you understand the Python code behind 18 | them a little better. 19 | 20 | BookmarkWidget or :code:`bookmarkwidget.py` 21 | =========================================== 22 | 23 | This widget docks to the left of the main window by default. It inherits QTreeView and 24 | loads a default set of bookmarks using a QStandardItemModel. The model is populated at startup 25 | from a JSON file, which is updated when you add or remove bookmarks from the tree view. 26 | 27 | .. automodule:: bookmarkwidget 28 | :members: 29 | 30 | DownloadWidget or :code:`downloadwidget.py` 31 | ============================================= 32 | 33 | The widget tracks progress of the download item. It inherits QProgressBar to display 34 | progress of the QWebEngineDownloadItem instance, and offers a context-menu with actions such as Launch, 35 | Show in folder, Cancel, and Remove. 36 | 37 | .. automodule:: downloadwidget 38 | :members: 39 | 40 | BrowserTabWidget or :code:`browsertabwidget.py` 41 | =============================================== 42 | 43 | The widget includes a QWebEngineView to enable viewing web content. It docks to the right 44 | of BookmarkWidget in the main window. 45 | 46 | .. automodule:: browsertabwidget 47 | :members: 48 | 49 | MainWindow or :code:`main.py` 50 | ============================= 51 | 52 | This is the parent window that collates all the other widgets together to offer the complete package. 53 | 54 | .. automodule:: main 55 | :members: 56 | 57 | 58 | Try running the example to explore it further. 59 | -------------------------------------------------------------------------------- /Chapter06/tabbedbrowser/tabbedbrowser.pyproject: -------------------------------------------------------------------------------- 1 | { 2 | "files": ["main.py", "bookmarkwidget.py", "browsertabwidget.py", 3 | "downloadwidget.py", "findtoolbar.py", "historywindow.py", 4 | "webengineview.py"] 5 | } 6 | -------------------------------------------------------------------------------- /Chapter07/MainWinSignalSlogRun.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | import sys 4 | from PySide6.QtWidgets import QApplication, QMainWindow 5 | from MainWinSignalSlog import Ui_Form 6 | from PySide6.QtCore import Signal, Qt 7 | 8 | 9 | class MyMainWindow(QMainWindow, Ui_Form): 10 | helpSignal = Signal(str) 11 | printSignal = Signal(list) 12 | # 声明一个多重载版本的信号,包括了一个带int和str类型参数的信号,以及带str参数的信号 13 | previewSignal = Signal([int, str], [str]) 14 | 15 | def __init__(self, parent=None): 16 | super(MyMainWindow, self).__init__(parent) 17 | self.setupUi(self) 18 | self.initUI() 19 | 20 | def initUI(self): 21 | self.helpSignal.connect(self.showHelpMessage) 22 | self.printSignal.connect(self.printPaper) 23 | self.previewSignal[str].connect(self.previewPaper) 24 | self.previewSignal[int, str].connect(self.previewPaperWithArgs) 25 | 26 | self.printButton.clicked.connect(self.emitPrintSignal) 27 | # self.previewButton.clicked.connect(self.emitPreviewSignal) 28 | 29 | # 发射预览信号 30 | def emitPreviewSignal(self): 31 | if self.previewStatus.isChecked() == True: 32 | self.previewSignal[int, str].emit(1080, " Full Screen") 33 | elif self.previewStatus.isChecked() == False: 34 | self.previewSignal[str].emit("Preview") 35 | 36 | # 发射打印信号 37 | def emitPrintSignal(self): 38 | pList = [] 39 | pList.append(self.numberSpinBox.value()) 40 | pList.append(self.styleCombo.currentText()) 41 | self.printSignal.emit(pList) 42 | 43 | def printPaper(self, list): 44 | self.resultLabel.setText("打印: " + "份数:" + str(list[0]) + " 纸张:" + str(list[1])) 45 | 46 | def previewPaperWithArgs(self, style, text): 47 | self.resultLabel.setText(str(style) + text) 48 | 49 | def previewPaper(self, text): 50 | self.resultLabel.setText(text) 51 | 52 | # 重载点击键盘事件 53 | def keyPressEvent(self, event): 54 | if event.key() == Qt.Key_F1: 55 | self.helpSignal.emit("help message") 56 | 57 | # 显示帮助消息 58 | def showHelpMessage(self, message): 59 | self.resultLabel.setText(message) 60 | self.statusBar().showMessage(message) 61 | 62 | 63 | if __name__ == "__main__": 64 | app = QApplication(sys.argv) 65 | win = MyMainWindow() 66 | win.show() 67 | sys.exit(app.exec()) 68 | -------------------------------------------------------------------------------- /Chapter07/images/cartoon1.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter07/images/cartoon1.ico -------------------------------------------------------------------------------- /Chapter07/images/cartoon2.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter07/images/cartoon2.ico -------------------------------------------------------------------------------- /Chapter07/images/cartoon3.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter07/images/cartoon3.ico -------------------------------------------------------------------------------- /Chapter07/images/cartoon4.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter07/images/cartoon4.ico -------------------------------------------------------------------------------- /Chapter07/images/python.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter07/images/python.jpg -------------------------------------------------------------------------------- /Chapter08/install/colorDialog.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | from PySide6.QtWidgets import QApplication, QPushButton, QColorDialog , QWidget 4 | from PySide6.QtCore import Qt 5 | from PySide6.QtGui import QColor 6 | import sys 7 | 8 | class ColorDialog ( QWidget): 9 | def __init__(self ): 10 | super().__init__() 11 | color = QColor(0, 0, 0) 12 | self.setGeometry(300, 300, 350, 280) 13 | self.setWindowTitle('颜色选择') 14 | self.button = QPushButton('点击选择颜色', self) 15 | self.button.setFocusPolicy(Qt.NoFocus) 16 | self.button.move(20, 20) 17 | self.button.clicked.connect(self.showDialog) 18 | self.setFocus() 19 | self.widget = QWidget(self) 20 | self.widget.setStyleSheet('QWidget{background-color:%s} '%color.name()) 21 | self.widget.setGeometry(130, 22, 100, 100) 22 | 23 | def showDialog(self): 24 | col = QColorDialog.getColor() 25 | if col.isValid(): 26 | self.widget.setStyleSheet('QWidget {background-color:%s}'%col.name()) 27 | 28 | if __name__ == "__main__": 29 | app = QApplication(sys.argv) 30 | qb = ColorDialog() 31 | qb.show() 32 | sys.exit(app.exec()) 33 | -------------------------------------------------------------------------------- /Chapter08/matplotlibDemo/matplotlib_pyqt.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Module implementing MainWindow. 5 | """ 6 | 7 | from PySide6.QtCore import Slot 8 | from PySide6.QtWidgets import QMainWindow, QApplication 9 | 10 | from Ui_matplotlib_pyqt import Ui_MainWindow 11 | 12 | 13 | class MainWindow(QMainWindow, Ui_MainWindow): 14 | """ 15 | Class documentation goes here. 16 | """ 17 | 18 | def __init__(self, parent=None): 19 | """ 20 | Constructor 21 | 22 | @param parent reference to the parent widget 23 | @type QWidget 24 | """ 25 | super(MainWindow, self).__init__(parent) 26 | self.setupUi(self) 27 | self.matplotlibwidget_dynamic.setVisible(False) 28 | self.matplotlibwidget_static.setVisible(False) 29 | 30 | @Slot() 31 | def on_pushButton_clicked(self): 32 | """ 33 | Slot documentation goes here. 34 | """ 35 | self.matplotlibwidget_static.setVisible(True) 36 | self.matplotlibwidget_static.mpl.start_static_plot() 37 | 38 | 39 | @Slot() 40 | def on_pushButton_2_clicked(self): 41 | """ 42 | Slot documentation goes here. 43 | """ 44 | self.matplotlibwidget_dynamic.setVisible(True) 45 | self.matplotlibwidget_dynamic.mpl.start_dynamic_plot() 46 | 47 | 48 | 49 | if __name__ == "__main__": 50 | import sys 51 | 52 | app = QApplication(sys.argv) 53 | ui = MainWindow() 54 | ui.show() 55 | sys.exit(app.exec()) 56 | -------------------------------------------------------------------------------- /Chapter08/matplotlibDemo/matplotlib_pyqt.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | MainWindow 4 | 5 | 6 | 7 | 0 8 | 0 9 | 800 10 | 600 11 | 12 | 13 | 14 | MainWindow 15 | 16 | 17 | 18 | 19 | 20 | 10 21 | 0 22 | 611 23 | 271 24 | 25 | 26 | 27 | 28 | 29 | 30 | 670 31 | 80 32 | 75 33 | 23 34 | 35 | 36 | 37 | 显示静态图 38 | 39 | 40 | 41 | 42 | true 43 | 44 | 45 | 46 | 10 47 | 270 48 | 611 49 | 291 50 | 51 | 52 | 53 | 54 | 55 | 56 | 670 57 | 370 58 | 75 59 | 23 60 | 61 | 62 | 63 | 显示动态图 64 | 65 | 66 | 67 | 68 | 69 | 70 | 0 71 | 0 72 | 800 73 | 23 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | MatplotlibWidget 82 | QWidget 83 |
MatplotlibWidget
84 | 1 85 |
86 |
87 | 88 | 89 |
90 | -------------------------------------------------------------------------------- /Chapter08/pandasDemo/BasicExample.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | import pandas 4 | import numpy 5 | from qtpy.QtCore import Qt 6 | 7 | from PySide6 import QtWidgets 8 | from qtpandas.models.DataFrameModel import DataFrameModel 9 | from qtpandas.views.DataTableView import DataTableWidget 10 | 11 | 12 | # sys.excepthook = excepthook # 设置PyQt的异常钩子,在本例中基本没什么用 13 | 14 | # 创建一个空的模型,该模型用于存储与处理数据 15 | model = DataFrameModel() 16 | 17 | # 创建一个应用用于显示表格 18 | app = QtWidgets.QApplication([]) 19 | widget = DataTableWidget() # 创建一个空的表格,主要用来呈现数据 20 | widget.resize(500, 300) # 调整Widget的大小 21 | widget.show() 22 | # 让表格绑定模型,也就是让表格呈现模型的内容 23 | widget.setViewModel(model) 24 | 25 | # 创建测试数据 26 | data = { 27 | 'A': [10, 11, 12], 28 | 'B': [20, 21, 22], 29 | 'C': ['Peter Pan', 'Cpt. Hook', 'Tinkerbell'] 30 | } 31 | df = pandas.DataFrame(data) 32 | 33 | # 下面两列用来测试委托是否成立 34 | df['A'] = df['A'].astype(numpy.int8) # A列数据格式变成整型 35 | df['B'] = df['B'].astype(numpy.float16) # B列数据格式变成浮点型 36 | 37 | # 在模型中填入数据df 38 | model.setDataFrame(df) 39 | 40 | # 启动程序 41 | app.exec() 42 | -------------------------------------------------------------------------------- /Chapter08/pandasDemo/Ui_pandas_pyqt.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | ################################################################################ 4 | ## Form generated from reading UI file 'pandas_pyqt.ui' 5 | ## 6 | ## Created by: Qt User Interface Compiler version 6.2.3 7 | ## 8 | ## WARNING! All changes made in this file will be lost when recompiling UI file! 9 | ################################################################################ 10 | 11 | from PySide6.QtCore import (QCoreApplication, QDate, QDateTime, QLocale, 12 | QMetaObject, QObject, QPoint, QRect, 13 | QSize, QTime, QUrl, Qt) 14 | from PySide6.QtGui import (QBrush, QColor, QConicalGradient, QCursor, 15 | QFont, QFontDatabase, QGradient, QIcon, 16 | QImage, QKeySequence, QLinearGradient, QPainter, 17 | QPalette, QPixmap, QRadialGradient, QTransform) 18 | from PySide6.QtWidgets import (QApplication, QMainWindow, QPushButton, QSizePolicy, 19 | QWidget) 20 | 21 | from qtpandas.views.DataTableView import DataTableWidget 22 | 23 | class Ui_MainWindow(object): 24 | def setupUi(self, MainWindow): 25 | if not MainWindow.objectName(): 26 | MainWindow.setObjectName(u"MainWindow") 27 | MainWindow.resize(800, 600) 28 | self.centralWidget = QWidget(MainWindow) 29 | self.centralWidget.setObjectName(u"centralWidget") 30 | self.pushButton = QPushButton(self.centralWidget) 31 | self.pushButton.setObjectName(u"pushButton") 32 | self.pushButton.setGeometry(QRect(680, 60, 75, 23)) 33 | self.pushButton_2 = QPushButton(self.centralWidget) 34 | self.pushButton_2.setObjectName(u"pushButton_2") 35 | self.pushButton_2.setGeometry(QRect(680, 170, 75, 23)) 36 | self.pandastablewidget = DataTableWidget(self.centralWidget) 37 | self.pandastablewidget.setObjectName(u"pandastablewidget") 38 | self.pandastablewidget.setGeometry(QRect(10, 30, 591, 331)) 39 | self.pandastablewidget.setStyleSheet(u"") 40 | MainWindow.setCentralWidget(self.centralWidget) 41 | 42 | self.retranslateUi(MainWindow) 43 | 44 | QMetaObject.connectSlotsByName(MainWindow) 45 | # setupUi 46 | 47 | def retranslateUi(self, MainWindow): 48 | MainWindow.setWindowTitle(QCoreApplication.translate("MainWindow", u"MainWindow", None)) 49 | self.pushButton.setText(QCoreApplication.translate("MainWindow", u"\u6570\u636e\u521d\u59cb\u5316", None)) 50 | self.pushButton_2.setText(QCoreApplication.translate("MainWindow", u"\u4fdd\u5b58\u6570\u636e", None)) 51 | # retranslateUi 52 | 53 | -------------------------------------------------------------------------------- /Chapter08/pandasDemo/data/fund_data.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter08/pandasDemo/data/fund_data.xlsx -------------------------------------------------------------------------------- /Chapter08/pandasDemo/data/fund_data_new.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter08/pandasDemo/data/fund_data_new.xlsx -------------------------------------------------------------------------------- /Chapter08/pandasDemo/pandas_pyqt.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Module implementing MainWindow. 5 | """ 6 | 7 | from PySide6.QtCore import Slot 8 | from PySide6.QtWidgets import QMainWindow, QApplication 9 | 10 | from Ui_pandas_pyqt import Ui_MainWindow 11 | 12 | from qtpandas.models.DataFrameModel import DataFrameModel 13 | import pandas as pd 14 | 15 | class MainWindow(QMainWindow, Ui_MainWindow): 16 | """ 17 | Class documentation goes here. 18 | """ 19 | def __init__(self, parent=None): 20 | """ 21 | Constructor 22 | 23 | @param parent reference to the parent widget 24 | @type QWidget 25 | """ 26 | super(MainWindow, self).__init__(parent) 27 | self.setupUi(self) 28 | 29 | '''初始化pandasqt''' 30 | widget = self.pandastablewidget 31 | widget.resize(600, 500) # 如果对部件尺寸大小不满意可以在这里设置 32 | 33 | 34 | self.model = DataFrameModel() # 设置新的模型 35 | widget.setViewModel(self.model) 36 | 37 | self.df = pd.read_excel(r'./data/fund_data.xlsx') 38 | self.df_original = self.df.copy() # 备份原始数据 39 | self.model.setDataFrame(self.df) 40 | 41 | 42 | 43 | @Slot() 44 | def on_pushButton_clicked(self): 45 | """ 46 | 初始化pandas 47 | """ 48 | self.model.setDataFrame(self.df_original) 49 | 50 | @Slot() 51 | def on_pushButton_2_clicked(self): 52 | """ 53 | 保存数据 54 | """ 55 | self.df.to_excel(r'./data/fund_data_new.xlsx') 56 | 57 | 58 | if __name__ == "__main__": 59 | import sys 60 | 61 | app = QApplication(sys.argv) 62 | ui = MainWindow() 63 | ui.show() 64 | sys.exit(app.exec()) 65 | -------------------------------------------------------------------------------- /Chapter08/pandasDemo/pandas_pyqt.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | MainWindow 4 | 5 | 6 | 7 | 0 8 | 0 9 | 800 10 | 600 11 | 12 | 13 | 14 | MainWindow 15 | 16 | 17 | 18 | 19 | 20 | 680 21 | 60 22 | 75 23 | 23 24 | 25 | 26 | 27 | 数据初始化 28 | 29 | 30 | 31 | 32 | 33 | 680 34 | 170 35 | 75 36 | 23 37 | 38 | 39 | 40 | 保存数据 41 | 42 | 43 | 44 | 45 | 46 | 10 47 | 30 48 | 591 49 | 331 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | DataTableWidget 61 | QWidget 62 |
qtpandas.views.DataTableView
63 | 1 64 |
65 |
66 | 67 | 68 |
69 | -------------------------------------------------------------------------------- /Chapter08/pandasDemo/qtpandas.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter08/pandasDemo/qtpandas.zip -------------------------------------------------------------------------------- /Chapter08/pandasDemo/qtpandas/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter08/pandasDemo/qtpandas/__init__.py -------------------------------------------------------------------------------- /Chapter08/pandasDemo/qtpandas/_lib/magic/db/magic.mgc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter08/pandasDemo/qtpandas/_lib/magic/db/magic.mgc -------------------------------------------------------------------------------- /Chapter08/pandasDemo/qtpandas/_lib/magic/libgcc_s_dw2-1.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter08/pandasDemo/qtpandas/_lib/magic/libgcc_s_dw2-1.dll -------------------------------------------------------------------------------- /Chapter08/pandasDemo/qtpandas/_lib/magic/libmagic-1.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter08/pandasDemo/qtpandas/_lib/magic/libmagic-1.dll -------------------------------------------------------------------------------- /Chapter08/pandasDemo/qtpandas/_lib/magic/libregex-1.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter08/pandasDemo/qtpandas/_lib/magic/libregex-1.dll -------------------------------------------------------------------------------- /Chapter08/pandasDemo/qtpandas/_lib/magic/magic1.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter08/pandasDemo/qtpandas/_lib/magic/magic1.dll -------------------------------------------------------------------------------- /Chapter08/pandasDemo/qtpandas/_lib/magic/zlib1.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter08/pandasDemo/qtpandas/_lib/magic/zlib1.dll -------------------------------------------------------------------------------- /Chapter08/pandasDemo/qtpandas/compat.py: -------------------------------------------------------------------------------- 1 | 2 | import logging 3 | log = logging.getLogger(__name__) 4 | 5 | 6 | try: 7 | import sip 8 | sip.setapi('QString', 2) 9 | sip.setapi('QVariant', 2) 10 | sip.setapi('QDate', 2) 11 | sip.setapi('QDateTime', 2) 12 | sip.setapi('QTextStream', 2) 13 | sip.setapi('QTime', 2) 14 | sip.setapi('QUrl', 2) 15 | except ValueError as e: 16 | log.error(e) 17 | except ImportError as e: 18 | log.error(e) 19 | 20 | try: 21 | from PyQt6.QtCore import * 22 | from PyQt6.QtGui import * 23 | from PyQt6.QtWidgets import * 24 | except: 25 | from PySide6.QtCore import * 26 | from PySide6.QtGui import * 27 | from PySide6.QtWidgets import * 28 | 29 | try: 30 | from PyQt6 import QtCore as QtCore_ 31 | from PyQt6 import QtGui as QtGui2 32 | from PyQt6 import QtWidgets as QtGui_ 33 | from PyQt6.QtCore import pyqtSlot as Slot, pyqtSignal as Signal 34 | except ImportError as e: 35 | from PySide6 import QtCore as QtCore_ 36 | from PySide6 import QtGui as QtGui2 37 | from PySide6 import QtWidgets as QtGui_ 38 | from PySide6.QtCore import Slot, Signal 39 | 40 | 41 | QtCore = QtCore_ 42 | QtGui = QtGui_ 43 | Qt = QtCore_.Qt 44 | 45 | 46 | -------------------------------------------------------------------------------- /Chapter08/pandasDemo/qtpandas/encoding.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import os 3 | import warnings 4 | BASEDIR = os.path.dirname(os.path.abspath(__file__)) 5 | 6 | if sys.platform == 'win32': 7 | # add local folder to path 8 | lib = os.path.join(BASEDIR, '_lib', 'magic') 9 | envpath = os.environ['PATH'] 10 | os.environ['PATH'] = ';'.join([lib, envpath]) 11 | 12 | # FIXME : Can we phase out all of this libmagic crap? 13 | # 14 | # try: 15 | # import magic 16 | # AUTODETECT = True 17 | # except ImportError as e: 18 | # # if sys.platform == 'darwin': 19 | # # raise ImportError('Please install libmagic') 20 | # warnings.warn("Please install libmagic - got an error: {}".format(e)) 21 | # AUTODETECT = False 22 | # except OSError as e: 23 | # warnings.warn("Detector.Issues importing libmagic - got an error: {}".format(e)) 24 | # AUTODETECT = False 25 | # 26 | # 27 | # class Detector(object): 28 | # 29 | # def __init__(self): 30 | # if AUTODETECT: 31 | # if sys.platform.startswith('linux'): 32 | # # Use the system wide installed version comming with windows. 33 | # # The included magic.mgc might be incompatible. 34 | # magic_db = os.path.join('/usr/share/file', 'magic.mgc') 35 | # else: 36 | # magic_db = os.path.join(BASEDIR, '_lib', 'magic', 'db', 37 | # 'magic.mgc') 38 | # if not os.path.exists(magic_db): 39 | # raise ImportError('Please install libmagic.') 40 | # self.magic = magic.Magic(magic_file=magic_db, mime_encoding=True) 41 | # else: 42 | # self.magic = False 43 | # 44 | # def detect(self, filepath): 45 | # if self.magic: 46 | # encoding = self.magic.from_file(filepath) 47 | # return encoding 48 | # return None 49 | -------------------------------------------------------------------------------- /Chapter08/pandasDemo/qtpandas/i18n/de.qm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter08/pandasDemo/qtpandas/i18n/de.qm -------------------------------------------------------------------------------- /Chapter08/pandasDemo/qtpandas/models/ProgressThread.py: -------------------------------------------------------------------------------- 1 | from qtpandas.compat import QtCore, QtGui, Qt, Signal, Slot 2 | 3 | 4 | class ProgressWorker(QtCore.QObject): 5 | 6 | progressChanged = Signal(int) # set value of OverlayProgressView 7 | finished = Signal() 8 | 9 | def __init__(self, name): 10 | """Worker object that will be passed to the thread. 11 | 12 | Args: 13 | name (str): name shown in progress ui. 14 | 15 | """ 16 | super(ProgressWorker, self).__init__() 17 | self.name = name 18 | 19 | @Slot() 20 | def doWork(self): 21 | """start the thread""" 22 | self.run() 23 | # emit the result of the operation? 24 | self.finished.emit() 25 | 26 | def run(self): 27 | """Implement your job here. This is what the thread will do. 28 | 29 | """ 30 | raise NotImplementedError 31 | 32 | 33 | 34 | def createThread(parent, worker, deleteWorkerLater=False): 35 | """Create a new thread for given worker. 36 | 37 | Args: 38 | parent (QObject): parent of thread and worker. 39 | worker (ProgressWorker): worker to use in thread. 40 | deleteWorkerLater (bool, optional): delete the worker if thread finishes. 41 | 42 | Returns: 43 | QThread 44 | 45 | """ 46 | thread = QtCore.QThread(parent) 47 | thread.started.connect(worker.doWork) 48 | worker.finished.connect(thread.quit) 49 | if deleteWorkerLater: 50 | thread.finished.connect(worker.deleteLater) 51 | 52 | worker.moveToThread(thread) 53 | worker.setParent(parent) 54 | return thread 55 | -------------------------------------------------------------------------------- /Chapter08/pandasDemo/qtpandas/models/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter08/pandasDemo/qtpandas/models/__init__.py -------------------------------------------------------------------------------- /Chapter08/pandasDemo/qtpandas/ui/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /Chapter08/pandasDemo/qtpandas/ui/fallback/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /Chapter08/pandasDemo/qtpandas/ui/fallback/easygui/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | Hello from easygui/__init__.py 3 | 4 | """ 5 | 6 | # __all__ must be defined in order for Sphinx to generate the API automatically. 7 | __all__ = ['buttonbox', 8 | 'diropenbox', 9 | 'fileopenbox', 10 | 'filesavebox', 11 | 'textbox', 12 | 'ynbox', 13 | 'ccbox', 14 | 'boolbox', 15 | 'indexbox', 16 | 'msgbox', 17 | 'integerbox', 18 | 'multenterbox', 19 | 'enterbox', 20 | 'exceptionbox', 21 | 'choicebox', 22 | 'codebox', 23 | 'passwordbox', 24 | 'multpasswordbox', 25 | 'multchoicebox', 26 | 'EgStore', 27 | 'eg_version', 28 | 'egversion', 29 | 'abouteasygui', 30 | ] 31 | 32 | # Import all functions that form the API 33 | from .boxes.base_boxes import buttonbox 34 | from .boxes.base_boxes import diropenbox 35 | from .boxes.base_boxes import fileopenbox 36 | from .boxes.base_boxes import filesavebox 37 | 38 | from .boxes.text_box import textbox 39 | 40 | from .boxes.derived_boxes import ynbox 41 | from .boxes.derived_boxes import ccbox 42 | from .boxes.derived_boxes import boolbox 43 | from .boxes.derived_boxes import indexbox 44 | from .boxes.derived_boxes import msgbox 45 | from .boxes.derived_boxes import integerbox 46 | from .boxes.derived_boxes import multenterbox 47 | from .boxes.derived_boxes import enterbox 48 | from .boxes.derived_boxes import exceptionbox 49 | from .boxes.derived_boxes import choicebox 50 | from .boxes.derived_boxes import codebox 51 | from .boxes.derived_boxes import passwordbox 52 | from .boxes.derived_boxes import multpasswordbox 53 | from .boxes.derived_boxes import multchoicebox 54 | from .boxes.egstore import EgStore 55 | from .boxes.about import eg_version, egversion, abouteasygui -------------------------------------------------------------------------------- /Chapter08/pandasDemo/qtpandas/ui/fallback/easygui/boxes/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter08/pandasDemo/qtpandas/ui/fallback/easygui/boxes/__init__.py -------------------------------------------------------------------------------- /Chapter08/pandasDemo/qtpandas/ui/fallback/easygui/boxes/state.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | .. moduleauthor:: Stephen Raymond Ferg and Robert Lugg (active) 4 | .. default-domain:: py 5 | .. highlight:: python 6 | 7 | Version |release| 8 | """ 9 | 10 | # Starting and global variables 11 | 12 | rootWindowPosition = "+300+200" 13 | 14 | PROPORTIONAL_FONT_FAMILY = ("MS", "Sans", "Serif") 15 | MONOSPACE_FONT_FAMILY = "Courier" 16 | 17 | PROPORTIONAL_FONT_SIZE = 10 18 | # a little smaller, because it is more legible at a smaller size 19 | MONOSPACE_FONT_SIZE = 9 20 | TEXT_ENTRY_FONT_SIZE = 12 # a little larger makes it easier to see 21 | 22 | 23 | STANDARD_SELECTION_EVENTS = ["Return", "Button-1", "space"] 24 | -------------------------------------------------------------------------------- /Chapter08/pandasDemo/qtpandas/views/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter08/pandasDemo/qtpandas/views/__init__.py -------------------------------------------------------------------------------- /Chapter08/pandasDemo/qtpandas/views/_ui/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /Chapter08/pandasDemo/qtpandasDemo.py: -------------------------------------------------------------------------------- 1 | from PySide6.QtWidgets import * 2 | import sys 3 | from qtpandas.models.DataFrameModel import DataFrameModel 4 | from qtpandas.views.DataTableView import DataTableWidget 5 | import os 6 | os.chdir(os.path.dirname(__file__)) 7 | import pandas as pd 8 | 9 | class qtpandasDemo(QMainWindow): 10 | 11 | def __init__(self, parent=None): 12 | super(qtpandasDemo, self).__init__(parent) 13 | self.setWindowTitle("qtpandas案例") 14 | self.resize(750, 500) 15 | layoutButton = QHBoxLayout() 16 | buttonInit = QPushButton('初始化数据') 17 | buttonSave = QPushButton('保存') 18 | layoutButton.addWidget(buttonInit) 19 | layoutButton.addWidget(buttonSave) 20 | layoutButton.addStretch(1) 21 | 22 | 23 | 24 | self.table = DataTableWidget() 25 | self.model = DataFrameModel() # 设置新的模型 26 | self.table.setViewModel(self.model) 27 | 28 | self.df = pd.read_excel(r'./data/fund_data.xlsx') 29 | self.df_original = self.df.copy() # 备份原始数据 30 | self.model.setDataFrame(self.df) 31 | 32 | buttonInit.clicked.connect(self.onButtonInit) 33 | buttonSave.clicked.connect(self.onButtonSave) 34 | 35 | layout = QVBoxLayout() 36 | layout.addLayout(layoutButton) 37 | layout.addWidget(self.table) 38 | widget=QWidget() 39 | self.setCentralWidget(widget) 40 | widget.setLayout(layout) 41 | 42 | 43 | def onButtonInit(self): 44 | """ 45 | 初始化pandas 46 | """ 47 | self.model.setDataFrame(self.df_original) 48 | 49 | def onButtonSave(self): 50 | """ 51 | 保存数据 52 | """ 53 | self.df.to_excel(r'./data/fund_data_new.xlsx') 54 | 55 | 56 | if __name__ == "__main__": 57 | app = QApplication(sys.argv) 58 | demo = qtpandasDemo() 59 | demo.show() 60 | app.exec() 61 | 62 | 63 | -------------------------------------------------------------------------------- /Chapter08/plotlyDemo/PyQt_plotly_setHtml.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | 4 | from PySide6.QtCore import * 5 | from PySide6.QtGui import * 6 | from PySide6.QtWidgets import * 7 | from PySide6.QtWebEngineWidgets import * 8 | import sys 9 | 10 | import pandas as pd 11 | import numpy as np 12 | import matplotlib.pyplot as plt 13 | from pandas import Series 14 | from pandas import DataFrame 15 | 16 | import os 17 | import plotly.offline as pyof 18 | import plotly.graph_objs as go 19 | from plotly import figure_factory as ff 20 | 21 | 22 | class MainWindow(QMainWindow): 23 | def __init__(self): 24 | super(MainWindow, self).__init__() 25 | self.setWindowTitle('setHtml无法渲染太大的内容') 26 | self.setGeometry(5, 30, 1355, 730) 27 | self.browser = QWebEngineView() 28 | 29 | lagest_down = [-3.74, -3.736, -3.736, -5.969, -5.969] 30 | xticks = ['2017/01', '2017/02', '2017/03', '2017/04', '2017/05', ] 31 | 32 | trace1 = go.Bar( 33 | x=xticks, 34 | y=lagest_down, 35 | name='最大下跌' 36 | ) 37 | 38 | data = [trace1] 39 | 40 | fig = go.Figure(data=data) 41 | merge_div = pyof.plot(fig, auto_open=False, output_type='div') 42 | message = ''' 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | %s 51 | 52 | 53 | ''' % (merge_div) 54 | 55 | self.browser.setHtml(message) 56 | self.setCentralWidget(self.browser) 57 | 58 | 59 | if __name__ == '__main__': 60 | app = QApplication(sys.argv) 61 | 62 | win = MainWindow() 63 | win.show() 64 | sys.exit(app.exec()) 65 | -------------------------------------------------------------------------------- /Chapter08/plotlyDemo/Ui_plotly_pyqt.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | ################################################################################ 4 | ## Form generated from reading UI file 'plotly_pyqt.ui' 5 | ## 6 | ## Created by: Qt User Interface Compiler version 6.2.3 7 | ## 8 | ## WARNING! All changes made in this file will be lost when recompiling UI file! 9 | ################################################################################ 10 | 11 | from PySide6.QtCore import (QCoreApplication, QDate, QDateTime, QLocale, 12 | QMetaObject, QObject, QPoint, QRect, 13 | QSize, QTime, QUrl, Qt) 14 | from PySide6.QtGui import (QBrush, QColor, QConicalGradient, QCursor, 15 | QFont, QFontDatabase, QGradient, QIcon, 16 | QImage, QKeySequence, QLinearGradient, QPainter, 17 | QPalette, QPixmap, QRadialGradient, QTransform) 18 | from PySide6.QtWebEngineWidgets import QWebEngineView 19 | from PySide6.QtWidgets import (QApplication, QMainWindow, QMenuBar, QSizePolicy, 20 | QStatusBar, QWidget) 21 | 22 | class Ui_MainWindow(object): 23 | def setupUi(self, MainWindow): 24 | if not MainWindow.objectName(): 25 | MainWindow.setObjectName(u"MainWindow") 26 | MainWindow.resize(800, 600) 27 | self.centralwidget = QWidget(MainWindow) 28 | self.centralwidget.setObjectName(u"centralwidget") 29 | self.qwebengine = QWebEngineView(self.centralwidget) 30 | self.qwebengine.setObjectName(u"qwebengine") 31 | self.qwebengine.setGeometry(QRect(0, 10, 451, 321)) 32 | self.qwebengine.setAutoFillBackground(False) 33 | self.qwebengine.setStyleSheet(u"background-color: rgb(170, 170, 127);") 34 | MainWindow.setCentralWidget(self.centralwidget) 35 | self.menubar = QMenuBar(MainWindow) 36 | self.menubar.setObjectName(u"menubar") 37 | self.menubar.setGeometry(QRect(0, 0, 800, 23)) 38 | MainWindow.setMenuBar(self.menubar) 39 | self.statusbar = QStatusBar(MainWindow) 40 | self.statusbar.setObjectName(u"statusbar") 41 | MainWindow.setStatusBar(self.statusbar) 42 | 43 | self.retranslateUi(MainWindow) 44 | 45 | QMetaObject.connectSlotsByName(MainWindow) 46 | # setupUi 47 | 48 | def retranslateUi(self, MainWindow): 49 | MainWindow.setWindowTitle(QCoreApplication.translate("MainWindow", u"MainWindow", None)) 50 | # retranslateUi 51 | 52 | -------------------------------------------------------------------------------- /Chapter08/plotlyDemo/demo_plotly_pyqt.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Module implementing MainWindow. 5 | """ 6 | 7 | from PySide6.QtCore import * 8 | from PySide6.QtGui import * 9 | from PySide6.QtWidgets import * 10 | import sys 11 | from PySide6.QtWebEngineWidgets import QWebEngineView 12 | import os 13 | os.chdir(os.path.dirname(__file__)) 14 | 15 | class Window(QWidget): 16 | def __init__(self): 17 | QWidget.__init__(self) 18 | self.qwebengine = QWebEngineView(self) 19 | self.qwebengine.setGeometry(QRect(50, 20, 1200, 600)) 20 | self.qwebengine.load(QUrl.fromLocalFile('\plotly_html\if_hs300_bais.html')) 21 | 22 | if __name__ == '__main__': 23 | app = QApplication(sys.argv) 24 | screen = Window() 25 | screen.showMaximized() 26 | sys.exit(app.exec()) 27 | -------------------------------------------------------------------------------- /Chapter08/plotlyDemo/plotlyDemo.py: -------------------------------------------------------------------------------- 1 | from PySide6.QtCore import * 2 | from PySide6.QtGui import * 3 | from PySide6.QtWidgets import * 4 | import sys 5 | import os 6 | import plotly.offline as pyof 7 | import plotly.graph_objs as go 8 | import pandas as pd 9 | from PySide6.QtWebEngineWidgets import QWebEngineView 10 | import os 11 | os.chdir(os.path.dirname(__file__)) 12 | 13 | class MainWindow(QWidget): 14 | 15 | def __init__(self, parent=None): 16 | super(MainWindow, self).__init__(parent) 17 | 18 | plotly_dir = 'plotly_html' 19 | if not os.path.isdir(plotly_dir): 20 | os.mkdir(plotly_dir) 21 | self.path_dir_plotly_html = os.getcwd() + os.sep + plotly_dir 22 | 23 | self.qwebengine = QWebEngineView(self) 24 | layout = QHBoxLayout() 25 | layout.addWidget(self.qwebengine) 26 | self.setLayout(layout) 27 | self.qwebengine.load(QUrl.fromLocalFile(self.get_plotly_path_if_hs300_bais())) 28 | 29 | def get_plotly_path_if_hs300_bais(self, file_name='if_hs300_bais.html'): 30 | path_plotly = self.path_dir_plotly_html + os.sep + file_name 31 | df = pd.read_excel(r'plotly_html\if_index_bais.xlsx') 32 | 33 | '''绘制散点图''' 34 | line_main_price = go.Scatter( 35 | x=df.index, 36 | y=df['main_price'], 37 | name='main_price', 38 | connectgaps=True, # 这个参数表示允许连接数据缺口 39 | ) 40 | 41 | line_hs300_close = go.Scatter( 42 | x=df.index, 43 | y=df['hs300_close'], 44 | name='hs300_close', 45 | connectgaps=True, 46 | ) 47 | data = [line_hs300_close, line_main_price] 48 | 49 | layout = dict(title='if_hs300_bais', 50 | xaxis=dict(title='Date'), 51 | yaxis=dict(title='Price'), 52 | ) 53 | 54 | fig = go.Figure(data=data, layout=layout) 55 | pyof.plot(fig, filename=path_plotly, auto_open=False) 56 | return path_plotly 57 | 58 | if __name__ == '__main__': 59 | app = QApplication(sys.argv) 60 | win = MainWindow() 61 | win.showMaximized() 62 | app.exec() 63 | -------------------------------------------------------------------------------- /Chapter08/plotlyDemo/plotly_html/if_index_bais.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter08/plotlyDemo/plotly_html/if_index_bais.xlsx -------------------------------------------------------------------------------- /Chapter08/plotlyDemo/plotly_pyqt.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Module implementing MainWindow. 5 | """ 6 | 7 | from Ui_plotly_pyqt import Ui_MainWindow 8 | from PySide6.QtCore import * 9 | from PySide6.QtGui import * 10 | from PySide6.QtWidgets import * 11 | import sys 12 | import plotly.offline as pyof 13 | import plotly.graph_objs as go 14 | import pandas as pd 15 | import os 16 | 17 | 18 | class MainWindow(QMainWindow, Ui_MainWindow): 19 | 20 | def __init__(self, parent=None): 21 | super(MainWindow, self).__init__(parent) 22 | self.setupUi(self) 23 | 24 | plotly_dir = 'plotly_html' 25 | if not os.path.isdir(plotly_dir): 26 | os.mkdir(plotly_dir) 27 | self.path_dir_plotly_html = os.getcwd() + os.sep + plotly_dir 28 | 29 | self.qwebengine.setGeometry(QRect(50, 20, 1200, 600)) 30 | self.qwebengine.load(QUrl.fromLocalFile(self.get_plotly_path_if_hs300_bais())) 31 | 32 | def get_plotly_path_if_hs300_bais(self, file_name='if_hs300_bais.html'): 33 | path_plotly = self.path_dir_plotly_html + os.sep + file_name 34 | df = pd.read_excel(r'plotly_html\if_index_bais.xlsx') 35 | 36 | '''绘制散点图''' 37 | line_main_price = go.Scatter( 38 | x=df.index, 39 | y=df['main_price'], 40 | name='main_price', 41 | connectgaps=True, # 这个参数表示允许连接数据缺口 42 | ) 43 | 44 | line_hs300_close = go.Scatter( 45 | x=df.index, 46 | y=df['hs300_close'], 47 | name='hs300_close', 48 | connectgaps=True, 49 | ) 50 | data = [line_hs300_close, line_main_price] 51 | 52 | layout = dict(title='if_hs300_bais', 53 | xaxis=dict(title='Date'), 54 | yaxis=dict(title='Price'), 55 | ) 56 | 57 | fig = go.Figure(data=data, layout=layout) 58 | pyof.plot(fig, filename=path_plotly, auto_open=False) 59 | return path_plotly 60 | 61 | if __name__ == '__main__': 62 | app = QApplication(sys.argv) 63 | win = MainWindow() 64 | win.showMaximized() 65 | app.exec() 66 | -------------------------------------------------------------------------------- /Chapter08/plotlyDemo/plotly_pyqt.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | MainWindow 4 | 5 | 6 | 7 | 0 8 | 0 9 | 800 10 | 600 11 | 12 | 13 | 14 | MainWindow 15 | 16 | 17 | 18 | 19 | 20 | 0 21 | 10 22 | 451 23 | 321 24 | 25 | 26 | 27 | false 28 | 29 | 30 | background-color: rgb(170, 170, 127); 31 | 32 | 33 | 34 | 35 | 36 | 37 | 0 38 | 0 39 | 800 40 | 23 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | QWebEngineView 49 | QWidget 50 |
PySide6.QtWebEngineWidgets
51 | 1 52 |
53 |
54 | 55 | 56 |
57 | -------------------------------------------------------------------------------- /Chapter08/pyqtgraphDemo/pyqtgraph_pyqt.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | MainWindow 4 | 5 | 6 | 7 | 0 8 | 0 9 | 800 10 | 600 11 | 12 | 13 | 14 | MainWindow 15 | 16 | 17 | 18 | 19 | 20 | 670 21 | 140 22 | 75 23 | 23 24 | 25 | 26 | 27 | 水平绘图 28 | 29 | 30 | 31 | 32 | 33 | 10 34 | 10 35 | 601 36 | 201 37 | 38 | 39 | 40 | 41 | 42 | 43 | 10 44 | 220 45 | 381 46 | 351 47 | 48 | 49 | 50 | 51 | 52 | 53 | 430 54 | 380 55 | 75 56 | 23 57 | 58 | 59 | 60 | 垂直绘图 61 | 62 | 63 | 64 | 65 | 66 | 67 | 0 68 | 0 69 | 800 70 | 23 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | GraphicsLayoutWidget 79 | QWidget 80 |
pyqtgraph
81 | 1 82 |
83 |
84 | 85 | 86 |
87 | -------------------------------------------------------------------------------- /Chapter09/myQuant/out/下影线策略_tradeFlow.csv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter09/myQuant/out/下影线策略_tradeFlow.csv -------------------------------------------------------------------------------- /Chapter09/myQuant/plotDataList.pkl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter09/myQuant/plotDataList.pkl -------------------------------------------------------------------------------- /Chapter09/myQuant/quant/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter09/myQuant/quant/__init__.py -------------------------------------------------------------------------------- /Chapter09/myQuant/quant/rhPlot/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter09/myQuant/quant/rhPlot/__init__.py -------------------------------------------------------------------------------- /Chapter09/myQuant/quant/rhPlot/plotDataList.pkl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/Chapter09/myQuant/quant/rhPlot/plotDataList.pkl -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 《Python 数据分析:基于 Plotly 的动态可视化绘图》源代码 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /appendix/B-CtoPyhtonDemo/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Generated from extension.pro. 2 | 3 | cmake_minimum_required(VERSION 3.16) 4 | project(extension LANGUAGES CXX) 5 | 6 | set(CMAKE_INCLUDE_CURRENT_DIR ON) 7 | 8 | set(CMAKE_AUTOMOC ON) 9 | set(CMAKE_AUTORCC ON) 10 | set(CMAKE_AUTOUIC ON) 11 | 12 | if(NOT DEFINED INSTALL_EXAMPLESDIR) 13 | set(INSTALL_EXAMPLESDIR "examples") 14 | endif() 15 | 16 | set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/dialogs/extension") 17 | 18 | find_package(Qt6 COMPONENTS Core) 19 | find_package(Qt6 COMPONENTS Gui) 20 | find_package(Qt6 COMPONENTS Widgets) 21 | 22 | qt_add_executable(extension 23 | finddialog.cpp finddialog.h 24 | main.cpp 25 | ) 26 | set_target_properties(extension PROPERTIES 27 | WIN32_EXECUTABLE TRUE 28 | MACOSX_BUNDLE TRUE 29 | ) 30 | target_link_libraries(extension PUBLIC 31 | Qt::Core 32 | Qt::Gui 33 | Qt::Widgets 34 | ) 35 | 36 | install(TARGETS extension 37 | RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" 38 | BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" 39 | LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" 40 | ) 41 | -------------------------------------------------------------------------------- /appendix/B-CtoPyhtonDemo/extension.pro: -------------------------------------------------------------------------------- 1 | QT += widgets 2 | 3 | HEADERS = finddialog.h 4 | SOURCES = finddialog.cpp \ 5 | main.cpp 6 | 7 | # install 8 | target.path = $$[QT_INSTALL_EXAMPLES]/widgets/dialogs/extension 9 | INSTALLS += target 10 | -------------------------------------------------------------------------------- /appendix/X/fundDemo/data/fund_data.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/appendix/X/fundDemo/data/fund_data.xlsx -------------------------------------------------------------------------------- /appendix/X/fundDemo/data/fund_data_new.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/appendix/X/fundDemo/data/fund_data_new.xlsx -------------------------------------------------------------------------------- /appendix/X/fundDemo/data/和聚光明1号_hs300_merge.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/appendix/X/fundDemo/data/和聚光明1号_hs300_merge.xlsx -------------------------------------------------------------------------------- /appendix/X/fundDemo/data/时时安稳健1号.csv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/appendix/X/fundDemo/data/时时安稳健1号.csv -------------------------------------------------------------------------------- /appendix/X/fundDemo/data/昆仑信托-昆仑三十六号.csv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/appendix/X/fundDemo/data/昆仑信托-昆仑三十六号.csv -------------------------------------------------------------------------------- /appendix/X/fundDemo/data/组合.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/appendix/X/fundDemo/data/组合.xlsx -------------------------------------------------------------------------------- /appendix/X/fundDemo/data/长城国瑞证券恒通23号.csv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/appendix/X/fundDemo/data/长城国瑞证券恒通23号.csv -------------------------------------------------------------------------------- /appendix/X/fundDemo/fundFOFRun.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Module implementing MainWindow. 5 | """ 6 | 7 | import pandas as pd 8 | import numpy as np 9 | 10 | from PySide6.QtWidgets import * 11 | from PySide6 import QtCore, QtGui 12 | from PySide6.QtCore import * 13 | from PySide6.QtGui import * 14 | 15 | from fundFOF import Ui_MainWindow 16 | # from PandasModel import PandasModel 17 | from Plotly_Qt import Plotly_Qt 18 | 19 | 20 | 21 | 22 | class MainWindow(QMainWindow, Ui_MainWindow): 23 | """ 24 | Class documentation goes here. 25 | """ 26 | 27 | def __init__(self, parent=None): 28 | """ 29 | Constructor 30 | 31 | @param parent reference to the parent widget 32 | @type QWidget 33 | """ 34 | super(MainWindow, self).__init__(parent) 35 | self.setupUi(self) 36 | self.plotly_Qt = Plotly_Qt() 37 | 38 | '''手动调整窗口部件的大小,使之看着更美观''' 39 | self.widget_parameter_tree.setMaximumWidth(300) 40 | self.widget_parameter_tree.setMinimumWidth(200) 41 | self.QWebEngineView_ProductVsHs300.setMinimumHeight(500) 42 | self.tabWidget.setMinimumHeight(400) 43 | 44 | 45 | '''显示parametertree,这里通过布局管理器来把ParameterTree间接地嵌套进Widget窗口里面''' 46 | from mypyqtgraph import p 47 | from pyqtgraph.parametertree import ParameterTree 48 | 49 | t = ParameterTree() 50 | t.setParameters(p, showTop=False) 51 | t.setHeaderLabels(["参数", "数值"]) 52 | # t.setWindowTitle('pyqtgraph example: Parameter Tree') 53 | layout = QGridLayout() 54 | self.widget_parameter_tree.setLayout(layout) 55 | layout.addWidget( 56 | QLabel("千石资本-和聚光明1号资产管理计划基本信息"), 0, 0, 1, 1) 57 | layout.addWidget(t) 58 | 59 | '''显示绘图函数''' 60 | self.QWebEngineView_ProductVsHs300.load( 61 | QUrl.fromLocalFile(self.plotly_Qt.get_plotly_path_product_vs_hs300())) 62 | self.QWebEngineView_LagestBack.load(QUrl.fromLocalFile(self.plotly_Qt.get_plotly_path_lagest_back())) 63 | self.QWebEngineView_PeriodReturn.load(QUrl.fromLocalFile(self.plotly_Qt.get_plotly_path_period_return())) 64 | self.QWebEngineview_MonthReturn.load(QUrl.fromLocalFile(self.plotly_Qt.get_plotly_path_month_return())) 65 | 66 | 67 | if __name__ == "__main__": 68 | import sys 69 | app = QApplication(sys.argv) 70 | ui = MainWindow() 71 | ui.showMaximized() 72 | sys.exit(app.exec()) 73 | -------------------------------------------------------------------------------- /appendix/X/images/boy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/appendix/X/images/boy.png -------------------------------------------------------------------------------- /appendix/X/images/down.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/appendix/X/images/down.png -------------------------------------------------------------------------------- /appendix/X/images/left.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/appendix/X/images/left.png -------------------------------------------------------------------------------- /appendix/X/images/mask.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/appendix/X/images/mask.png -------------------------------------------------------------------------------- /appendix/X/images/mask2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/appendix/X/images/mask2.png -------------------------------------------------------------------------------- /appendix/X/images/right.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/appendix/X/images/right.png -------------------------------------------------------------------------------- /appendix/X/images/up.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/appendix/X/images/up.png -------------------------------------------------------------------------------- /appendix/X/qt_setMask1.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | 【简介】 5 | 不规则的,可以拖动的窗体实现例子 6 | 7 | 8 | """ 9 | 10 | import sys 11 | from PySide6.QtWidgets import QApplication, QWidget 12 | from PySide6.QtGui import QPixmap, QPainter, QCursor, QBitmap,QMouseEvent 13 | from PySide6.QtCore import Qt 14 | import os 15 | os.chdir(os.path.dirname(__file__)) 16 | 17 | class ShapeWidget(QWidget): 18 | def __init__(self, parent=None): 19 | super(ShapeWidget, self).__init__(parent) 20 | self.setWindowTitle("不规则的,可以拖动的窗体实现例子") 21 | self.updatePix() 22 | 23 | # 显示不规则 pic 24 | def updatePix(self): 25 | # self.pix = QBitmap("./images/mask.png") 26 | self.pix = QBitmap("./images/mask2.png") 27 | self.resize(self.pix.size()) 28 | self.setMask(self.pix) 29 | print(self.pix.size()) 30 | self.dragPosition = None 31 | 32 | # 重定义鼠标按下响应函数mousePressEvent(QMouseEvent)和鼠标移动响应函数mouseMoveEvent(QMouseEvent),使不规则窗体能响应鼠标事件,随意拖动。 33 | def mousePressEvent(self, event:QMouseEvent): 34 | if event.button() == Qt.LeftButton: 35 | self.m_drag = True 36 | self.m_DragPosition = event.globalPosition().toPoint() - self.pos() 37 | event.accept() 38 | self.setCursor(QCursor(Qt.OpenHandCursor)) 39 | if event.button() == Qt.RightButton: 40 | self.close() 41 | 42 | def mouseMoveEvent(self, event:QMouseEvent): 43 | if Qt.LeftButton and self.m_drag: 44 | # 当左键移动窗体修改偏移值 45 | self.move(event.globalPosition().toPoint() - self.m_DragPosition) 46 | event.accept() 47 | 48 | def mouseReleaseEvent(self, event:QMouseEvent): 49 | self.m_drag = False 50 | self.setCursor(QCursor(Qt.ArrowCursor)) 51 | 52 | # 一般 paintEvent 在窗体首次绘制加载, 要重新加载paintEvent 需要重新加载窗口使用 self.update() or self.repaint() 53 | def paintEvent(self, event): 54 | painter = QPainter(self) 55 | painter.drawPixmap(0, 0, self.width(), self.height(), QPixmap("./images/boy.png")) 56 | 57 | 58 | if __name__ == '__main__': 59 | app = QApplication(sys.argv) 60 | form = ShapeWidget() 61 | form.show() 62 | app.exec() 63 | -------------------------------------------------------------------------------- /appendix/X/testCase/RunTestCase.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | 【简介】 5 | 自动化测试用例 6 | 7 | 8 | """ 9 | 10 | import unittest 11 | import HTMLTestRunner 12 | import time 13 | from MatrixWinTest import MatrixWinTest 14 | from PySide6.QtWidgets import QApplication 15 | import sys 16 | import os 17 | os.chdir(os.path.dirname(__file__)) 18 | 19 | if __name__ == "__main__": 20 | app = QApplication(sys.argv) 21 | now = time.strftime("%Y-%m-%d-%H_%M_%S", time.localtime(time.time())) 22 | print(now) 23 | testunit = unittest.TestSuite() 24 | testunit.addTest(unittest.makeSuite(MatrixWinTest)) 25 | 26 | 27 | htmlFile = ".\\" + now + "HTMLtemplate.html" 28 | print('htmlFile=' + htmlFile) 29 | fp = open(htmlFile, 'wb') 30 | runner = HTMLTestRunner.HTMLTestRunner( 31 | stream=fp, 32 | title=u"Qt for Python测试报告", 33 | description=u"用例测试情况") 34 | runner.run(testunit) 35 | app.exec() 36 | fp.close() 37 | 38 | -------------------------------------------------------------------------------- /appendix/X/testCase/reportLog.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/appendix/X/testCase/reportLog.txt -------------------------------------------------------------------------------- /appendix/《PySide6-PyQt6快速开发与实战》附赠电子版.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunshe35/PySide6-codes/bc27d951e3bb004ede417ee5ae8e37c16f31251c/appendix/《PySide6-PyQt6快速开发与实战》附赠电子版.pdf --------------------------------------------------------------------------------