• 技术文章 >Python技术 >Python基础教程

    python PyQt信号和插槽的连接

    小妮浅浅小妮浅浅2021-10-09 09:55:45原创2451

    1、为了让菜单选项和工具栏在用户点击它们时启动,需要将信号与内置插槽连接起来。

    2、QAction物体可以发出各种信号。triggered()与插槽连接。

    菜单和工具栏中最常用的信号是.triggered()。用户每次点击菜单选项或工具栏按钮都会发出这个信号。

    实例

    1

    2

    3

    4

    5

    6

    7

    8

    9

    10

    11

    12

    13

    14

    15

    16

    17

    18

    19

    20

    21

    22

    23

    24

    25

    26

    27

    28

    29

    30

    31

    32

    33

    class Window(QMainWindow):

        # Snip...

        def newFile(self):

            # Logic for creating a new file goes here...

            self.centralWidget.setText("<b>File > New</b> clicked")

      

        def openFile(self):

            # Logic for opening an existing file goes here...

            self.centralWidget.setText("<b>File > Open...</b> clicked")

      

        def saveFile(self):

            # Logic for saving a file goes here...

            self.centralWidget.setText("<b>File > Save</b> clicked")

      

        def copyContent(self):

            # Logic for copying content goes here...

            self.centralWidget.setText("<b>Edit > Copy</b> clicked")

      

        def pasteContent(self):

            # Logic for pasting content goes here...

            self.centralWidget.setText("<b>Edit > Paste</b> clicked")

      

        def cutContent(self):

            # Logic for cutting content goes here...

            self.centralWidget.setText("<b>Edit > Cut</b> clicked")

      

        def helpContent(self):

            # Logic for launching help goes here...

            self.centralWidget.setText("<b>Help > Help Content...</b> clicked")

      

        def about(self):

            # Logic for showing an about dialog content goes here...

            self.centralWidget.setText("<b>Help > About...</b> clicked")

    以上就是python PyQt信号和插槽的连接方法,希望对大家有所帮助。更多Python学习指路:python基础教程

    本文教程操作环境:windows7系统、Python 3.9.1,DELL G3电脑。

    专题推荐:python pyqt
    上一篇:python PyQt组织上下文菜单选项 下一篇:Python PyQt菜单的动态填充

    相关文章推荐

    • python线程通信Condition提供的方法• python正则表达式问号的使用• python选择排序算法的特点• python format()的格式化使用• python中%如何实现格式化• python中PyQt创建菜单栏• python PyQt如何使用资源• python PyQt添加菜单选项• python PyQt子菜单的使用• python PyQt用动作填充工具栏• python PyQt向工具栏添加小部件• python PyQt组织菜单和工具栏• python PyQt创建上下文菜单• python PyQt事件处理实现上下文菜单• python PyQt组织上下文菜单选项

    全部评论我要评论

    © 2021 Python学习网 苏ICP备2021003149号-1

  • 取消发布评论
  • 

    Python学习网