从QWidget更改QMainWindow中的statusBar

时间:2017-03-20 14:29:55

标签: python pyqt pyqt5

这里我有一个QMainWindow和QWidget类

class WifiHotspot(QMainWindow):

    def __init__(self, parent=None):
        super(WifiHotspot, self).__init__(parent)
        self.title = 'WIFI HOTSPOT'
        self.initUI()

    def initUI(self):
        self.virtual_wifi = VirtualWifi(self)
        self.setCentralWidget(self.virtual_wifi)

        # i want to dynamic set statusBar in VirtualWifi class
        #self.statusBar().showMessage('message here') # it work only in WifiHotspot

        self.setWindowTitle(self.title)
        self.show()

class VirtualWifi(QWidget):

    def __init__(self, parent):
        super (VirtualWifi, self).__init__(parent)
        self.initVirtualWifi()

    def initVirtualWifi(self):

        startButton = QPushButton('Start', self)
        startButton.setToolTip('Start sharing wifi')
        // when click
        startButton.clicked.connect(self.start_hotspot)

    @pyqtSlot()
    def start_hotspot(self):
        # show message in statusBar in QMainWindow

当从VirtualWifi点击startButton时,如何在WifiHotspot中显示statusBar消息

1 个答案:

答案 0 :(得分:0)

这是一个答案

**答案:

在WifiHotspot中创建一个set_status_message

def set_status_message(self, message):
        return self.statusBar().showMessage(message) 

从start_hotspot(自我)

调用它
def start_hotspot(self):
        self.parent().set_status_message('hello world')