Qt Designer: could not find custom PyQt widget plugins - python

I wrote a lot of custom widget plug-ins for using them in the Qt Designer and my Pipeline.
This is working fine on my Mac (Mavericks, PyQt4, Python 2.7), and this week I wanted to implement those plugins on my Windows environment as well. But it wasn't working. The plug-ins are not appear in the Qt Designer's Widget Box on the left (Windows 7, PyQt4, Python 2.7).
After a lot of try's, I downloaded the PyQt4 example files and followed the instructions from: PyQt Reference Guide and also the instructions
from the example launcher file examples/designer/plugins/plugins.py itself, but it was still not working.
So I copied the the following example files:
plugin files to "C:\designer_plugins"
widget files to "C:\designer_widgets"
Just to making the code as simple as possible to figure out what is going wrong.
So, this is my testing plugins.py file:
#!/usr/bin/env python
import sys
import os
from PyQt4 import QtCore, QtGui, uic
env = os.environ.copy()
env['PYTHONPATH'] = r"C:\designer_widgets" #("%s"%os.pathsep).join(sys.path)
env['PYQTDESIGNERPATH'] = r"C:\designer_plugins"
qenv = ['%s="%s"' % (name, value) for name, value in env.items()]
# Start Designer.
designer = QtCore.QProcess()
designer.setEnvironment(qenv)
designer_bin = r"C:\Python27x64\Lib\site-packages\PyQt4\designer.exe"
designer.start(designer_bin)
designer.waitForFinished(-1)
sys.exit(designer.exitCode())
I thought that my designer object didn't get the right path, so I implemented the folowing to check it's environment:
# Check if paths are right
print "\n # Designer Env:"
for pypath in designer.environment():
if "PYTHONPATH" in pypath:
print " # ",pypath
if "PYQTDESIGNERPATH" in pypath:
print " # ",pypath
Console output:
# Designer Env:
# PYQTDESIGNERPATH="C:\designer_plug"
# PYTHONPATH="C:\designer_widgets"
The paths are right. And like I said, on my mac it works perfectly.
I was trying this also with different Qt Designer installations. But both (PyQt4 and PySide) designers doesn't show any of the example plugins. Both Qt Designer couldn't find the example plugins. I double checked it inside the designer with Help/About Plugins).
Any ideas what I did wrong? Or is this generally not working on a Windows 7 System?

All fixed. I rebuild PyQt4, so I think I made probably a mistake in the source code of Qt in the past.

Related

QtDesigner Pyqt / Pyside disable translatable by default

is it possible to set the translataable checkbox for everything inside the qtdesigner to disabled as default. I only need one language and much prefer the cleaner auto generated code, leaving the retranslateUI funtion empty and setting everything up in the constructor.
Setting the checkbox for everything to disabled is super annoying.
Qt designer does not allow to do it, that is the default configuration that plugins have, so I will propose a workaround, modify the .ui with a small script to disable that property:
from PyQt4 import QtCore, QtXml
if __name__ == '__main__':
filename = "/path/of/your_file.ui"
file = QtCore.QFile(filename)
if not file.open(QtCore.QFile.ReadOnly):
sys.exit(-1)
doc = QtXml.QDomDocument()
if not doc.setContent(file):
sys.exit(-1)
file.close()
strings = doc.elementsByTagName("string")
for i in range(strings.count()):
strings.item(i).toElement().setAttribute("notr", "true")
if not file.open(QtCore.QFile.Truncate|QtCore.QFile.WriteOnly):
sys.exit(-1)
xml = doc.toByteArray()
file.write(xml)
file.close()
Note:
The script is compatible with PyQt4, PyQt5, PySide and PySide2, they should only change PyQt4 with the name of the other libraries.

PyQt QtCharts Designer plugin

I have tried the procedure (Qt Charts and Data Visualization widgets) to integrate the qtchart plugin.
But it don't work. Makeing the plugin and add it to the desinger folder worked. qt designer ‎recognize the plugin but compiling the ui to a python file I get following error:
Unknown Qt widget: QtCharts.QChartView
I'm using linux with qt 5.7 and qtcharts and also pyqtcharts.
I thing the problem is the 's' at the end of QtCharts, but I have no idea how I can fix it.
Hope someone has a idea.
You don't have to integrate it.
Add a normal Widget in qt-designer, then right click it, and select Promote to ....
In the window that opens, write QChartView for the Promoted class name:, and PyQt5.QtChart for the Header file:. Press Add. It will be added to the list of Promoted Classes. Select it from the list, and press Promote. That's it.
Then in your python code, you can write something like this:
from PyQt5.QtChart import QChart, QLineSeries
...
chart = QChart()
series = QLineSeries()
series.append(1,3)
series.append(2,4)
chart.addSeries(series)
chart.setTitle('Example')
chart.createDefaultAxes()
self.ui.widget.setChart(chart) # this is the view you added in qt-designer
Make sure you have pyqtchart installed (with pip).

