Results 1 to 4 of 4

Thread: Make True or False a variable

  1. #1
    Join Date
    Jan 2017
    Posts
    27
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Make True or False a variable

    If I have the following snippet of code (from a larger section):
    Qt Code:
    1. if self.generator.MS == "S":
    2. self.lockSpouseBoxes(True)
    3. else:
    4. self.lockSpouseBoxes(False)
    5.  
    6. def lockSpouseBoxes(self):
    7.  
    8. self.ui.lineEdit1.setEnabled(variable for True or False)
    To copy to clipboard, switch view to plain text mode 

    How do I modify either/both the top part and the bottom function to carry the True or False from the top part to the function (there will be many line edits to setEnabled true or false). Stated another way, if MS == "S", I want to set a bunch of line edits to "setEnabled(True)" and vice versa. I'm new and not quite sure how to phrase the question.

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

    Default Re: Make True or False a variable

    Your "lockSpousesBoxes" needs a parameter for the boolean value

    Qt Code:
    1. def lockSpousesBoxes(self, enable):
    2. self.ui.lineEdit1.setEnabled(enable)
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

  3. #3
    Join Date
    Jan 2017
    Posts
    27
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Make True or False a variable

    Quote Originally Posted by anda_skoa View Post
    Your "lockSpousesBoxes" needs a parameter for the boolean value

    Qt Code:
    1. def lockSpousesBoxes(self, enable):
    2. self.ui.lineEdit1.setEnabled(enable)
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _
    '
    thanks for your response, but it does not work. I do not understand how the variable 'enable' receives a value of True or False from the code (the "if" statement) above the function? By the way, the code above the function is contained in another function. Sorry, I forgot to mention that.

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,165
    Thanks
    235
    Thanked 662 Times in 652 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: Make True or False a variable

    I do not understand how the variable 'enable' receives a value of True or False from the code
    What do you think this line of code does?

    Qt Code:
    1. self.lockSpouseBoxes(True)
    To copy to clipboard, switch view to plain text mode 

    If you don't know, then you really need to learn something about the Python language before you try to write programs using it.

    You also need to be very careful about indenting in Python. An indented section in Python is the same as code enclosed in curly braces "{}" in C / C++ - it defines the scope for that section of code. So if your code is really indented the way you pasted it, then I don't have any idea how Python interprets the scope of the lockSpouses function.
    Last edited by d_stranz; 27th April 2019 at 00:02.
    <=== 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. Swich Control - How to get True or false?
    By Mathan in forum Qt Programming
    Replies: 1
    Last Post: 10th October 2016, 13:17
  2. Qt true,false speed
    By mero in forum Qt Programming
    Replies: 3
    Last Post: 9th October 2010, 21:09
  3. Replies: 9
    Last Post: 22nd July 2010, 09:40
  4. Qt for S60, compiler warning regarding TRUE/FALSE
    By Archimedes in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 22nd October 2009, 15:09
  5. how to make menu visible false?
    By rajesh in forum Qt Programming
    Replies: 2
    Last Post: 18th July 2006, 11:04

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.