Python Forum
[PyQt] Seeking guidance on PyQt Instantiation and correct way to use an instance of QWidget
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyQt] Seeking guidance on PyQt Instantiation and correct way to use an instance of QWidget
#3
Broo, that was awesome! Thank you for such a detailed response. Finally getting some answers!

That was a really cool idea using that click button to visually show me that it's the exact same object we are referencing.

I ran your code and this has helped me learn so much! I did not know about the __call__ method and if I understand correctly, even if I initialize class scope attributes in this instance with value A for example, then change it later in the code to value B, when I quit this instance and call it again, that attribute still reads value B.

I was not expecting this at all which is why I'm glad I caught it before writing this implementation in my project.

Where would you recommend resetting my attributes to ensure they are always correctly initialized with their default values? or is there another trick I can do to kind of reset the instance to it's original state?

Quote:Is it OK to reuse this instance after it's been quit out of using QApplication.quit() like this?
I can think of no reasons to do this, but that doesn't mean they don't exist. Qt doesn't seem to mind.?

The project I am building will be using a QApplication QWidget class to draw some overlays to my screen. This will be called multiple times through out the program I write but there may be times where I don't need any overlays drawn for a few minutes.

So my natural instinct was to close that instance since it's not needed during that downtime, but perhaps it's a better idea just to leave it open the whole time? I'm always after minimizing the memory I am occupying where possible but still have a very small understanding of memory.

I also had someone explain to me that due to the nature of how QWidget works, there is no need to implement a singleton method because only one instance of QWidget can exist at a time?


To reiterate, my response questions are:

1. Where would you recommend resetting my attributes to ensure they are always correctly initialized with their default values? or is there another trick I can do to kind of reset the instance to it's original state when it's recalled?

2. Is it better just to leave it open while it's not required? or to close it and reopen it as I need it?

3. Do you think any of this is necessary if my class inherits QWidget?

Thanks again for putting in that time to even write examples of your answer, I've spent a couple days trying to figure this out across multiple sources and you are the first person to give me some useful information back, really made my day <3
Reply


Messages In This Thread
RE: Seeking guidance on PyQt Instantiation and correct way to use an instance of QWidget - by BrewBarred - Jan-22-2024, 10:05 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Video [PyQt] Get a executable file (.exe) from a .py file add a promoted class in a QWidget MiguelonReyes 0 833 Oct-17-2023, 11:43 PM
Last Post: MiguelonReyes
  Upload file data on Qwidget maiya 4 1,638 Jul-08-2022, 08:34 AM
Last Post: Axel_Erfurt
  Made new instance - button still goes to old instance nanok66 6 3,178 Nov-06-2020, 07:44 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020