When I convert a .ui file in QtDesigner to a .py file, the format changes and it runs differently.
When I run it in QtDesigner it looks like a normal page but once I convert it to a .py file and run it, the edges are cut off and I cannot see half the buttons/labels. Even once I expand the screen that has opened the labels are cut off and only half visible.
Is there a way I can stop this from happening?
You firstly need to correctly set the layout and widgets inside them, in a way that the size of each object is guaranteed when moving to the code.
Try to watch this tutorial, I found it very useful!
Qt Designer - create application GUI (DESIGN APPLICATION LAYOUT) - part 02
And then you need to just import the .ui file as follows:
from PyQt5 import uic
class MainWindow(QMainWindow):
def __init__(self):
super(MainWindow,self).__init__()
uic.loadUi("NameofYourFile.ui",self)
self.show()
Related
I am using Qt Designer for creating GUI files all work well for me in Qt Designer GUI window but if I run the generated file in Python it the text context is cut short, I need to know why this is happening?
This image is the preview feature of Qt Designer:
This image is the output of the python file generated when the QtDesigner was converted to a python file and executed.:
I suppose you are new in PyQt5.Sooner or later you will understand that whenever you create something in Qt designer like a button or a label,this item will be completely static.That means that whatever you create will be 'stuck' there with the absolute coordinates you defined and absolutelly zero interactivity.Here comes layers and minimum-maximum sizes of widgets.You can apparently just drag more your labels width manually from Qt Designer but this approach will not get you very far.Because this topic is rather big ,i will suggest playing more with Qt Designer and the inputs you can provide on the right tab ,and watch some tutorial about PyQt5 like this:https://www.youtube.com/watch?v=FVpho_UiDAY&ab_channel=TechWithTim
I need to be load QMovie in QtDesigner. I noticed that a lot of classes are not accessible from QtDesigner. I usually design in QtDesigner and I just load the ui file directly in my code. This way I never had to worry about implementing the GUI itself in code.
Is there a way I can do this without having to edit my code ?
So in summation I want to add QMovie to a horizontal layout in my main window.
QMovie is not a widget, so it makes no sense to add it to as layout.
You probably want a QLabel, which has a setMovie method for dispalying animated images. But note that a QMovie cannot play videos - if you want that functionality, you will have to use a Phonon.VideoWidget, rather than a QLabel.
A while back I made a project using PyQt. I created some .ui files and generated the corresponding .py files using pyuic4. I want to start work on it again, but I have lost the .ui files (I formatted my PC and took a backup, but the .ui files were residing in the Qt designer folder and got lost).
Is there any way I can restore those .ui files from the .py files generated?
It is possible to do this using QFormBuilder:
from PyQt4 import QtCore, QtGui, QtDesigner
from myui import Ui_Dialog
def dump_ui(widget, path):
builder = QtDesigner.QFormBuilder()
stream = QtCore.QFile(path)
stream.open(QtCore.QIODevice.WriteOnly)
builder.save(stream, widget)
stream.close()
app = QtGui.QApplication([''])
dialog = QtGui.QDialog()
Ui_Dialog().setupUi(dialog)
dialog.show()
dump_ui(dialog, 'myui.ui')
(NB: showing the window seems to be quite important in order to get the best results).
Don't expect to get a perfect reconstruction of your original ui file, though. You will almost certainly need to do quite a lot of tidying up to get something acceptable - but if your ui is quite complex, it should still be worth it.
I've used PyQt for quite a while, and the entire time I've used it, there has been a pretty consistent programming pattern.
Use Qt Designer to create a .ui file.
Create a python class of the same type as the widget you created in the .ui file.
When initializing the python class, use uic to dynamically load the .ui file onto the class.
Is there any way to do something similar in PySide? I've read through the documentation and examples and the closest thing I could find was a calculator example that pre-rendered the .ui file out to python code, which is the super old way of doing it in PyQt (why bake it to python when you can just parse the ui?)
I'm doing exactly that with PySide. :)
You use this https://gist.github.com/cpbotha/1b42a20c8f3eb9bb7cb8 (original by Sebastian Wiesner was at https://github.com/lunaryorn/snippets/blob/master/qt4/designer/pyside_dynamic.py but has disappeared) - which overrides PySide.QtUiTools.QUiLoader and supplies a new loadUi() method so that you can do this:
class MyMainWindow(QMainWindow):
def __init__(self, parent=None):
QMainWindow.__init__(self, parent)
loadUi('mainwindow.ui', self)
When you instantiate MyMainWindow, it will have the UI that you designed with the Qt Designer.
If you also need to use custom widgets ("Promote To" in Qt Designer), see this answer: https://stackoverflow.com/a/14877624/532513
I created a main app with a mdiArea for loading map graphics with Qt Designer *.ui and coded with pyQt4 using uic.loadUi() in python.
I also created a separate *.ui file and tested the dockWidget successfully in a separate python script file.
I wish to combine these 2 UI so that the main_app window will have the mdiArea widget on the left, while the dockWidget as the info_panel on the right.
I tried to load the *.ui file in the main app python, but ended up the dockWidget as a separate window when show().
Any advice to resolve this?
I hope I need not have to use Qt Designer to combine the mdiArea main_app UI with the dockWidget info_panel and load them as a single UI. ;P
Thanks in advance.
I've worked on some software where every different pane is done as a separate. Ui file, so that they can be changed independently without requiring merges. It worked fine. Can you turn the map and dock parts into widgets, and then make a new "main window" ui, and then give that a layout and add the other two as child widgets to it?