Open lazigu opened 1 year ago
Before working on this, it would be good to understand better how magicgui and qt can be combined. E.g. designing a pulldown with all image layers that are open in Napari might be tricky with the Qt designer, however it's a one-liner using magicgui.
@haesleinhuepf, I think @jo-mueller combined Designer with magicgui in napari-stress, it is possible to "reserve" some space for magicgui widgets that are added then later if I got the explanation right :)
But how can I include a magicgui-based pulldown into a user-interface that comes from a .ui file?
I do it here, for instance. The general code base doesn't change that much and follows the following pattern:
class my_widget(QWidget):
def __init__(self, napari_viewer):
super().__init__()
self.viewer = napari_viewer
uic.loadUi(os.path.join(Path(__file__).parent, './toolbox.ui'), self) # this loads the ui file
# this adds a magicgui widget to the widget
self.image_layer_select = create_widget(annotation=Image, label="Image_layer")
self.layout().addWidget(self.image_layer_select.native, 0, 1)
In principle, the loadUi
function just wraps up all the widget creation stuff (adding buttons, texts, size policies, tooltips, default values, etc) - connecting them to actual functionality still needs to be done inside the __init__
of the widget definition.
The only thing to be kept in mind is to leave a blank space in the designer (i.e. an empty widget) where the magicgui should later go.
The only thing to be kept in mind is to leave a blank space in the designer (i.e. an empty widget) where the magicgui should later go.
That's the interesting part! How can I replace an empty widget, that was created using the designer, with a magicgui generated widget? I imagine it's hard to replace a widget in the middle of other widgets surrounded by buttons and tabs with a custom widget and make sure the magicgui functionality still works. Do you think it makes sense to demonstrate this in a short blog post? 🙃
https://doc.qt.io/qt-6/qtdesigner-manual.html