[PyQt] On/Off Switch

Saeed Mahdizadeh Bakhshmand saeedbakhshmand at gmail.com
Sun May 29 21:11:45 BST 2016


Thanks, earlier than seeing your message I managed to use connect and
disconnect functions to be activated while entering On and Off states,
respectively. I used this example
<https://doc.qt.io/archives/4.6/statemachine-twowaybutton.html> to
implement state machine and added:
on.connect('entered()',onApplyButton_connect)
on.connect('exited()',onApplyButton_disconnect)

which ApplyButton_connect  and ApplyButton_disconnect are as following:

  def onApplyButto_connect(self):
   Table.selectionModel().selectionChanged.connect(cellSelected'''#call to
the function that should be carried out on cell selection''')

  def onApplyButton_disconnect(self):
    Table.selectionModel().selectionChanged.disconnect(cellSelected
'''#call to the function that should be carried out on cell selection''')


On Wed, May 25, 2016 at 11:18 AM, David Cortesi <davecortesi at gmail.com>
wrote:

> You want to make table items selectable when switch is On, and not
> selectable when Off?
>
> I think the answer is in the flags() method of your table MODEL (not view).
>
> You have I assume a table model based on QAbstractTableModel (
> http://doc.qt.io/qt-5/qabstracttablemodel.html)
>
> and it has a flags() method returning the boolean OR of the flags in
> http://doc.qt.io/qt-5/qt.html#ItemFlag-enum
>
> So, when the switch (button? checkbox?) state is Off, flags() must not
> return the Qt.ItemIsSelectable for any item.
>
> When the switch changes state from On to Off, you tell the VIEW to clear
> the selection (http://doc.qt.io/qt-5/qabstractitemview.html#clearSelection
> )
>
> Best of luck,
> Dave Cortesi
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20160529/104e39d1/attachment.html>


More information about the PyQt mailing list