[PySide] Value of QAbtractItemModel.flags()

Carlos Zuniga carlos.zun at gmail.com
Fri Jun 14 05:59:20 CEST 2013


On Thu, Jun 13, 2013 at 6:03 PM, Alexey Vihorev <vihorev at gmail.com> wrote:
> Hi!
>
> I guess that is a stupid question, but I was never able to understand binary
> operators.  And now I’m stuck with this:
>
>
>
>
>
> class MyModel(QAbtractItemModel):
>
>>
> def flags(index):
>
>       if index.isValid() and whatever:
>
> return Qt.ItemIsEditable|Qt.ItemIsEnabled|Qt.ItemIsSelectable #that is one
> problematic return value
>
>
>
> Now I need to know, if an item at a given index is editable. I get the
> return value from model.flags(index), but how can I know if
>
> Qt.ItemIsEditable is actually in there somewhere, inside this
> Qt.ItemIsEditable|Qt.ItemIsEnabled|QtItemIsSelectable value? Thanks!
>

Hi, you can use & to see if it has that flag:

val = model.flags(index)
if val & Qt.ItemIsEditable:
    pass

Basically:

>>> bin(0b010 | 0b001)  # join flags
'0b11'
>>> bin(0b011 & 0b001)  # check flag
'0b1'
>>> bin(0b011 & 0b100)  # when flag isn't set it returns 0
'0b0'


Cheers
--
Carlos



More information about the PySide mailing list