Results 1 to 3 of 3

Thread: Why doesn't this button become invisible?

  1. #1
    Join Date
    Jul 2010
    Posts
    10
    Thanks
    7
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Why doesn't this button become invisible?

    I want a button to become invisible when I click on it. I'm inheriting from QPushButton and then promoting. I know the button is being created properly because when I put the setVisible part into the constructor, it works. It just doesn't work when I click on the button when the program is running, despite my attempt to override the QPushButton functions of click() or clicked(). What am I doing wrong here? How can I get this to work?

    Qt Code:
    1. #ifndef SOUNDBUTTON_H
    2. #define SOUNDBUTTON_H
    3.  
    4. #include <QPushButton>
    5.  
    6. class SoundButton : public QPushButton
    7. {
    8. public:
    9. SoundButton(QWidget *parent = 0);
    10.  
    11. void click();
    12. void clicked();
    13. };
    14.  
    15. #endif // SOUNDBUTTON_H
    16.  
    17. // the cpp file
    18.  
    19. #include "soundbutton.h"
    20. #include <stdio.h>
    21.  
    22. SoundButton::SoundButton(QWidget *parent)
    23. : QPushButton(parent)
    24. {
    25. printf("test me"); //doesn't output but not related to the problem
    26. }
    27.  
    28. void SoundButton::click()
    29. {
    30. this->setVisible(false);
    31. }
    32.  
    33. void SoundButton::clicked()
    34. {
    35. this->setVisible(false);
    36. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by wysota; 23rd July 2010 at 23:22.

  2. #2
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Why doesn't this button become invisible?

    I might not understood you right, you need a button that will hide itself when clicked?
    Qt Code:
    1. #ifndef SOUNDBUTTON_H
    2. #define SOUNDBUTTON_H
    3.  
    4. #include <QPushButton>
    5.  
    6. class SoundButton : public QPushButton
    7. {
    8. Q_OBJECT // also don't forget Q_OBJECT macro when declare signals and slots in a class
    9. public:
    10. SoundButton(QWidget *parent = 0);
    11. public slots: // declare the slots of your class
    12. void SoundButtonHide(); //declare a slot that will hide the object,
    13. };
    14.  
    15. #endif // SOUNDBUTTON_H
    16.  
    17. // the cpp file
    18.  
    19. #include "soundbutton.h"
    20. #include <stdio.h>
    21.  
    22. SoundButton::SoundButton(QWidget *parent)
    23. : QPushButton(parent)
    24. {
    25. printf("test me"); //doesn't output but not related to the problem //this doesn't have where to print, because you are not making a console application
    26. connect(this, SIGNAL(clicked()), this, SLOT(SoundButtonHide())); //connect the clicked signal with the slot that will hide the button, are you sure that you need the button to hide itself?
    27.  
    28. }
    29.  
    30. void SoundButton::SoundButtonHide(){
    31. this->setVisible(false);
    32. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by Zlatomir; 23rd July 2010 at 23:10.

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

    Plixil (24th July 2010)

  4. #3
    Join Date
    Jul 2010
    Posts
    10
    Thanks
    7
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Why doesn't this button become invisible?

    Ha! I finally understand slots and signals. Thanks, Zlatomir

Similar Threads

  1. setchecked( true) of the radio button doesn't work
    By richardander in forum Qt Programming
    Replies: 9
    Last Post: 28th January 2009, 17:54
  2. why doesn't the button work?
    By mattia in forum Newbie
    Replies: 18
    Last Post: 5th November 2007, 12:14
  3. Replies: 4
    Last Post: 23rd November 2006, 05:24
  4. Replies: 2
    Last Post: 1st August 2006, 10:23
  5. [qt3]invisible toolbar
    By lszk in forum Qt Programming
    Replies: 2
    Last Post: 26th February 2006, 18:34

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.