PDA

View Full Version : Disable button click



"BumbleBee"
25th March 2011, 18:56
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.

Zlatomir
25th March 2011, 19:06
You can disconnect (http://doc.qt.nokia.com/latest/qobject.html#disconnect) or block (http://doc.qt.nokia.com/latest/qobject.html#blockSignals) signals.

"BumbleBee"
25th March 2011, 19:35
Yeah,I disconnected it!

Thank you.

SixDegrees
25th March 2011, 19:45
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.

"BumbleBee"
26th March 2011, 05:30
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?:o

SixDegrees
26th March 2011, 10:12
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.

"BumbleBee"
26th March 2011, 12:49
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.

SixDegrees
26th March 2011, 13:37
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".

"BumbleBee"
26th March 2011, 15:24
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?

BalaQT
26th March 2011, 16:02
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

"BumbleBee"
26th March 2011, 16:34
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:

if(btn[0]->property("x").toBool() && btn[1]->property("x").toBool() && btn[2]->property("x").toBool())
//msgBox here.;

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

Archa4
28th March 2011, 10:09
My code is:

if(btn[0]->property("x").toBool() && btn[1]->property("x").toBool() && btn[2]->property("x").toBool())
//msgBox here.;

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

if(btn[0]->property("x").toBool()==true && btn[1]->property("x").toBool()==true && btn[2]->property("x").toBool()==true)

stampede
28th March 2011, 10:34
@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.

BalaQT
28th March 2011, 10:44
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

"BumbleBee"
28th March 2011, 12:51
Well I did what BalaQT said,but I know realised that I didn't put the false after text...does it change things?

BalaQT
28th March 2011, 12:59
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

"BumbleBee"
28th March 2011, 16:21
Well,no I still get the bug...
The code is:

void TicTacToe::btnChangeX(QPushButton * x) //this function is run on every pressed button
{
x->setIcon(QIcon("ex.png"));
x->setIconSize(QSize(64,64));
x->disconnect();
x->setProperty("x",false); //here is set it to x,false
lbl->setText("<b>Turn : Player 2</b>");
turn = false;
}

bool TicTacToe::winX() //this function is called to every btn as well and checks for winner
{
if(btn[0]->property("x").toBool() && btn[1]->property("x").toBool() && btn[2]->property("x").toBool())
{


btn[0]->setText("x won 1"); //here is the bug,although i did click only btn[0],the winner text has appeared....
for(i; i < 9; i++)
btn[i]->disconnect();

return true;
}

wysota
28th March 2011, 16:54
"x" is an existing property name. Use something that doesn't exist, like:

button->setProperty("I need to read Qt documentation more", true);

"BumbleBee"
28th March 2011, 19:46
"x" is an existing property name. Use something that doesn't exist, like:

button->setProperty("I need to read Qt documentation more", true);

Ok thanks it works now.

"BumbleBee"
30th March 2011, 13:16
Can someone tell me,why the icon doesn't show in /Debug?
At runtime it's ok,but http://i110.photobucket.com/albums/n112/4826721/firefox3/windows-exeicon.png