Results 1 to 4 of 4

Thread: Does a radio button fire upon "deselection"

  1. #1
    Join Date
    Jan 2017
    Posts
    54
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Does a radio button fire upon "deselection"

    I have two radio buttons (yesRB and noRB) in a "group" such that when one is selected, the other is automatically deselected. I have separate functions tied to each button when selected.
    Qt Code:
    1. self.ui.yesRB.toggled.connect(self.yesRB)
    2. self.ui.noRB.toggled.connect(self.noRB)
    To copy to clipboard, switch view to plain text mode 

    My question: Let's say "noRB" is currently selected, and I then select "yesRB". Does the automatic "deselecting" of "noRB" trigger the function tied to "noRB" BEFORE it then triggers the function of yesRB?
    thanks

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Does a radio button fire upon "deselection"

    Yes, the toggled() signal will be emitted when the state changes either way.

    You can easily detect that inside the function connected to it via the boolean parameter it carries.

    Cheers,
    _

  3. The following user says thank you to anda_skoa for this useful post:

    dennisvz (12th May 2019)

  4. #3
    Join Date
    Jan 2017
    Posts
    54
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Does a radio button fire upon "deselection"

    Sorry, a follow-up question. If I have a Qcheckbox that has one function tied to it that either runs code for .isChecked(True) or code for .isChecked(False): Does checking an "unchecked" box first run the code for the False portion before running the code for True? Or, does it just run the True portion of the code?

  5. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,229
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Does a radio button fire upon "deselection"

    Does checking an "unchecked" box first run the code for the False portion before running the code for True? Or, does it just run the True portion of the code?
    This question doesn't make a lot of sense.

    If you connect a slot to either the QCheckBox::stateChanged() or the QAbstractButton::toggled() signal (which QCheckBox inherits), then the signal is fired once when the state changes and the argument to the signal is the current state of the button (Qt::CheckState for a check box state change, true or false for the toggled signal).

    In your slot, if you either look at the argument to the slot or at the value returned by .isChecked() method, you get the same value - true or false. There is no "isChecked( bool )" method (ie. no .isChecked(True) or .isChecked(False)). So your slot is going to decide based on the state of the check box whether to execute the code you have written to handle the case of checked or not checked.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Replies: 1
    Last Post: 1st April 2017, 22:13
  2. Replies: 1
    Last Post: 20th November 2015, 11:02
  3. Replies: 3
    Last Post: 8th December 2011, 20:21
  4. Translation QFileDialog standart buttons ("Open"/"Save"/"Cancel")
    By victor.yacovlev in forum Qt Programming
    Replies: 4
    Last Post: 24th January 2008, 20:05

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.