Results 1 to 20 of 20

Thread: Disable button click

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2011
    Posts
    128
    Thanks
    2

    Question Disable button click

    How would it be possible to make a button not aceept clicks?
    I have clicked it once and set an icon to it..and now I don't want to disable it(because icon goes grey >.<),but I want to keep it enabled,with no clicks..

    Thank you.

  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: Disable button click

    You can disconnect or block signals.

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

    "BumbleBee" (25th March 2011)

  4. #3
    Join Date
    Jan 2011
    Posts
    128
    Thanks
    2

    Default Re: Disable button click

    Yeah,I disconnected it!

    Thank you.

  5. #4
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Disable button click

    Just a note - that sort of behavior has the potential to be very frustrating to users. Clicking a button that looks and behaves as if it is active and having it do nothing indicates that something isn't right, that the program has failed in some way.

    I'd suggest changing the button's appearance in some way to indicate that it has fulfilled its one-shot role.

  6. #5
    Join Date
    Jan 2011
    Posts
    128
    Thanks
    2

    Default Re: Disable button click

    Quote Originally Posted by SixDegrees View Post
    Just a note - that sort of behavior has the potential to be very frustrating to users. Clicking a button that looks and behaves as if it is active and having it do nothing indicates that something isn't right, that the program has failed in some way.

    I'd suggest changing the button's appearance in some way to indicate that it has fulfilled its one-shot role.
    Well,you have a point.
    But that would be so in a normal program,while I'm creating a tic tac toe game,so I need to disable a used button.Won't the user understand that the button is used,so it's not working?

  7. #6
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Disable button click

    That's a call you'll have to make for yourself. There are always exceptions. As a general rule, though, it's often a bad idea to tinker with normal GUI behaviors.

  8. #7
    Join Date
    Jan 2011
    Posts
    128
    Thanks
    2

    Default Re: Disable button click

    Hey guys,how can I check for winner?
    I cannot check,because buttons have no value(or sth..)..so I'd do: if(btn[0] == x && btn[1] == x && btn[2] == x )

    Thank you.

  9. #8
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Disable button click

    There are several approaches. First, you can derive a trivial extension of QPushButton that can be assigned a value depending on state, row and column or whatever.

    Better would be to completely sever any connection between application logic and application UI, and have the buttons manipulate some underlying data structure that ultimately drives game logic. This makes it easy to replace the UI with a different one while leaving the rest of the program unchanged. For more information, look up the "Model/View/Controller".

  10. #9
    Join Date
    Jan 2011
    Posts
    128
    Thanks
    2

    Default Re: Disable button click

    Quote Originally Posted by SixDegrees View Post
    There are several approaches. First, you can derive a trivial extension of QPushButton that can be assigned a value depending on state, row and column or whatever.

    Better would be to completely sever any connection between application logic and application UI, and have the buttons manipulate some underlying data structure that ultimately drives game logic. This makes it easy to replace the UI with a different one while leaving the rest of the program unchanged. For more information, look up the "Model/View/Controller".
    When you say subclass(derive) and assign values,do you mean,like putting the array of buttons in that class(as objects) and add another int variable,which will be assigned 1 when buttons gets 'x' icon and o when it gets 'o' icons?

  11. #10
    Join Date
    Aug 2009
    Location
    coimbatore,India
    Posts
    314
    Thanks
    37
    Thanked 47 Times in 43 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Disable button click

    I cannot check,because buttons have no value(or sth..)
    you can use setProperty to set a "x" and "0" and access it by callling property

    it will be like ,
    when you set property
    btn[0]->setProperty("marked",false);

    when you access, if(btn[0]->property("marked").toBool())

    hope it helps
    bala
    Last edited by BalaQT; 26th March 2011 at 16:15. Reason: ex code added

  12. #11
    Join Date
    Jan 2011
    Posts
    128
    Thanks
    2

    Default Re: Disable button click

    Quote Originally Posted by BalaQT View Post
    you can use setProperty to set a "x" and "0" and access it by callling property

    it will be like ,
    when you set property
    btn[0]->setProperty("marked",false);

    when you access, if(btn[0]->property("marked").toBool())

    hope it helps
    bala
    My code is:
    Qt Code:
    1. if(btn[0]->property("x").toBool() && btn[1]->property("x").toBool() && btn[2]->property("x").toBool())
    2. //msgBox here.;
    To copy to clipboard, switch view to plain text mode 

    And it gives a bug,when I press any btn,the msg appears(i mean without completing a line of Xs..it skips everything on first click....)

Similar Threads

  1. Disable right mouse click on QAction
    By stefan in forum Newbie
    Replies: 13
    Last Post: 15th May 2013, 22:04
  2. How to disable mouse click over a QSplashScreen
    By graciano in forum Qt Programming
    Replies: 2
    Last Post: 8th November 2009, 16:02
  3. Replies: 3
    Last Post: 25th August 2009, 22:35
  4. QDockWidget: disable double click on title bar
    By ElectroQt in forum Qt Programming
    Replies: 2
    Last Post: 9th October 2008, 22:22
  5. Replies: 4
    Last Post: 31st August 2006, 12:11

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.