2

I have a plugin with QDockWidget and QActions. When I first load (or reload) the plugin, the actions' size is set according to current settings.

However, when QGIS is closed and open, the actions are smaller. The size of my actions is "one step behind" QGIS settings unless the smallest icon size is set.

Here is a part of my code where dock widget is initialized and showed/hidden.

def initGui(self):
    self.dockWidget = dockwidget.DockWidget(self.iface)
    self.iface.addDockWidget(Qt.TopDockWidgetArea, self.dockWidget)

def unload(self):
    self.iface.removeDockWidget(self.dockWidget)

def run(self):
    if not self.dockWidget.isVisible():
        self.dockWidget.show()
    else:
        self.dockWidget.hide()

Is there a way to keep the actions' size according to QGIS settings?

The only idea I came up with is to keep track of the dock widget's current area and initialize the dock widget every time QGIS starts but that is not satisfying.

2
  • What do you mean by "actions' size"?
    – DIV
    Commented Dec 26, 2016 at 10:55
  • By actions' size I mean icon size of actions.
    – svoboond
    Commented Dec 27, 2016 at 19:30

1 Answer 1

1

I solved it by creating a function that sets icon size of actions according to QGIS settings and connecting that function to initializationCompleted signal of QgsInterface.

Something like this:

self.iface.initializationCompleted.connect(self._set_icon_size)

def _set_icon_size(self):
    self.setIconSize(self.iface.mainWindow().iconSize())

During QGIS initialization the actions are smaller but when the initialization is completed the size is set properly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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