PDA

View Full Version : Problem with setFont for a PushButton



arunvv
28th March 2008, 18:55
Hi All

I am having a problem with setFont for a PushButton.
I have designer GUI which have GroupBoxes, inside these GroupBoxes I have pushbuttons, where the pushbuttons font set to sanserif, 10, Bold.
On clicking these pushbuttons I need to change the text on PushButton as well as from bold to normal.
Here is the Code Snippet for changing font for a pushbutton which is not working for me.

code:

void MainWindow::function1()
{
....
....
QObject::connect(pushButton1, SIGNAL(clicked()), this, SLOT(changeProperties()));
}

void MainWindow::changeProperties()
{
.....
.....
/*QFont f declared in .h file*/
f.setPointSize(10);
f.setBold(false);
f.setWeight(5);
pushButton1->setFont(f);
pushButton1->setText("Changed Property");
}

I am expicitly trying to change the font properties to this pushButton widget, which should overwrite the its own properties for font or parent widget properties, if at all it is using.
I am not sure why it is not changing. Help me in this regard.

Thanks & Regards,
Arun

jpn
28th March 2008, 19:51
Does the slot get called? Does the button text change to "Changed Property"?

aamer4yu
28th March 2008, 21:08
are u at all calling the function function1() ???
does the connect statement gets executed at all ??

try to connect the signal and slot in constructor.

arunvv
28th March 2008, 22:16
Function1 is calling from another routine.
Yes the button text is changing to "ChangeProperty" text. But font is not changing to normal.
It is still in bold.

Thanks & Regards,
Arun.

arunvv
2nd April 2008, 20:30
Still facing the same problem, the text is changing to ChangeProperty but font is still in bold.
I am exactly doing as shown in above sample code.
Any help will be appreciated?

Thanks & Regards,
Arun.

jpn
2nd April 2008, 20:36
Could you attach a simple compilable test application which reproduces the problem?

arunvv
3rd April 2008, 19:13
Here is the attached compilable Test program which reproduces the problem for font.

Have a look at this program. Look for a solution on this problem.

Thanks & Regards,
Arun.

arunvv
3rd April 2008, 20:15
I wrote look for a solution in my earlier post, i had a typo there it is to mention looking forward for a solution of this problem.

Thanks & Regards,
Arun

jpn
3rd April 2008, 21:59
First of all, you should call QObject::connect() once. Do not call it again and again after every button push. You end up having tons of connections which means that your slots will get called more and more times after every button push. Secondly, what should I do the reproduce the problem? MainWindow::noChangeProperty() does not do anything at all...

arunvv
3rd April 2008, 23:24
Thanks for your reply.
My application has to change text and properties of a pushbutton.

Whenever I click on PushButton I have to change the text and property of a pushButton everytime I click on it, that is why I am connecting two slots for the same widget( i.e pushButton here) at different contexts.

Yes you are right, MainWindow::noChangeProperty() does not do anything, it is just a dummy button to distinguish with other two buttons, if at all the other two buttons changes their property.

To reproduce the problem, we have run the executable and click on propertyButton , which appears below of app, click on pushButtons on that page. On clicking 1st Button has to change the property from Bold to Normal, 2nd is dummy, 3rd is increase and decrease font size of that Button text.

Thanks & Regards,
Arun

jpn
4th April 2008, 07:58
Whenever I click on PushButton I have to change the text and property of a pushButton everytime I click on it, that is why I am connecting two slots for the same widget( i.e pushButton here) at different contexts.
But you establish one MORE connection EVERY time a button gets pressed. Notice that old connections remain.


To reproduce the problem, we have run the executable and click on propertyButton , which appears below of app, click on pushButtons on that page. On clicking 1st Button has to change the property from Bold to Normal, 2nd is dummy, 3rd is increase and decrease font size of that Button text.
Yes, they do change for me. Where's the problem? :)

arunvv
4th April 2008, 18:55
Thanks for reply.

I crosscompiled the code and copied the executable on to target board(PowerPC). When I run the executable it is not behaving as same as it behaves on desktop.

The font change from Bold to Normal, font increase doesn't happen on target board.

Where could be the cause?

Thanks & Regards,
Arun.

arunvv
8th April 2008, 00:35
Sorry to bother you all. It was my mistake, due to space contraint on target board, keeping 1 or 2 fonts, I removed rest of all the fonts, from font directory on target board.
So that is why the changes are not reflecting on target board.
When I copied some of the font files to font directory on target board it is working fine.
Thanks once again for you imm. replies and co-opeartion.

Thanks & Regards,
Arun.