pyqt5-1.按鈕組互斥操作

  1. 創建按鈕組
# -*- coding: UTF-8 -*-
from PyQt5.Qt import *
from PyQt5 import QtCore, QtGui, QtWidgets
 cb_group = QButtonGroup()
 self.cb_group.addButton(self.pushButton_enterprise,0)
        self.cb_group.addButton(self.pushButton_private,1)
        self.cb_group.addButton(self.pushButton_projectwork,2)
        self.cb_group.addButton(self.pushButton_teamwork,3)
        self.cb_group.addButton(self.pushButton_collect,4)
        self.cb_group.addButton(self.pushButton_history,5)
        self.cb_group.addButton(self.pushButton_translist,6)
        self.cb_group.addButton(self.pushButton_sync,7)
        self.cb_group.addButton(self.pushButton_recycl,8)
        self.cb_group.setExclusive(True)   //設置按鈕組互斥

        self.cb_group.buttonClicked[int].connect(self.slot_buttongroup_switch_ctl)   //按鈕組被按下觸發的槽
  1. 按鈕組槽處理
def slot_buttongroup_switch_ctl(self,id):
        self.button_switch_clicked(id)

id對應的就是按下組中對應的按鈕編號

def button_switch_clicked(self,id):
        self.button_switch_clicked_tubiao(id)
        self.enterprise_show = e1form()
        self.r_Widget_main.addWidget(self.enterprise_show)
        self.enterprise_show.show()
        self.enterprise_show.setVisible(False)
        print("px:",self.width()-self.leftWidget.width()-globalv.gl_leftwidget_lc,"py:",self.height())
        globalv.gl_menban.resize(self.width()-self.leftWidget.width()-globalv.gl_leftwidget_lc,self.height())
        globalv.gl_menban.setVisible(True)
        globalv.gl_menban.move(self.x()+self.leftWidget.width()+globalv.gl_leftwidget_lc,self.y())
        if 0 == id:
            globalv.gl_com_dev.post(ufile.webdirlist_data(-1,"0"))
        elif 1 == id:
            globalv.gl_com_dev.post(ufile.webdirlist_data(-1,"0"))
            pass
        elif 2 == id:
            pass
        elif 3 == id:
            pass
        elif 4 == id:
            pass
        elif 5 == id:
            pass
        elif 6 == id:
            pass
        elif 7 == id:
            pass
        elif 8 == id:
            pass

這個函數中就是針對不同的按鈕對應的不同的操作,既有界面切換,也有數據傳輸

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章