9

I am trying to write a custom widget for the Qt Designer using only Python. I was following a couple of tutorials I found online but none of them were working or anything close to what I would call to be a minimum working example.

So my questions are:

  1. What steps are involved to make a a custom widget appear in the Widget Box of Qt Designer?
  2. If you can spare the time: Please provide a minimum working example (like a widget with a label in it saying "A truly minimal working Qt custom widget example").
  3. Or is it maybe not possible at all to include a custom widget using only python?
Woltan
  • 13,723
  • 15
  • 78
  • 104

3 Answers3

2

There are very few examples available on how to make a custom widget in pyqt. I wrote this article with a working example: Making a Custom Widget in PyQt

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
scottydelta
  • 1,786
  • 4
  • 19
  • 39
  • Thank you for this post, but unfortunately this does **not** answer my question. I am after a custom widget that is displayed in the designer itself without the need to add it "manually" within some code. – Woltan Apr 17 '13 at 05:49
  • can you elaborate along with an example, in your question you said "how to make a custom widget appear in other widget box", and thats what the post i wrote for you on my blog does, anyways, elaborate your problem with an example, will try to help you. – scottydelta Apr 17 '13 at 06:57
  • 1
    I am talking about the Widget Box of the Qt Designer ([link](http://doc.crossplatform.ru/qt/4.3.2/images/designer-widget-box.png)). The Widget Box lists all common widgets like buttons, lists etc. I want my custom widget to be displayed in that box so that I can add and work with my custom widget in the Qt Designer. – Woltan Apr 17 '13 at 07:39
2

Here is the answer to your question #3: How do I use promote to in Qt Designer in pyqt4?

I am using PySide and it works the same way. This method works directly with your Python custom widget code. You do not need to write any separate plugin code.

After you have promoted your custom widget, you can right click on it and add your signals with "Change signals/slots..."

I would recommend putting all you widgets in a YourCostumWidgetsPack.UI file, and then when you load this file in Qt Designer, in addition to the UI you are working. It will load all your custom widget information.

Community
  • 1
  • 1
Tim S
  • 21
  • 1
1

I found this article to be your answer: https://doc.qt.io/archives/qq/qq26-pyqtdesigner.html

But, I haven't been able to install it in Qt Designer though :D

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
swdev
  • 4,997
  • 8
  • 64
  • 106
  • 1
    Nice, I am currently now working with Qt anymore. But this definitely answers my question! Thx for this late reply! – Woltan May 21 '14 at 07:03
  • Great! Just able to install it in Qt Designer: just make sure to add your path to custom widget into environment variables PYTHONPATH and PYQTDESIGNERPATH. And, I think we have to use Qt designer supplied by PyQt. I test it with Qt Designer from Qt C++ distribution, and it won't display my custom python qt widget. – swdev May 21 '14 at 13:38
  • 1
    Your link is broken, illustrating why you should always summarize the contents of a link, and just include it for reference. – MattDMo Aug 03 '15 at 05:21
  • Hm, pardon for that. Will note this – swdev Aug 04 '15 at 01:21
  • That answer is not longer valid, the link is broken. – Aftab Naveed Mar 18 '16 at 07:35
  • As others have commented link is gone - no answer now – Tim Seed Mar 25 '16 at 04:54
  • *Qt Designer*? Don't you mean ***[Qt Creator](http://en.wikipedia.org/wiki/Qt_Creator)***? – Peter Mortensen Apr 16 '17 at 18:36
  • @PeterMortensen He meant Designer. But do you know a way to use QtCreator alongside PyQt ? – melMass Apr 18 '17 at 21:05