Python Forum
Custom widget in Python-Qt, 'live' at Qt Designer
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Custom widget in Python-Qt, 'live' at Qt Designer
#1
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.
Reply
#2
Quote:For example, in this tutorial:

Is this a homework assignment?

You didn't give a URL
Reply
#3
(Jan-05-2017, 10:40 AM)Larz60+ Wrote:
Quote:For example, in this tutorial:

Is this a homework assignment?

You didn't give a URL

Sorry, here it is: h**ps://doc.qt.io/archives/qq/qq26-pyqtdesigner.html
(replace ** with tt)

No, it' s not a homework assignment, I'm trying to make an application.

Ok, I 'm examining a simpler tutorial: h**ps://wiki.python.org/moin/PyQt/Using_Python_Custom_Widgets_in_Qt_Designer
(replace ** with tt)

In this one, I 'll have to create files:
1. for the widget: class PyAnalogClock(QtGui.QWidget). How should I name this file? analogclockwiget.py?
2. for the plugin: class PyAnalogClockPlugin(QtDesigner.QPyDesignerCustomWidgetPlugin) How should I name this file? analogclockplugin.py?
3. 'place the modules containing the custom widget and its plugin class in the appropriate locations in the file system'. Which are these locations?
Reply
#4
By default, modules containing plugin classes should be located in the python directory inside the directory containing the other Qt plugins for Qt Designer. For testing purposes, the PYQTDESIGNERPATH environment variable can be used to refer to the location of the modules containing the plugin classes. I want to test it (for now), so how can I do it with PYQTDESIGNERPATH?

The modules containing the custom widgets themselves only need to be located on one of the standard paths recognized by Python, and can therefore be installed in the user's site-packages directory, or the PYTHONPATH environment variable can be set to refer to their location. How can I do it with PYTHONPATH?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  I want to create custom charts in Python. js1152410 1 541 Nov-13-2023, 05:45 PM
Last Post: gulshan212
  Is it possible to capture live running waveforms in an oscilloscope using python? Girishbabu_27 4 986 Jul-29-2023, 06:05 AM
Last Post: Girishbabu_27
  Plot a pandas data fram via pyqtgraph with an modul import and qt designer widget Nietzsche 0 850 May-29-2023, 02:42 PM
Last Post: Nietzsche
  How to parse a live feed in Python? Daring_T 2 4,123 Jan-20-2022, 04:17 AM
Last Post: Daring_T
  importing same python library in multiple custom module escape_freedom13 6 3,824 May-10-2020, 07:01 PM
Last Post: escape_freedom13
  Python animate live plotting fetching data from Mysql Table dhirajm 6 3,645 Apr-24-2020, 05:07 PM
Last Post: dhirajm
  Importing Custom Modules in Python 3 Flexico 1 2,586 Aug-24-2019, 08:11 PM
Last Post: snippsat
  problem using custom exception handling in python srm 3 3,053 Jul-03-2019, 09:10 PM
Last Post: ichabod801
  Python Extensions with C Custom PyObject? babaliaris 9 5,532 Feb-14-2018, 08:39 PM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020