From .ui to .py : pyside-uic not working - python

I cannot convert my .ui file from Qt Designer to a .py file with the PySide scritp : pyside-uic.exe
I get this error :
Someone can help me ?

OK, I have the answer now, I was using both PyQT4 and Pyside as librairies for my interface. The problem is that some librairies are not compatible with both librairies (like PyQwt). So, it's really important to choose weather you use PyQt or Pyside for your interface.

Related

Can't get custom PyQt5 widget plugin to show up in Qt designer (macos)

I would like to make a custom widget plugin for Qt Designer using python (3.7 with pyqt5). Everything should work, but it doesn't show up in Qt Designer.
Here is what I have done so far after much trial and error and a little help from others with similar issues (Qt Designer: could not find custom PyQt widget plugins and Custom QWidgets. How do I build/get the pyqt5 plugin for Qt Designer on Mac?)
I installed Qt Designer (Creator) 5.13 from the Qt website.
I installed SIP (4.9.18) and PyQt5 (5.13.0) from source rather than pip because it was necessary to get the libpyqt5.dylib file that is necessary (no pyqt5-tools for mac). I put this file in the /Users/[user]/Qt/5.13.0/clang_64/plugins/designer directory
I just want to get the setup correct before making my own plugin. So, I downloaded analogclock.py and analogclockplugin.py from https://github.com/baoboa/pyqt5/tree/master/examples/designer/plugins and modified the plugins.py file like this:
from PyQt5.QtCore import QLibraryInfo, QProcess, QProcessEnvironment
# Tell Qt Designer where it can find the directory containing the plugins and
# Python where it can find the widgets.
env = QProcessEnvironment.systemEnvironment()
env.insert('PYQTDESIGNERPATH', '[path to the plugin.py files]/designer_plugins')
env.insert('PYTHONPATH', '[path to the widgets]/designer_widgets')
# Start Designer.
designer = QProcess()
designer.setProcessEnvironment(env)
designer_bin = QLibraryInfo.location(QLibraryInfo.BinariesPath)
designer_bin = '/Users/[user]/Qt/5.13.0/clang_64/bin/Designer.app/Contents/MacOS/Designer'
designer.start(designer_bin)
designer.waitForFinished(-1)
I ran plugins.py. Qt Designer opens correctly, and when I checked the Designer-->About Plugins I see libpyqt5.dylib inside Loaded Plugins. However, the PyAnalogClock widget was not inside of it and the plugin widget was not in the left-side widget box.
I tried to debug by setting environmental variables from the terminal like this:
[user]$ export QT_DEBUG_PLUGINS=1
[user]$ export PYQTDESIGNERPATH='[path to the widgets]/designer_widgets'
[user]$ export PYTHONPATH='[path to the widgets]/designer_widgets'
[user]$ /Users/[user]/Qt/5.13.0/clang_64/bin/Designer.app/Contents/MacOS/Designer
The relevant portion of the output was this:
Found metadata in lib /Users/[user]/Qt/5.13.0/clang_64/plugins/designer/libpyqt5.dylib, metadata=
{
"IID": "org.qt-project.Qt.QDesignerCustomWidgetCollectionInterface",
"archreq": 0,
"className": "PyCustomWidgets",
"debug": false,
"version": 331008
}
loaded library "/Users/[user]/Qt/5.13.0/clang_64/plugins/designer/libpyqt5.dylib"
and toward the end
loaded library "Python.framework/Versions/3.7/Python"
ModuleNotFoundError: No module named 'PyQt5'
ModuleNotFoundError: No module named 'PyQt5'
When I did not export PYQTDESIGNERPATH and PYTHONPATH from the command line, this error disappeared. But of course, then Qt doesn't know where the files are.
In any case, that is my current state. I do not understand why the PyQt5 module cannot be found by Qt Designer or what else I can try to get this to work.
here is an 🤦‍♂️ momemt
So, I found this on the PyQt reference guide which I had somehow overlooked
For a simple but complete and fully documented example of a custom widget that defines new Qt signals, slots and properties, and its plugin, look in the examples/designer/plugins directory of the PyQt5 source package
ok. did that. ran the demo. it works fine. Copied the whole plugins directory somewhere else. still fine. So I must have done something funky naming the folders or something. anyway, now I will just work on making my own plugin. days of frustration because of being dumb. but happy it works.

PyQt5 FileDialog: Show network folders

