How to detect, in a QWidget, closing the main window - python-3.x

I know that similar question was already answered, but my case is a little bit different
Case:
I have a QWidget which contains a QLineEdit and a QListWidget
The QListWidget is a FramelessWindow which means that it is not located in the main window but it appears independently (actually it is a dynamically changing list depending on the content of the QLineEdit filed: "filter as you type")
Problems:
When I close the main window, it will not close the QListWidget automatically. After the main window closed, the QListWidget will be still seen. - I could not find event, in the QWidget, which would work for that purpose. The closeEvent(self, event) is never triggered.
When I move the main window the QListWidget will be still stay in the original position. It will not follow the QLineEdit's position. I could not find event, in the QWidget, which would work for that purpose.
Conditions:
I do not want to detect the changes in the main window. I know that the
closeEvent(self, event)
works in the main window, and I could delegate it to the QListWidget.
BUT I want to write an independent widget, which does not depend on the setting in the main window.
Can somebody help me with telling/suggesting how to detect the window close/window move inside a widget?
If you need the code (pretty long ~300 lines), I can copy it here.

Related

How to propagate the parent's click event in Pyside2 as if I have clicked the button directly while hovering over it?

How to propagate the parent's click event in Pyside2 as if I have clicked the button directly while hovering over it?
This is a very peculiar problem, and I haven't been able to find even a question like this.
A button is positioned on the main UI window. When clicked, it hides the parent window, and spawns another window at that position. I need it to work with a single click, for example, I want to press the button, and not release the mouse immediately, but hover over a certain part of the newly spawned window and then release it.
This works perfectly fine if I click the button directly , but the problem is I need to click the button from the main UI window.
I am doing it by sending "mousePressEvent" from the main UI window to the child widget's "mousePressEvent", like this:
def mousePressEvent(self, event): #parent mouse press event
#----
#----
self.FocusedButton.mousePressEvent(event) # child widget
When I activate the button from the mainUI window, the window is immediately hidden and the new window is spawned. However, since I haven't performed mouse release yet, I am stuck into the parent's mouse press event loop. The mouse doesn't invoke paint event and doesn't register mouseMoveEvent until I release the click because the mainUI window is hidden and mouse tracking doesn't work any more.
I have tried setting the flags of the window in every way, (QtCore.Qt.WA_TransparentForMouseEvents,True ) for example, but none of it worked.
The main UI window inherits from "QtWidgets.QWidget" and does not have the clicked method.

pyqt5 permanent widget focus

in my pyqt5 application, I have a QLineEdit that can have its value changed by both typing and pressing buttons that have advanced actions on the QLineEdit's text.
I have done some research and found the setFocusPolicy, but it does not have a permanent focus option, is there a way around this?
edit: by "permanent focus" I mean that the QLineEdit is always in a focus state where one can type into it, but clicking somewhere else or tabbing does not change the focus to a different widget
musicamante had it right, what I did was add a corresponding *widgetObject*.setFocusPolicy(Qt.NoFocus) line for each of my widgets that could possibly focus
note: I had this import line specifically for the NoFocus constant
from PyQt5.QtCore import Qt

Updating QListWidget and QtreeWidget in a QMainWindow PyQt

I have a QMainWindow that creates a QListWidget and a QTreeViewWidget and places them in a QDockWidget. I then have an "open" action in the menu bar. When clicked it gives a dialog were you choose a pickle file to load. Upon opening i need the information to be loaded into the QTreeView and QListWidget in the QMainWindow. However, since the widgets were already instantiated upon opening the program they don't update. Everything works fine if i choose a file before the program actually starts. Everything also works if i close and reopen the widgets after i choose my file. So, is there some way to update the QMainWindow to show the updated information after opening a new file?

Is there an 'Onload' sort of a signal for QMainWindow?

PyQt noob here.
I need to call a dialog window as soon as the main window is loaded.
I also need the main window to be displayed in the background when this dialog is shown on top of it.
So, I'm looking for a 'onload' sort of a signal for the main window to call the function which in turn calls the dialog. Is there any other way around?
You can override the QWidget.showEvent for your QMainWindow to achieve the same effect. However, you need to keep track of whether it is the first time the window is shown or not since that method will be called every time the window is displayed after being hidden. Then use a modal QDialog so that the main window is shown in the background, but not enabled.

Resizing a Qt main window when a contained widget changes its size

In PyQt4, I have a main window which sets as its central (and only) widget a custom widget I created. Through user action, the widget can change its size. When this happens, I want the main window that contains the widget to adjust its size so that it conforms to the new size of its child widget. Unfortunately, this isn't happening. The new widget is created but it is forced to adapt to the main window's previous size. I have over-ridden the sizeHint method for the widget so that it returns the desired size but this appears to be ignored. I've also added a call to updateGeometry for both the widget and the main window but this has no affect either.
I'm pretty sure I'm close to getting this to work but I'm not terribly experienced in Qt's nuances. Can someone give me some guidance here?

Resources