[PySide] Custom PySide widget support in QtDesigner?

2,657 views
Skip to first unread message

Åke Kullenberg

unread,
Dec 21, 2011, 5:46:46 AM12/21/11
to pys...@lists.pyside.org
AFAIK there is no way to import custom pyside widgets in QtDesigner. Is there any particular reason for this? This is a huge shame, QtDesigner is a major time saver in terms of producing straightforward ui components such as dialogs. Other python gui frameworks really don't have anything like it to offer either, so it's definitely a big competitive advantage for pyside/qt. However If I can't use custom pyside widgets QtDesigner is a lot less useful IMHO. 

Nathan Smith

unread,
Dec 21, 2011, 11:04:25 AM12/21/11
to Åke Kullenberg, pys...@lists.pyside.org
Åke,

There used to be a QtDesigner plugin for PySide, but I don't think it ever worked.  Fortunately, you can still use Designer even without the plugin by using the "promotion" system.  Say, for example, you've created MyLineEdit, a QLineEdit subclass.  
  1. In Designer, drop a QLineEdit on the form where you'd like your MyLineEdit to go
  2. Right click on the QLineEdit widget you added to the form and select "Promote to...".
  3. In "Promoted class name:", enter MyLineEdit.
  4. In "Header file", enter package/path/to/MyLineEdit.h, where package/path/to is the Python package path to the .py file that contains the MyLineEdit widget class.  pyside-uic converts this into "from package.path.to import MyLineEdit"
  5. Click "Add"
  6. Click "Promote"
The next time you add a QLineEdit to the form, you can use the promotion you've already defined, so you don't have to go through these steps for each widget.  The downside to this approach is that you don't have access to the widget's custom properties like you would through a plugin.

Good luck!

Nathan

On Wed, Dec 21, 2011 at 4:46 AM, Åke Kullenberg <ake.kul...@gmail.com> wrote:
AFAIK there is no way to import custom pyside widgets in QtDesigner. Is there any particular reason for this? This is a huge shame, QtDesigner is a major time saver in terms of producing straightforward ui components such as dialogs. Other python gui frameworks really don't have anything like it to offer either, so it's definitely a big competitive advantage for pyside/qt. However If I can't use custom pyside widgets QtDesigner is a lot less useful IMHO. 
_______________________________________________
PySide mailing list
PyS...@lists.pyside.org
http://lists.pyside.org/listinfo/pyside


Åke Kullenberg

unread,
Dec 21, 2011, 7:24:46 PM12/21/11
to Nathan Smith, pys...@lists.pyside.org
Thanks for this. I got it to work if I use pyside-uic. But if I try to load the ui file in the script with a QUiLoader, I get this line:

"QFormBuilder was unable to create a custom widget of the class 'mycustom'; defaulting to base class 'QToolButton'." 

Is there any way to fix that?

Nathan Smith

unread,
Dec 21, 2011, 7:34:21 PM12/21/11
to Åke Kullenberg, pys...@lists.pyside.org

I always use uic, so I don't know. Perhaps someone else on the list knows.

Nathan

Åke Kullenberg

unread,
Dec 22, 2011, 1:10:38 AM12/22/11
to Nathan Smith, pys...@lists.pyside.org
That turned out easier than I thought. Just register the class to the QUiLoader instance with registerCustomWidget.

Big thanks for the help, that saved my day (week)!

Aaron Richiger

unread,
Jan 13, 2012, 2:08:56 PM1/13/12
to pys...@lists.pyside.org
Hello everybody!

I found a strange behaviour of QTabWidget depending on the platform. The
type of the argument passed by the signal "currentChanged" should be
integer looking at the doc and it is on linux, but on MacOS, a QWidget
is passed (The current tab widget...). Why?!? Thanks for having a look
at it or sending me the type passed on Windows (I have currently no
windows to test, sorry)!
Aaron

This code demonstrates it:


from PySide.QtGui import *
from PySide.QtCore import *
import sys


def slot(parameter):
print type(parameter)


app = QApplication(sys.argv)
t = QTabWidget()
for i in xrange(1, 4):
t.addTab(QWidget(), 'Tab %d' % i)
t.currentChanged.connect(slot)
t.show()
app.exec_()

Tim Doty

unread,
Jan 14, 2012, 9:42:24 AM1/14/12
to Aaron Richiger, pys...@lists.pyside.org
Hi Aaron,

On Jan 13, 2012, at 1:08 PM, Aaron Richiger wrote:

> Hello everybody!
>
> I found a strange behaviour of QTabWidget depending on the platform. The type of the argument passed by the signal "currentChanged" should be integer looking at the doc and it is on linux, but on MacOS, a QWidget is passed (The current tab widget...). Why?!? Thanks for having a look at it or sending me the type passed on Windows (I have currently no windows to test, sorry)!

What version of PySide are you using? I backed down to 1.0.4 due to the bugs in newer versions.

On OS X with PySide 1.0.4 I got the expected output (type is int) which is the same result as I got on Windows and Linux.

Tim Doty

Aaron Richiger

unread,
Jan 14, 2012, 11:48:05 AM1/14/12
to Tim Doty, pys...@lists.pyside.org
Hello!
On MacOS, I'm using PySide 1.0.6 (I know, it's not the newest, but
because building it from source with the mysql driver is so painful, I
do not recompile on every release...), Qt4.7.4.
On my ubuntu machine I use PySide 1.0.9, Qt4.7.4!

Could anyone with a newer PySide version test my testcode on MacOS to
tell me whether the bug is still there? Thanks!

Aaron

Reply all
Reply to author
Forward
0 new messages