1

I have two quick questions with the plugin I built:

  1. (Red circle) How can I set the size of the plugin window when it loads into QGIS? The default size when loaded is a little bit too small and not all tabs are visible.

  2. (Yellow circle) Is there any method to change the name of the plugin? I change the code of the Sava_attribute plugin (in the tutorial) to make my own but I would like the change the name of the plugin.

enter image description here

1

You can change the size (and position) of your plugin window fairly easily. You should be able to add the following line in the initGui() method of your main plugin python file (change the parameters to suit your needs):

self.dlg.setGeometry(100, 100, 750, 500)

The parameters are: x position (distance from left of screen), y position (distance from top of screen), width of dialog window, height of dialog window.

And just bear in mind that the x, y position is anchored to the top left corner of the central frame of the window, not the corner of the window itself (see image):

*interestingly, it seems the exception to this is if you use a 0, 0 position which, on my Windows laptop at least, results in the dialog window locking perfectly in to the corner of the screen; while a 5, 5 position cuts off the window title bar.

enter image description here

As for changing the name, if you just want to change the title of the plugin dialog window (circled in yellow in your screenshot) you should get away with just adding another line to the initGui() method:

self.dlg.setWindowTitle('Window Title You Want')

However if you want to change the name of the entire plugin everywhere including in the plugin manger etc. that would be a lot more tedious. If you used Plugin Builder, the generated files use the name you entered as your plugin name and this name is referenced throughout the plugin e.g. in the metadata, in the plugin dialog file to load the ui, in the main plugin file to import the dialog class, to add the plugin to menus and icons to toolbars etc. etc.

I suppose you could technically replace all references to the old name with the new, but this would be quite time consuming and prone to error and could cause the plugin not to load properly. In that case, it might be quicker and easier to run Plugin Builder again and generate all the necessary files with the new name and copy the code containing your 'plugin logic' from one to the other. If you spent a lot of time modifying the ui file in Designer, you could probably re-use that by renaming it and copying into the plugin folder.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.