Jan-05-2017, 10:34 AM
Hi everybody!
I 'm trying to make a custom widget for Qt in Python. I want it, in Qt Designer, to be able to receive events. e.g: (in Qt Designer, at design time) when a textbox is placed within my custom widget, the custom widget to get some attributes from the textbox and make an options list from them.
I 've seen lots of tutorials about extending widgets, making plugins (should I also make a plugin?) but none of them is really complete.
For example, in this tutorial: h**ps://doc.qt.io/archives/qq/qq26-pyqtdesigner.html
(replace ** with tt)
1. I have to create some files:
a. The file for the widget:class GeoLocationWidget(QWidget):
b. the file for the plugin: class GeoLocationPlugin(QPyDesignerCustomWidgetPlugin)
c. then it say: For this plugin, we install a task menu extension to let users configure our custom widget on the form via the context menu.
Do I have to install some extension?
I think I don't need a context menu (I suppose it is a menu that shows up with a right click on th widget in QtDesigner).
d. In 'Making a menu' section, I also think this is needed only if I want a Dialog for editing the properties. From what I understand, I can edit the properties of my custom widget from Qt Designer's property editor, right?
e. The file for class GeoLocationMenuEntry(QPyDesignerTaskMenuExtension).
So in fact I need 3 files: a, b, e. Right?
Then it says: ' Unlike C++ plugins, those written in Python do not have to be compiled or otherwise prepared before we install them—we can simply copy the sources to the appropriate locations so that Qt Designer can find them.
So, these 3 files, I 'll have to put them in the 'appropriate locations'. Which re these locations?
I have installed designer.exe (the QtDesigner executable) at: F:\Python34\Lib\site-packages\PyQt4
'The convention for Python plugins is to create a python directory alongside the C++ plugins and store them in there'...
I suppose the directory of C++ plugins is: F:\Python34\Lib\site-packages\PyQt4\plugins
So, I have to create a directory F:\Python34\Lib\site-packages\PyQt4\mycustomplugin?
And which files should I put there? The plugin files? That is, the b in the above list?
'The widgets themselves need to be placed in a standard location so that the Python interpreter can find them. Often, it is convenient to store them in the Python installation's site-packages directory'.
So the file a (in the list), I 'll have to move it in F:\Python34\Lib\site-packages\PyQt4\mycustomwidget?
'As an alternative to installation, environment variables can be set to refer to the locations of plugins and custom widgets. Developers familiar with Python will know that PYTHONPATH can be used to add new directories to the list of known locations of modules and packages.
Similarly, PYQTDESIGNERPATH can be used to add locations of Python modules containing plugins and extensions for Qt Designer.'
So I don't have to install anything, right? So, how can I do it with PYTHONPATH and PYQTDESIGNERPATH?
The whole example archive can be downloaded from h**ps://doc.qt.io/archives/qq/qq26-pyqtdesigner-1.1.zip
(replace ** with tt)
I want to use them without installing them first. In the readme.txt, it says:
To use the custom widget plugins and extensions without installing them first,
open a console, enter the qq26-pyqtdesigner directory and type
PYQTDESIGNERPATH=python designer &
It looks like something missing?
Of course, if you have some complete tutorial (I say this because I found lots of tutorials, but none complete) to propose, please do.
I 'm trying to make a custom widget for Qt in Python. I want it, in Qt Designer, to be able to receive events. e.g: (in Qt Designer, at design time) when a textbox is placed within my custom widget, the custom widget to get some attributes from the textbox and make an options list from them.
I 've seen lots of tutorials about extending widgets, making plugins (should I also make a plugin?) but none of them is really complete.
For example, in this tutorial: h**ps://doc.qt.io/archives/qq/qq26-pyqtdesigner.html
(replace ** with tt)
1. I have to create some files:
a. The file for the widget:class GeoLocationWidget(QWidget):
b. the file for the plugin: class GeoLocationPlugin(QPyDesignerCustomWidgetPlugin)
c. then it say: For this plugin, we install a task menu extension to let users configure our custom widget on the form via the context menu.
Do I have to install some extension?
I think I don't need a context menu (I suppose it is a menu that shows up with a right click on th widget in QtDesigner).
d. In 'Making a menu' section, I also think this is needed only if I want a Dialog for editing the properties. From what I understand, I can edit the properties of my custom widget from Qt Designer's property editor, right?
e. The file for class GeoLocationMenuEntry(QPyDesignerTaskMenuExtension).
So in fact I need 3 files: a, b, e. Right?
Then it says: ' Unlike C++ plugins, those written in Python do not have to be compiled or otherwise prepared before we install them—we can simply copy the sources to the appropriate locations so that Qt Designer can find them.
So, these 3 files, I 'll have to put them in the 'appropriate locations'. Which re these locations?
I have installed designer.exe (the QtDesigner executable) at: F:\Python34\Lib\site-packages\PyQt4
'The convention for Python plugins is to create a python directory alongside the C++ plugins and store them in there'...
I suppose the directory of C++ plugins is: F:\Python34\Lib\site-packages\PyQt4\plugins
So, I have to create a directory F:\Python34\Lib\site-packages\PyQt4\mycustomplugin?
And which files should I put there? The plugin files? That is, the b in the above list?
'The widgets themselves need to be placed in a standard location so that the Python interpreter can find them. Often, it is convenient to store them in the Python installation's site-packages directory'.
So the file a (in the list), I 'll have to move it in F:\Python34\Lib\site-packages\PyQt4\mycustomwidget?
'As an alternative to installation, environment variables can be set to refer to the locations of plugins and custom widgets. Developers familiar with Python will know that PYTHONPATH can be used to add new directories to the list of known locations of modules and packages.
Similarly, PYQTDESIGNERPATH can be used to add locations of Python modules containing plugins and extensions for Qt Designer.'
So I don't have to install anything, right? So, how can I do it with PYTHONPATH and PYQTDESIGNERPATH?
The whole example archive can be downloaded from h**ps://doc.qt.io/archives/qq/qq26-pyqtdesigner-1.1.zip
(replace ** with tt)
I want to use them without installing them first. In the readme.txt, it says:
To use the custom widget plugins and extensions without installing them first,
open a console, enter the qq26-pyqtdesigner directory and type
PYQTDESIGNERPATH=python designer &
It looks like something missing?
Of course, if you have some complete tutorial (I say this because I found lots of tutorials, but none complete) to propose, please do.