Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. QCheckBox change state without triggering stateChanged
Forum Updated to NodeBB v4.3 + New Features

QCheckBox change state without triggering stateChanged

Scheduled Pinned Locked Moved Solved Qt for Python
3 Posts 2 Posters 2.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    midnightdim
    wrote on 28 Mar 2021, 16:24 last edited by midnightdim
    #1

    I'm stuck with the following problem.
    I have a QCheckBox and a list of items in a table. I'm recording checked/unchecked state of each item to the database when user selects and item and checks/unchecks the checkbox.
    I'm using myCheckBox.stateChanged.connect(self.update_db) to trigger update_db() that updates the item state in the database.
    I also need to update the state of the checkbox to show the current state of the item when user selects the item in the table.
    To do this I call myCheckBox.setChecked()

    The problem is that when I call setChecked() it triggers stateChanged() which in turn triggers update_db() which is an unnecessary call.

    Is it possible to call setChecked() (or setCheckState()) without triggering stateChanged()?
    Or is it possible to identify if stateChanged() was triggered by the user action or by the code?

    UPDATE:
    A possible solution would be to connect to clicked() instead - it doesn't trigger stateChanged(). Is this the only solution?

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 28 Mar 2021, 18:45 last edited by
      #2

      Hi,

      You can use QSignalBlocker.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      M 1 Reply Last reply 29 Mar 2021, 04:53
      3
      • S SGaist
        28 Mar 2021, 18:45

        Hi,

        You can use QSignalBlocker.

        M Offline
        M Offline
        midnightdim
        wrote on 29 Mar 2021, 04:53 last edited by
        #3

        @SGaist Thanks! For now I switched to clicked() which seems to be fine, but checked QSignalBlocker and it works too, good to know it exists.
        I'm new to Qt and it's really impressive how thought out to the details it is! And what's more important there are gurus who share their knowledge and respond quicker than tech support of most of the software dev companies :-) Thanks again!

        1 Reply Last reply
        0

        1/3

        28 Mar 2021, 16:24

        • Login

        • Login or register to search.
        1 out of 3
        • First post
          1/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved