Skip to main content
added 4 characters in body; edited tags; edited title
Source Link
Taras
  • 34.1k
  • 4
  • 73
  • 148

How to display Displaying QgsMessageBar from a plugin?

As suggested in docs, the QGIS message bar is usually the best option to show short messages communicating with the user.

Is it possible to show the QGIS message bar inside a plugin's guiGUI developed with Qt Designer as shown below?

QGIS guiGUI:

  
QGIS interface

Desired plugin guiGUI:

  
Desired plugin interface

This would simplify interacting with the user when plugin's window is in full screen mode, hiding qgisQGIS main window.

EDIT after J. Monticolo's answer.

In order to integrate J. Monticolo's code to an existing plugin, I inserted this in its main's run method:

def run(self):
        """Run method that performs all the real work"""

        # Create the dialog with elements (after translation) and keep reference
        # Only create GUI ONCE in callback, so that it will only load when the plugin is started
        if self.first_start == True:
            self.first_start = False            
            self.my_msg_bar = QgsMessageBar()
            self.dlg.verticalLayout.insertWidget(0, self.my_msg_bar)
            self.my_msg_bar.pushMessage("Welcome", "This plugin is ready at your service.", level=Qgis.Success, duration=-1)

Where verticalLayoutverticalLayout is an object introduced with Qt Designer:

enter image description here

referenceReference: https://docs.qgis.org/3.16/en/docs/pyqgis_developer_cookbook/communicating.html

How to display QgsMessageBar from a plugin?

As suggested in docs, the QGIS message bar is usually the best option to show short messages communicating with the user.

Is it possible to show the QGIS message bar inside a plugin's gui developed with Qt Designer as shown below?

QGIS gui:

 QGIS interface

Desired plugin gui:

 Desired plugin interface

This would simplify interacting with the user when plugin's window is in full screen mode, hiding qgis main window.

EDIT after J. Monticolo's answer.

In order to integrate J. Monticolo's code to an existing plugin, I inserted this in its main's run method:

def run(self):
        """Run method that performs all the real work"""

        # Create the dialog with elements (after translation) and keep reference
        # Only create GUI ONCE in callback, so that it will only load when the plugin is started
        if self.first_start == True:
            self.first_start = False            
            self.my_msg_bar = QgsMessageBar()
            self.dlg.verticalLayout.insertWidget(0, self.my_msg_bar)
            self.my_msg_bar.pushMessage("Welcome", "This plugin is ready at your service.", level=Qgis.Success, duration=-1)

Where verticalLayout is an object introduced with Qt Designer:

enter image description here

reference: https://docs.qgis.org/3.16/en/docs/pyqgis_developer_cookbook/communicating.html

Displaying QgsMessageBar from plugin

As suggested in docs, the QGIS message bar is usually the best option to show short messages communicating with the user.

Is it possible to show the QGIS message bar inside a plugin's GUI developed with Qt Designer as shown below?

QGIS GUI: 
QGIS interface

Desired plugin GUI: 
Desired plugin interface

This would simplify interacting with the user when plugin's window is in full screen mode, hiding QGIS main window.

EDIT after J. Monticolo's answer.

In order to integrate J. Monticolo's code to an existing plugin, I inserted this in its main's run method:

def run(self):
        """Run method that performs all the real work"""

        # Create the dialog with elements (after translation) and keep reference
        # Only create GUI ONCE in callback, so that it will only load when the plugin is started
        if self.first_start == True:
            self.first_start = False            
            self.my_msg_bar = QgsMessageBar()
            self.dlg.verticalLayout.insertWidget(0, self.my_msg_bar)
            self.my_msg_bar.pushMessage("Welcome", "This plugin is ready at your service.", level=Qgis.Success, duration=-1)

Where verticalLayout is an object introduced with Qt Designer:

enter image description here

Reference: https://docs.qgis.org/3.16/en/docs/pyqgis_developer_cookbook/communicating.html

added 937 characters in body
Source Link

As suggested in docs, the QGIS message bar is usually the best option to show short messages communicating with the user.

Is it possible to show the QGIS message bar inside a plugin's gui developed with Qt Designer as shown below?

QGIS gui:

QGIS interface

Desired plugin gui:

Desired plugin interface

This would simplify interacting with the user when plugin's window is in full screen mode, hiding qgis main window.

EDIT after J. Monticolo's answer.

In order to integrate J. Monticolo's code to an existing plugin, I inserted this in its main's run method:

def run(self):
        """Run method that performs all the real work"""

        # Create the dialog with elements (after translation) and keep reference
        # Only create GUI ONCE in callback, so that it will only load when the plugin is started
        if self.first_start == True:
            self.first_start = False            
            self.my_msg_bar = QgsMessageBar()
            self.dlg.verticalLayout.insertWidget(0, self.my_msg_bar)
            self.my_msg_bar.pushMessage("Welcome", "This plugin is ready at your service.", level=Qgis.Success, duration=-1)

Where verticalLayout is an object introduced with Qt Designer:

enter image description here

reference: https://docs.qgis.org/3.16/en/docs/pyqgis_developer_cookbook/communicating.html

As suggested in docs, the QGIS message bar is usually the best option to show short messages communicating with the user.

Is it possible to show the QGIS message bar inside a plugin's gui developed with Qt Designer as shown below?

QGIS gui:

QGIS interface

Desired plugin gui:

Desired plugin interface

This would simplify interacting with the user when plugin's window is in full screen mode, hiding qgis main window.

reference: https://docs.qgis.org/3.16/en/docs/pyqgis_developer_cookbook/communicating.html

As suggested in docs, the QGIS message bar is usually the best option to show short messages communicating with the user.

Is it possible to show the QGIS message bar inside a plugin's gui developed with Qt Designer as shown below?

QGIS gui:

QGIS interface

Desired plugin gui:

Desired plugin interface

This would simplify interacting with the user when plugin's window is in full screen mode, hiding qgis main window.

EDIT after J. Monticolo's answer.

In order to integrate J. Monticolo's code to an existing plugin, I inserted this in its main's run method:

def run(self):
        """Run method that performs all the real work"""

        # Create the dialog with elements (after translation) and keep reference
        # Only create GUI ONCE in callback, so that it will only load when the plugin is started
        if self.first_start == True:
            self.first_start = False            
            self.my_msg_bar = QgsMessageBar()
            self.dlg.verticalLayout.insertWidget(0, self.my_msg_bar)
            self.my_msg_bar.pushMessage("Welcome", "This plugin is ready at your service.", level=Qgis.Success, duration=-1)

Where verticalLayout is an object introduced with Qt Designer:

enter image description here

reference: https://docs.qgis.org/3.16/en/docs/pyqgis_developer_cookbook/communicating.html

Source Link

How to display QgsMessageBar from a plugin?

As suggested in docs, the QGIS message bar is usually the best option to show short messages communicating with the user.

Is it possible to show the QGIS message bar inside a plugin's gui developed with Qt Designer as shown below?

QGIS gui:

QGIS interface

Desired plugin gui:

Desired plugin interface

This would simplify interacting with the user when plugin's window is in full screen mode, hiding qgis main window.

reference: https://docs.qgis.org/3.16/en/docs/pyqgis_developer_cookbook/communicating.html