PyQt5 QListView sluggish first drag/drop on windows - python 3.5/3.4 32bit, pyqt5 from sourceforge

I have installed 32bit Python 3.4 and 3.5 and PyQt5 on our windows 7 work machine via the executable available from https://sourceforge.net/projects/pyqt/, however I now find that when I run my simple drag and drop test code it is very sluggish moving the first element (the ui freezes for about 4-5 seconds before completing the move). All subsequent drag and drop operations happen without that delay.
By "ui freezes" I mean that the selection remains highlit and in its original place when i move the cursor away and the drag and drop guide graphics (a line appearing where the items would move to if i let the mouse button go at that time, the mouse cursor changing to a different icon to indicate that drag and drop is occuring) do not appear. If I release the mouse button during this time the selected elements are moved to that location but not until the 4-5 second wait time has elapsed.
The code is as follows:
from PyQt5.QtWidgets import QMainWindow, QApplication, QListView, QAbstractItemView
from PyQt5.QtGui import QStandardItemModel, QStandardItem
def createModel():
model = QStandardItemModel()
for i in range(0,101):
item = QStandardItem(str(i))
item.setText(str(i))
item.setEditable(False)
item.setDropEnabled(False)
model.appendRow(item)
return model
class TestListView(QMainWindow):
def __init__(self, parent=None):
super(TestListView, self).__init__(parent)
self.listView = QListView()
self.setCentralWidget(self.listView)
self.listView.setModel(createModel())
self.listView.setSelectionMode(QAbstractItemView.ExtendedSelection)
self.listView.setDragEnabled(True)
self.listView.setDragDropMode(QAbstractItemView.InternalMove)
def main():
app = QApplication([])
lvt = TestListView()
lvt.show()
app.exec_()
if __name__ == '__main__':
main()
I am hoping someone can point out a foolish mistake I've made that is the cause of this issue (like when I earlier had passed ints to the QStandardItems constructor instead of strings, resulting in a crash each time I tried to drag and drop), but if that isn't the case, if anyone is able to recommend a combination of pyqt5 and 32bit (64bit is not an option for us) python components that they've found that does not exhibit this behaviour? I don't really care if it's python 3.x or python 2.x (although I haven't seen any pyqt5/python2 combinations previously), as long as it works.
I've tried the python-qt5 package that pip installs (after following the instructions here https://blogs.msdn.microsoft.com/pythonengineering/2016/04/11/unable-to-find-vcvarsall-bat/ by installing visual c++ build tools) in both 3.4 and 3.5, but the full version of this script will use .ui files from QtCreator, and the pip version of python-qt5 throws an error:
File "testReorder.py", line 2, in <module>
from PyQt5 import uic
File "c:\python35-32\lib\site-packages\PyQt5\uic\__init__.py", line 43, in <module>
from .Compiler import indenter, compiler
File "c:\python35-32\lib\site-packages\PyQt5\uic\Compiler\compiler.py", line 43, in <module>
from ..properties import Properties
File "c:\python35-32\lib\site-packages\PyQt5\uic\properties.py", line 46, in <module>
from .icon_cache import IconCache
File "c:\python35-32\lib\site-packages\PyQt5\uic\icon_cache.py", line 27, in <module>
from .port_v3.as_string import as_string
ImportError: No module named 'PyQt5.uic.port_v3'
when I include the import line
from PyQt5 import uic
in the code.
Edit: Having gotten home and tested the code on my linux machine (and seen no signs of sluggishness), I'm thinking this issue must be either specific to the combination of the pyqt, python and windows version, or something specific to that particular windows installation, and not a problem with my code.
I'd still be interested in hearing of anyone able to run the same code and not see the same issues on a windows (especially windows 7) machine, but I'm thinking it's less likely that I can assign the blame for this behaviour solely at pyqt's door.
Ran same code on another windows 7 computer with same packages installed. The issue is not seen there, so is obviously a problem with something specific to this machine rather than the code I've written/versions of python I'm using/version of pyqt.

