1
votes

Here I have a QMainWindow and QWidget class

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

How can I show a statusBar message in WifiHotspot when click startButton from VirtualWifi

1
Just refer to self.parent() in start_hotspot? - a_guest
@a_guest where can i put this - thoongnv
@a_guest thank you, i solved it with your help, i will edited my question - thoongnv
Please don't add the answer to the question, but put it as separate item (an answer) using the answer box below. - Trilarion
@Trilarion okie, I'll do it - thoongnv

1 Answers

0
votes

Here is an answer

** Answers:

Create a set_status_message in WifiHotspot

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

Call it from start_hotspot(self)

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