Results 1 to 20 of 20

Thread: Disable button click

  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....)

  13. #12
    Join Date
    Feb 2011
    Location
    Latvia
    Posts
    139
    Thanks
    24
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Disable button click

    Quote Originally Posted by "BumbleBee" View Post
    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....)
    I'm not sure, but may be u should try
    Qt Code:
    1. if(btn[0]->property("x").toBool()==true && btn[1]->property("x").toBool()==true && btn[2]->property("x").toBool()==true)
    To copy to clipboard, switch view to plain text mode 

  14. #13
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Disable button click

    @Archa4: it does not make any difference, "true==true" and "false==true" evaluates to "true" and "false" respectively

    Show the code where you assign the "x" property, maybe you set it to "true" for all the buttons.

  15. #14
    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

    hi, bumblebee
    as stampede mentioned, you need to check your logic,
    And it gives a bug,when I press any btn,the msg appears
    its the logical issue.
    post setProperty code here

    bala

  16. #15
    Join Date
    Jan 2011
    Posts
    128
    Thanks
    2

    Default Re: Disable button click

    Well I did what BalaQT said,but I know realised that I didn't put the false after text...does it change things?

  17. #16
    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 know realised that I didn't put the false after text.does it change things?
    yes, that will correct your problem. if you still not able to solve the problem, post the setProperty code here.

    bala

  18. #17
    Join Date
    Jan 2011
    Posts
    128
    Thanks
    2

    Default Re: Disable button click

    Well,no I still get the bug...
    The code is:
    Qt Code:
    1. void TicTacToe::btnChangeX(QPushButton * x) //this function is run on every pressed button
    2. {
    3. x->setIcon(QIcon("ex.png"));
    4. x->setIconSize(QSize(64,64));
    5. x->disconnect();
    6. x->setProperty("x",false); //here is set it to x,false
    7. lbl->setText("<b>Turn : Player 2</b>");
    8. turn = false;
    9. }
    10.  
    11. bool TicTacToe::winX() //this function is called to every btn as well and checks for winner
    12. {
    13. if(btn[0]->property("x").toBool() && btn[1]->property("x").toBool() && btn[2]->property("x").toBool())
    14. {
    15.  
    16.  
    17. btn[0]->setText("x won 1"); //here is the bug,although i did click only btn[0],the winner text has appeared....
    18. for(i; i < 9; i++)
    19. btn[i]->disconnect();
    20.  
    21. return true;
    22. }
    To copy to clipboard, switch view to plain text mode 

  19. #18
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    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: Disable button click

    "x" is an existing property name. Use something that doesn't exist, like:
    Qt Code:
    1. button->setProperty("I need to read Qt documentation more", true);
    To copy to clipboard, switch view to plain text mode 
    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.


  20. #19
    Join Date
    Jan 2011
    Posts
    128
    Thanks
    2

    Default Re: Disable button click

    Quote Originally Posted by wysota View Post
    "x" is an existing property name. Use something that doesn't exist, like:
    Qt Code:
    1. button->setProperty("I need to read Qt documentation more", true);
    To copy to clipboard, switch view to plain text mode 
    Ok thanks it works now.

  21. #20
    Join Date
    Jan 2011
    Posts
    128
    Thanks
    2

    Default Re: Disable button click

    Can someone tell me,why the icon doesn't show in /Debug?
    At runtime it's ok,but

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.