Closed Tanza3D closed 1 year ago
Components are designed with the assumption that re-drawing the preview happens after some "tracked value" (usually the content of a widget) changes.
Normally the component's update
method does cause the preview to re-render, but it will only do so if the output of the component's savePreset
method changes... this is a dictionary of tracked values.
The simplest way to get the preview to re-render, is to put the image URL into a Qwidget (could be an invisible one). Use the trackWidgets
method as described in step 3 of component creation.
Something like
def widget(self, *args):
super().widget(*args)
self.page.pushButton_GetNew.clicked.connect(self.getNewImage)
self.trackWidgets({
'imagePath': self.page.label_imagePath,
'tags': self.page.lineEdit_tags,
})
Then this component would have the properties imagePath
and tags
.
The getNewImage
method can get the value of self.tags
and ask Unsplash for an image path, then set the value of the tracked Qwidget (self.page.label_imagePath
in my hypothetical) which will automatically set the value of self.imagePath
and trigger the preview to re-render. And this should make the component work with the project system and undo system, I think.
Thanks for your interest in the program and don't hesitate to ask more questions! I'll try to respond a bit sooner next time :)
ah, that worked! alright, thanks for letting me know how it works, and i'll be sure to reach out if i have any more questions! thanks for the help!
Hello! I'm working on some custom components and I was wondering if there was a way I could request a re-render of the preview? We've got a component which allows the user to select a random image, but every time they have to mess around a bit to actually see which image they get. Is there any way I could request a render from a component?
https://github.com/djfun/audio-visualizer-python/assets/33783503/89e31859-0c04-428d-ba09-50b91db93d9f