0

I'm working on creating python plugin that implements image viewer and use layout to plased elements in correct plases. I want to resize all elements in dialog window of this plugin using resizeEvent of QDialog, but I have one strange problem: when I want to make dialog window smaller - all works good like on image1, but, if I want to make window bigger I have seen a problem like on image2:

Image1 Image2

Here is my resizeEvent method for my dialog:

def resizeEvent(self, a0: QResizeEvent):
    geom = list(self.geometry().getCoords())
    x_shift = geom[2] - geom[0] #transform x coord from monitor coords to dialog window coords
    y_shift = geom[3] - geom[1] #transform y coord from monitor coords to dialog window coords
    self.verticalLayout.setGeometry(QRect(0, 0, x_shift, y_shift))

And here is my code how I connect my ui with python code using uic:

import os

from qgis.PyQt import uic
from qgis.PyQt import QtWidgets

FORM_CLASS, _ = uic.loadUiType(os.path.join(
    os.path.dirname(__file__), 'name_of_ui'))
class nameDialog(QtWidgets.QDialog, FORM_CLASS):
def __init__(self, parent=None):
    super(status_checkerDialog, self).__init__(parent)
    self.setupUi(self)

In this script, I create the resize function. Also, I would like to add that I use to build the skeleton of the module named Plugin Builder. Maybe this information will help you point out exactly where I am making a mistake. I also add the code skeleton that implements all functions of the module:

class status_checker:

    def __init__(self, iface):
        "Constructor"
    def add_action(
        self,
        icon_path,
        text,
        callback,
        enabled_flag=True,
        add_to_menu=True,
        add_to_toolbar=True,
        status_tip=None,
        whats_this=None,
        parent=None):
        """Add a toolbar icon to the toolbar"""
    def initGui(self):
        """Create the menu entries and toolbar icons inside the QGIS GUI"""
    def unload(self):
        """Removes the plugin menu item and icon from QGIS GUI."""
    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.first_start is a variable that is created in the initialization function and initially set to true
            self.dlg = status_checkerDialog()
Danylo
  • 1
  • 2
  • Why are you manually setting the geometry of the layout? – musicamante Jul 26 '22 at 09:05
  • I manually setting the geometry because I use external dialog ui and add it to the code with qgis.PyQt.uic.loadUiType – Danylo Jul 27 '22 at 10:53
  • That is irrelevant, using a ui loaded with uic doesn't require to do that, so you're doing something wrong, and I suggest you to [edit] your question to provide a [mre] of how you're creating the class and loading its ui. – musicamante Jul 27 '22 at 14:03

0 Answers0