PyQt4 checkboxes are not showing (but clickable) on Mac OS, on Windows it works fine

I'm creating a GUI with PyQt4 for my bachelor thesis. I have a QComboBox, where every item is a checkbox. Here is my code:
somewhere in the constructor:
self.multi = QtGui.QComboBox(self)
self.multi.setEnabled(True)
self.multi.view().pressed.connect(self.handleItemPressed)
and here I fill the QComboBox with my checkboxes:
def fillMultiCombo(self):
# len(self.featureNames) rows, 1 column
model = QtGui.QStandardItemModel(len(self.featureNames), 1)
firstItem = QtGui.QStandardItem("feature(s)")
firstItem.setBackground(QtGui.QBrush(QtGui.QColor(200, 200, 200)))
firstItem.setSelectable(False)
model.setItem(0, 0, firstItem)
for i,query in enumerate(self.featureNames):
item = QtGui.QStandardItem(query)
item.setFlags(QtCore.Qt.ItemIsEnabled)
item.setData(QtCore.Qt.Unchecked, QtCore.Qt.CheckStateRole)
model.setItem(i+1, 0, item)
self.multi.setModel(model)
Just to say in advance: I think it's not a code issue, but I provided some code to make it clearer.
The problem now is: On Windows 7 (on 2 different machines) it all works fine. But on my tutor's machine (Macbook Pro, I don't know which OS sorry), the checkboxes are not showing (but no error or warning printed), BUT when you click it, the checkbox is checked. So it's like the checkbox is there and functions, but it is invisible.
So is this a bug, machine dependent or some other issue. Because all other things work on her machine totally smooth.
After a long time I've finally found the problem. Here is the important code snippet:
app = QtGui.QApplication(sys.argv)
# Available styles (depending on the OS) for my ThinkPad:
# Windows
# WindowsXP
# WindowsVista
# Motif
# CDE
# Plastique
# Cleanlooks
# makes the split bar visible
app.setStyle(QtGui.QStyleFactory.create('Plastique'))
So before I set the style for my application, Qt chose the most appropriate style depending on the plattform resp. OS. So the default style Qt chose for my machine worked and the checkboxes are normally shown. The default style Qt chose for the application on the machine from my tutor was not the same. In fact if I change from 'Plastique' to 'Cleanlooks' my checkboxes also disappear.

Window Icon of Exe in PyQt4

I have a small program in PyQt4 and I want to compile the program into an Exe. I am using py2exe to do that. I can successfully set icon in the windows title bar using the following code, but when i compile it into exe the icon is lost and i see the default windows application. here is my program:
import sys
from PyQt4 import QtGui
class Icon(QtGui.QWidget):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.setGeometry(300, 300, 250, 150)
self.setWindowTitle('Icon')
self.setWindowIcon(QtGui.QIcon('c:/python26_/repy26/icons/iqor1.ico'))
app = QtGui.QApplication(sys.argv)
icon = Icon()
icon.show()
sys.exit(app.exec_())
**** Here is the setup.py for py2exe****
from distutils.core import setup
import py2exe
setup(windows=[{"script":"iconqt.py"
,"icon_resources": [(1, "Iqor1.ico")]}]
,options={"py2exe":{"includes":["sip", "PyQt4.QtCore"]}})
The problem is that py2exe doesn't include the qt icon reader plugin. You need to tell it to include it with the data_files parameter. Something along these lines:
setup(windows=[{"script":script_path,
"icon_resources":[(1, icon_path)]}],
data_files = [
('imageformats', [
r'C:\Python26\Lib\site-packages\PyQt4\plugins\imageformats\qico4.dll'
])],
options={"py2exe":{"packages":["gzip"],
"includes":["sip"]}})
I believe you need to reference the .ico file directly from the EXE or DLL that you are creating with py2exe. You seem to have the setup.py script correct, so take a look at: http://www.py2exe.org/index.cgi/CustomIcons. There is an example for wxWidgets, but you could try to adapt it to Qt.
I would suggest you to create a file called YourApp.rc, add up the following line :
IDI_ICON1 ICON DISCARDABLE "res/icons/app_icon.ico"
Then in your .PRO file, add up the following lines :
win32{
RC_FILE = YourApp.rc
}
It should fix your problem !
I had the same issue. For some reason it worked just fine with a image.png file & not an image.ico file. No clue why. But i converted the ico to png & it worked

Categories