Results 1 to 7 of 7

Thread: disable myself when clicked

  1. #1
    Join Date
    Oct 2008
    Location
    Beijing China
    Posts
    77
    Thanks
    21
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Question disable myself when clicked

    Qt Code:
    1. connect( button, SIGNAL(clicked()), this, SLOT( on_button_clicked()));
    2.  
    3. This::on_button_clicked()
    4. {
    5. button->setEnabled(false);
    6. }
    To copy to clipboard, switch view to plain text mode 

    this does not work, of course. how to implement to disable a button when it is clicked?

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: disable myself when clicked

    does ur cod reach the slot ?
    Are you using your own slot ? or is it the default slot : on_XXXX_clicked() ?

    BTW, how do you plan to enable it again ? bec you wont be able to click a disabled button

  3. #3
    Join Date
    Oct 2008
    Location
    Beijing China
    Posts
    77
    Thanks
    21
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: disable myself when clicked

    Quote Originally Posted by aamer4yu View Post
    does ur cod reach the slot ?
    Are you using your own slot ? or is it the default slot : on_XXXX_clicked() ?

    BTW, how do you plan to enable it again ? bec you wont be able to click a disabled button
    first question, yes, i could hit the break point in this slot, and the enabled state remains false until exiting this field.

    second question, i could enable it by other object's signal

    Thanks for ur reply.

  4. #4
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: disable myself when clicked

    try this
    Qt Code:
    1. connect(button, SIGNAL(clicked(bool)), button, SLOT(setEnabled(bool)));
    To copy to clipboard, switch view to plain text mode 
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  5. #5
    Join Date
    Dec 2007
    Posts
    40
    Thanks
    6
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: disable myself when clicked

    Quote Originally Posted by aamer4yu View Post
    does ur cod reach the slot ?
    Are you using your own slot ? or is it the default slot : on_XXXX_clicked() ?

    BTW, how do you plan to enable it again ? bec you wont be able to click a disabled button
    the setEnabled() kind of functions do not reflect the change till the slot is complete and control goes back to event loop. and as explained below by others, if the only thing you have to do is to disable/enable the button, best is to connect it to the button's slot

    cheers!
    Let your work talk for you

  6. #6
    Join Date
    Oct 2008
    Location
    Beijing China
    Posts
    77
    Thanks
    21
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: disable myself when clicked

    i created a test project like this:
    Qt Code:
    1. connect(ui.btn, SIGNAL(clicked()), this, SLOT(on_btn_clicked()));
    2. connect(ui.btn_2, SIGNAL(clicked()), this, SLOT(on_btn_2_clicked()));
    3. //...
    4. THIS::on_btn_clicked()
    5. {
    6. ui.btn->setEnabled(false);
    7. ui.btn_2->setEnabled(true);
    8. }
    9. THIS::on_btn_2_clicked()
    10. {
    11. ui.btn_2->setEnabled(false);
    12. ui.btn->setEnabled(true);
    13. }
    To copy to clipboard, switch view to plain text mode 

    and it works well. my connections are more complicated: like this:
    Qt Code:
    1. //calendar is a QCalendarWidget, currentPageChanged(int, int ) is it's signal, this signal is //often emitted the same time the QPushButton prevMonth and nextMonth is clicked
    2. //currentPageChagned(int,int ) is not triggered by the buttons' clicking
    3. //on_currentPage_changed(int, int) is my slot
    4. void MyWidget::on_currentPage_changed(int, int)
    5. {
    6. prevMonth->setEnabled(false);
    7. nextMonth->setEnabled(true);
    8. }
    To copy to clipboard, switch view to plain text mode 

  7. #7
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: disable myself when clicked

    Looks, like you could have a look at QWizard...

    Lykurg

Similar Threads

  1. How to disable NextButton in QWizard ?
    By litroncn in forum Qt Programming
    Replies: 3
    Last Post: 27th May 2008, 07:05
  2. Replies: 1
    Last Post: 21st April 2008, 22:43
  3. disable clicked() signal
    By mattia in forum Newbie
    Replies: 2
    Last Post: 27th February 2008, 10:27
  4. Replies: 10
    Last Post: 27th January 2006, 18:12

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.