# Qt enum access from Slicer using Python?

**URL:** <https://discourse.slicer.org/t/qt-enum-access-from-slicer-using-python/8231>\
**Category:** Development\
**Created:** [August 29, 2019, 8:55pm UTC](https://discourse.slicer.org/t/qt-enum-access-from-slicer-using-python/8231 "2019-08-29T20:55:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mikebind](https://avatars.discourse-cdn.com/v4/letter/m/71e660/32.png) [@mikebind](https://discourse.slicer.org/u/mikebind)\
**Post date:** [August 29, 2019, 8:55pm UTC](https://discourse.slicer.org/t/qt-enum-access-from-slicer-using-python/8231/1 "2019-08-29T20:55:05Z")

</div>

I’m working on a custom module and want to use a QTableWidget filled with QTableWidgetItems. I have that working, but as I work on it, I keep coming across Qt enums being used to set various policies or flags. For example, to control how QTableWidgetItems can be interacted with, I need to use QTableWidgetItems.setFlags(). Qt documentation examples explain that this function takes a logical combination of enums like this

```auto
QTableWidgetItem *item = new QTableWidgetItem();
item->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEnabled);

```

Is there any way to access these enums from a python slicer module? My workaround is currently to dig in the Qt documentation to find out what integers the enums correspond to (e.g. [https://doc.qt.io/qt-5/qt.html#ItemFlag-enum](https://doc.qt.io/qt-5/qt.html#ItemFlag-enum)) and use that number. So far, that works fine, but is much uglier and less clear than the named enum approach.

The equivalent version I have working is

```
item = qt.QTableWidgetItem()
item.setFlags(33) # 33 because selectable is 1 and enabled is 32 and to combine them you add them up

```

I’ve tried searching the slicer source on github and exploring the autocomplete methods and properties under qt.Q… and a couple qt.QAbstract… classes, but have not found any leads. Some of these enums show up in .ui files, but not in anything python that I’ve found. Thanks for any help you can provide.

---

<div class="post-metadata">

**Author:** ![Sunderlandkyl](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/sunderlandkyl/32/79987_2.png) [@Sunderlandkyl](https://discourse.slicer.org/u/Sunderlandkyl)\
**Post date:** [August 29, 2019, 9:09pm UTC](https://discourse.slicer.org/t/qt-enum-access-from-slicer-using-python/8231/2 "2019-08-29T21:09:47Z")

</div>

Yes, you can access the enums in the Qt namespace like this:

```
qt.Qt.ItemIsEnabled
```

---

<div class="post-metadata">

**Author:** ![mikebind](https://avatars.discourse-cdn.com/v4/letter/m/71e660/32.png) [@mikebind](https://discourse.slicer.org/u/mikebind)\
**Post date:** [August 29, 2019, 10:05pm UTC](https://discourse.slicer.org/t/qt-enum-access-from-slicer-using-python/8231/3 "2019-08-29T22:05:04Z")

</div>

Thank you! I felt like there should be something like that, but did not find it!
