[PyQt] Custom widget property

Vincent Vande Vyvre vincent.vandevyvre at swing.be
Fri Aug 17 13:10:35 BST 2012


Hi,

I'm working on a custom widget, I've created a file plugin and I can use
my widget into the Designer.

So, this widget has a property 'orientation' wich may take two values:
'east' or 'west'.

Into the properties editor this property appears with a lineEdit, how
can make
to change this lineEdit to a comboBox with the two values?

This is the code for this property:

    def getOrientation(self):
         return self.orientation_

    def setOrientation(self, orientation):
        """Sets the orientation of the widgets.

        Args:
        orientation -- str() 'east', the widgets are placed from left to
                        right (default) or 'west'
        """

        if orientation not in ('east', 'west'):
            raise ValueError('VToolHeader.setOrientation(orientation)
arg 1 has'
                                ' unexpected value {0}'.format(orientation))

        if orientation != self.orientation_:
            self.orientation_ = orientation
            self.__set_direction()

            if self.collapsible_:
                self.collapse_btn.update_icon()

    orientation = pyqtProperty('QString', getOrientation, setOrientation)


Thanks for all advices

-- 
Vincent V.V.
Oqapy <https://launchpad.net/oqapy> . Qarte
<https://launchpad.net/qarte> . PaQager <https://launchpad.net/paqager>



More information about the PyQt mailing list