Hi,
I think in this case, as you do not want to close your gui, you should put the message bar in your gui, I suppose it's a dialog. you have a code sample in Qgis cookbook <https://docs.qgis.org/testing/en/docs/pyqgis_developer_cookbook/communicating.html> , may it can help you: class MyDialog(QDialog): def __init__(self): QDialog.__init__(self) self.bar = QgsMessageBar() self.bar.setSizePolicy( QSizePolicy.Minimum, QSizePolicy.Fixed ) self.setLayout(QGridLayout()) self.layout().setContentsMargins(0, 0, 0, 0) self.buttonbox = QDialogButtonBox(QDialogButtonBox.Ok) self.buttonbox.accepted.connect(self.run) self.layout().addWidget(self.buttonbox, 0, 0, 2, 1) self.layout().addWidget(self.bar, 0, 0, 1, 1) def run(self): self.bar.pushMessage("Hello", "World", level=Qgis.Info) De: QGIS-Developer [mailto:qgis-developer-boun...@lists.osgeo.org] Em nome de Roberta Fagandini Enviada em: sexta-feira, 3 de maio de 2019 10:45 Para: qgis-developer@lists.osgeo.org Assunto: [QGIS-Developer] show error message without exiting the plugin Hi all, I'm developing a plugin and I need to check if some features of the input vector layer are selected or not. If not I'd like to show an error message without closing the plugin gui: This is the code at the moment: if self.dlg.checkBox.isChecked(): check_sel = selectedLayer2.selectedFeatureCount() if check_sel > 0: intersec_layer = QgsProcessingFeatureSourceDefinition(selectedLayer2.id(), True) else: self.iface.messageBar().pushCritical("Error", "No features selected in layer {}.".format(selectedLayer2.name())) return Any idea? Thanks Roberta
_______________________________________________ QGIS-Developer mailing list QGIS-Developer@lists.osgeo.org List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer