[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    Re: [PyQt] On/Off Switch
From:       Saeed Mahdizadeh Bakhshmand <saeedbakhshmand () gmail ! com>
Date:       2016-05-29 20:11:45
Message-ID: CAGdd0Q6oJc0eYCRJruFoTFGCJDTzHpv1AZX5EePV=PMBMuh7OA () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


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@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
>
>

[Attachment #5 (text/html)]

<div dir="ltr"><div><div>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<a \
href="https://doc.qt.io/archives/4.6/statemachine-twowaybutton.html"> this \
example</a> to implement state machine and added: \
<br>on.connect(&#39;entered()&#39;,onApplyButton_connect)<br>on.connect(&#39;exited()&#39;,onApplyButton_disconnect)<br><br></div>which \
ApplyButton_connect   and ApplyButton_disconnect are as following:<br><br>   def \
onApplyButto_connect(self):<br>     \
Table.selectionModel().selectionChanged.connect(cellSelected&#39;&#39;&#39;#call to \
the function that should be carried out on cell selection&#39;&#39;&#39;)<br>       \
<br>   def onApplyButton_disconnect(self):<br>       \
Table.selectionModel().selectionChanged.disconnect(cellSelected &#39;&#39;&#39;#call \
to the function that should be carried out on cell \
selection&#39;&#39;&#39;)<br><br></div></div><div class="gmail_extra"><br><div \
class="gmail_quote">On Wed, May 25, 2016 at 11:18 AM, David Cortesi <span \
dir="ltr">&lt;<a href="mailto:davecortesi@gmail.com" \
target="_blank">davecortesi@gmail.com</a>&gt;</span> wrote:<br><blockquote \
class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc \
solid;padding-left:1ex"><div dir="ltr"><div><div><div><div><div><div><div>You want to \
make table items selectable when switch is On, and not selectable when \
Off?<br><br></div>I think the answer is in the flags() method of your table MODEL \
(not view).<br><br></div>You have I assume a table model based on QAbstractTableModel \
(<a href="http://doc.qt.io/qt-5/qabstracttablemodel.html" \
target="_blank">http://doc.qt.io/qt-5/qabstracttablemodel.html</a>)<br><br></div>and \
it has a flags() method returning the boolean OR of the flags in <a \
href="http://doc.qt.io/qt-5/qt.html#ItemFlag-enum" \
target="_blank">http://doc.qt.io/qt-5/qt.html#ItemFlag-enum</a><br><br></div>So, when \
the switch (button? checkbox?) state is Off, flags() must not return the \
Qt.ItemIsSelectable for any item.<br><br></div>When the switch changes state from On \
to Off, you tell the VIEW to clear the selection (<a \
href="http://doc.qt.io/qt-5/qabstractitemview.html#clearSelection" \
target="_blank">http://doc.qt.io/qt-5/qabstractitemview.html#clearSelection</a>)<br><br></div>Best \
of luck,<br></div>Dave Cortesi<br><br></div> </blockquote></div><br></div>


[Attachment #6 (text/plain)]

_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
https://www.riverbankcomputing.com/mailman/listinfo/pyqt

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic