[PyQt] Adding properties to a custom widget

skawaii skawaii at gmail.com
Fri Sep 7 20:54:19 BST 2007


I've looked around and tried things for a couple of days now, but haven't
been able to figure this out quite yet.

I've created a custom widget in Qt Designer. It's working great and I'd like
to be able to use this widget in future GUI's that I make (obviously). When
in the "Edit Custom Widgets" dialog (Tools > Custom), I tried to add some
properties that I'd like visible in Designer for future use. For example, a
property called "precision" that is an int. Fantastic.

I added my widget to a new dialog as a test. Compiled the ui file to python,
which has the following line -
self.fValuator2.setProperty("precision",QVariant(3)).

However, when I run this test dialog (i.e. python test_dialog.py), I get the
following error -
QWidget::setProperty( "display_precision", value ) failed: property invalid,
read-only or does not exist.

So, it seems the adding the property in Designer does not equate to the
property being created in my widget class. And this is where I hit a dead
end. How do i create this property in my widget class? I looked at the 
http://doc.trolltech.com/3.3/properties.html Qt docs  on properties;
however, I can't seem to figure out where the Q_PROPERTY macro is in PyQt
3.3.6 (upgrading to version 4.3 isn't an option for me, unfortunately). I've
also found some material 
http://www.diotavelli.net/PyQtWiki/Using_Python_Custom_Widgets_in_Qt_Designer
here , but it's again for PyQt 4.3 and doesn't seem that it'll work for me.

Any suggestions out there? Thanks in advance.
-- 
View this message in context: http://www.nabble.com/Adding-properties-to-a-custom-widget-tf4403448.html#a12562213
Sent from the PyQt mailing list archive at Nabble.com.



More information about the PyQt mailing list