Casting a QDialog to QWidget - pyqt4

I lost my .ui file, and it seems pyuic4 cannot make a .ui file out of a .py file, only the other way around.
I have a QDialog, and I am now instead going to put its content inside a tab-pane. For that I need a widget, not a "stand-alone" dialog.
How can I cast QDialog to QWidget, or is there any other workaround other than doing the whole design over again.
Thanks

If I understand you correctly, you have a custom class that drives from QDialog, but you would now like to use it inside a tab pane rather than standalone.
For that the simplest path is to change your class to inherit from QWidget directly rather than QDialog. There should be little to no code change in that class (except for the obvious stuff in the constructor).
(I have no idea what your .ui problem has to do with this though.)
Also, QDialog inherits from QWidget. No type-casting necessary to use a QDialog when a QWidget is expected.

Related

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

How to detect, in a QWidget, closing the main window

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.

Adding image to PyQT without QRC file

I used Designer to create the layout for my gui. I need to be able to have QLabel that is part of the main GUI cycle through a couple of different, newly-created images while the GUI is running. There must be a way to do this, right? Whenever I look up how to do that, I only find ways to add an image to Designer, then pyrrc the qrc file, and you know the drill. But there must be a way to add an image while avoiding all that.. right?
There is, actually. Find the label you want. Let us say the label is label_1. Then, in your MainDialog class (or wherever), use QPixmap like this:
self.label_1.setPixmap(QPixmap("img.jpg"))
That should work. Good luck!

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?

slightly customized widget for PyQt4 with qtdesigner

I am creating an application with PyQt4 and I want to use qtDesigner to design the layout. The application contains a QGraphicView, for which I want to implement panning and zomming per mouse. The only way I know how to do that is deriving from QGraphicView overwriting the "mouse*" functions to do the panning and zooming.
Now I want to use this new custom widget with qtdesigner.
googling I find that I could write a "custom widget plugin" for qtdesigner. While it does not seem to be to difficult, I still find it overkill for such a little adjustment I want to make.
What other ways are there to customize a widget in PyQt4 when the layout is done with qdesigner?
Thanks!
You can promote your QGraphicsView to your own subclass
In the designer, right click on the QGraphicsView and select "Promote To" and fill the dialog with relevant information about your own subclass:

Resources