Results 1 to 4 of 4

Thread: setVisible(bool) problem, only works one way

  1. #1
    Join Date
    Dec 2010
    Posts
    23
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Windows

    Default setVisible(bool) problem, only works one way

    I am trying to set up a function that will make a label visible and invisible on alternating times I push a putton. So far I have set up the connection to use the setVisible(bool) public slot when I push the button. I have set up the function to access ButtonClickedHandler(bool) when action clicked(bool) is taken

    Qt Code:
    1. void MainWindow::ButtonClickedHandler(bool checked)
    2. {
    3. ui->label->setVisible(checked);
    4. }
    To copy to clipboard, switch view to plain text mode 

    When I compile and run the program, pushing the button the first time makes the label disappear, but pushing it subsequent times does not do anything, and does not turn the visibility back on. How can I get this to work properly?



    Alternatively I've tried to just create a connection between the button using clicked(bool) and the label using setVisible(bool), but I have the same exact problem, the first push makes the label disappear but subsequent pushes do not make it return.

    Thank you in advance
    Last edited by hojoff79; 29th December 2010 at 17:57.

  2. #2
    Join Date
    Nov 2010
    Posts
    97
    Thanks
    6
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: setVisible(bool) problem, only works one way

    Is your button a checkable button? If not then 'checked' is going to always be false. Have you used a debugger to break in that function and see what value it's being supplied with?
    This rude guy who doesn't want you to answer his questions.

    Note: An "expert" here is just someone that's posted a lot.

    "The fact of where you do the encapsulation is meaningless." - Qt Certified Developer and forum moderator

  3. #3
    Join Date
    Dec 2010
    Posts
    23
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Windows

    Default Re: setVisible(bool) problem, only works one way

    That was the problem, thank you for your help

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: setVisible(bool) problem, only works one way

    In addition to what was already said, use the toggled(bool) signal instead of clicked() as there as situations when clicked() is not emitted and the check state of the button changes.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. setVisible textblock in QTextEdit
    By corrado in forum Qt Programming
    Replies: 2
    Last Post: 27th April 2010, 03:04
  2. QTextBlock::setVisible()
    By jgrauman in forum Qt Programming
    Replies: 3
    Last Post: 11th December 2009, 01:06
  3. setVisible(false) doesn't work
    By sepehr in forum Qt Programming
    Replies: 2
    Last Post: 4th February 2009, 16:20
  4. setVisible, -> token, problems
    By Salazaar in forum Newbie
    Replies: 25
    Last Post: 12th June 2007, 14:30
  5. Problem with "setModified(bool)"
    By _SamSoft_ in forum Qt Programming
    Replies: 3
    Last Post: 3rd June 2007, 14:51

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.