My system is as follows: python 3.6.0 with PyQt 5.8.1 installed in an anaconda environment on ubuntu 16.10.
I want to show/select network folders (connected via samba) with the PyQt5 FileDialog, but am unable to do so.
In PyQt4 (another environment) it works.
relevant code:
from PyQt5 import QtWidgets
fileDialog=QtWidgets.QFileDialog()
workDirectory = str(fileDialog.getExistingDirectory(caption= "Set Work Directory", directory=defaultWorkDirectory))
fileDialog.deleteLater()
The PyQt5 documentation just leads to the C++ one and there is this about network/local files: "Note: The non-native QFileDialog supports only local files." and "When possible, this static function will use the native file dialog and not a QFileDialog. On platforms which don't support selecting remote files, Qt will allow to select only local files."
I thought, ubuntu supports this (just like in PyQt4).
Is there a way to do this or do i have to settle with PyQt4?
Thanks,
Topsrek
This happens because the gtk3 file dialog hides non-local files by default. (this has to be explicitly enabled in the Qt gtk3 platform implementation, bugreport)
Qt4 doesn’t have gtk3 support so you get a gtk2 file dialog which doesn’t do this.
I didn’t find a way to get Qt5 to use the gtk2 dialog and as you found out yourself the non-native dialog doesn’t support network locations either.
As a workaround you can navigate to already mounted locations in /run/user/(your username)/gvfs/*.
As ugly as this may seem, I suggest using this instead of going back to PyQt4.
In case anyone wants to modify this behavior in Qt5, here is one solution. In qtbase/src/plugins/platformthemes/gtk3/qgtk3dialoghelpers.cpp, change the parameter of gtk_file_chooser_set_local_only:
void QGtk3FileDialogHelper::applyOptions()
{
GtkDialog *gtkDialog = d->gtkDialog();
const QSharedPointer<QFileDialogOptions> &opts = options();
gtk_window_set_title(GTK_WINDOW(gtkDialog), qUtf8Printable(opts->windowTitle()));
//gtk_file_chooser_set_local_only(GTK_FILE_CHOOSER(gtkDialog), true);
gtk_file_chooser_set_local_only(GTK_FILE_CHOOSER(gtkDialog), false);
//...
}
Now the GTK 3 file dialog can show the mounted shares. See gtk-file-chooser-set-local-only.

How to convert .ui to py in windows ?

I followed this link to convert .ui to .py using python in windows but its not working.I tried installing pyuic4 but its not working. Is there any tools or libraries in python for doing it? Please suggest .
why not just import it?
import sys
from PyQt4 import QtGui, uic
app = QtGui.QApplication(sys.argv)
widget = uic.loadUi('demo.ui')
widget.show()
sys.exit(app.exec_())
ps: sorry i cant answer in comment section. my reputation too low
have an application created to convert the .ui (Pyqt5 Created by qt designer) file to py ( you can use for windows it will work perfectly)
you can convert your file easily using this application,
Direct Download Link: https://download1653.mediafire.com/utmxc4pza7ug/1f0gkwk6577g7fi/Ui+to+Py.zip
Mediafire link to download: https://www.mediafire.com/file/1f0gkwk6577g7fi/Ui_to_Py.zip/file
you check the source code of the application on my GitHub: https://github.com/Harvindar994/
tags: python, pyqt5, qt designer

python 2.7 under windows: cannot import ui_mainwindow

I have python 2.7 under windows x64, I have been trying to make a simple GUI using PyQt4, like this:
from PyQt4 import *
from ui_mainwindow import Ui_MainWindow
class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
when I run the program I have this error: " No module named ui_mainWindow"
-I have pyqt4 installed
- I have tried to replace um_mainwindow with ui_simple and clientGUI but the same error resulted.
What am I doing wrong and how to fix this?
thank you
As far as I know, ui_mainWindow is a python file generated by some Qt Tool, that transforms .ui file from QtDesigner to Python class.
I have no real experience with PyQT, but I know both C++/Qt and python. In C++/Qt QtCreator does the job of transforming .ui file to C++ class, but probably in python You need to do this Yourself.

Library not loaded: QtCore.framework/Versions/4/QtCore

I was trying to do gui programming in Python.I figured out that PySide is a good framework to start with.As i was running Python 2.7.2 i downloaded PySide 2.7 and tried running a sample app.I got QtCore Library not loaded error.
This is the error that i got..
from PySide import QtCore, QtGui
ImportError: dlopen(/Library/Python/2.7/site-packages/PySide/QtCore.so, 2):
Library not loaded: QtCore.framework/Versions/4/QtCore
Referenced from: /Library/Python/2.7/site-packages/PySide/QtCore.so
Reason: image not found
I googled and found out that many people were facing the same issue and i saw solutions being posted based on exporting DYLD_FRAMEWORK_PATH. I was not able to follow this.
Could anyone please tell me whats the issue and how to fix it!!
Thanks..
You don't mention the OS you are working on, but from the paths in your error message it looks like you're on Mac OSX.
I'm not an expert in PySide at all, but I had the same problem a while ago and I think I know what's going on: The library at /Library/Python/2.7/site-packages/PySide/QtCore.so is the part that makes the Qt Core C++ library available to Python. It is just the wrapper though or some sort of translator between C++ and Python, the actual C++ functionality is elsewhere - and when the Python interpreter tries to load the C++ library that contains that functionality from QtCore.framework/Versions/4/QtCore, if fails to find it, hence the error message.
A quick and dirty way to solve your problem is to create symbolic links from the location where QtCore.so expects the C++ library to where it actually is. For that, you will obviously have to find the C++ library. If you downloaded Qt 4.8.4 as an installer from the Qt Project page, the libraries AFAIK are somewhere in /usr/lib, so you would create a symlink like this:
ln -vis /usr/lib/<insert subfolder>/QtCore.framework /Library/Python/2.7/site-packages/PySide/QtCore.framework
You will have to do this in a similar way for QtGui and any other Qt library you want to use as well. Note that this obviously does not symlink the library itself, but the folder in which QtCore.so expects it.
An alternate way would be to build PySide from the sources (which is what I ended up doing), but that takes longer - and you sound like you just want to get going with Python and Qt.
Have you installed standalone QT package for mac?
Qt for Mac OS X: Download Qt 4.7.4 ftp://ftp.qt-project.org/qt/source/qt-mac-opensource-4.7.4.dmg standalone pyside installation raises same error log for me

Categories