Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exchange Qt code file with a file from Qt Designer #175

Open
lazigu opened this issue Feb 15, 2023 · 6 comments
Open

Exchange Qt code file with a file from Qt Designer #175

lazigu opened this issue Feb 15, 2023 · 6 comments
Labels
enhancement New feature or request

Comments

@lazigu
Copy link
Collaborator

lazigu commented Feb 15, 2023

https://doc.qt.io/qt-6/qtdesigner-manual.html

@lazigu lazigu added the enhancement New feature or request label Feb 15, 2023
@haesleinhuepf
Copy link
Member

haesleinhuepf commented Feb 17, 2023

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.

@lazigu
Copy link
Collaborator Author

lazigu commented Feb 17, 2023

@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 :)

@jo-mueller
Copy link
Collaborator

You can do it the same way you already do it (e.g., here where a magicgui widget is created which is later added to the bigger widget here . It would work analogously if you used the designer.

@haesleinhuepf
Copy link
Member

But how can I include a magicgui-based pulldown into a user-interface that comes from a .ui file?

@jo-mueller
Copy link
Collaborator

jo-mueller commented Feb 19, 2023

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.

@haesleinhuepf
Copy link
Member

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? 🙃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants