I'm creating QGIS plugin and I'm informing user about the progress of computation via QProgressBar, that is shown in messageBar. I have added Cancel button, that gives user a possibility to end the computation (it shows QMessageBox with question whether the user wants to end computation or not). I'd like to implement the same functionality as Cancel button to x button, that is created automatically as part of messageBar or completely erase it, so there will be only Cancel button.
Does anybody have an idea how to get rid of x button or what signal is emitted, when it is clicked? I found one signal in QObject class - destroyed, but if I understand it correctly from the documentation, the process of destroying QObject cannot be stopped this way.
For illustration, my code looks like this:
def progressBar(self): """Initializing progress bar. """ self.progressMessageBar = iface.messageBar().createMessage(u"Ground Radiation Monitoring:",u" Computing...") self.progress = QProgressBar() self.progress.setMaximum(100) self.progress.setAlignment(Qt.AlignLeft|Qt.AlignVCenter) self.cancelButton = QtGui.QPushButton() self.cancelButton.setText('Cancel') self.progressMessageBar.layout().addWidget(self.cancelButton) self.progressMessageBar.layout().addWidget(self.progress) self.iface.messageBar().pushWidget(self.progressMessageBar, iface.messageBar().INFO) self.cancelButton.clicked.connect(self.onCancelButton)