Results 1 to 13 of 13

Thread: Problem with setFont for a PushButton

  1. #1
    Join Date
    Jun 2006
    Location
    San Diego, USA
    Posts
    95
    Thanks
    9
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Problem with setFont for a PushButton

    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:
    Qt Code:
    1. void MainWindow::function1()
    2. {
    3. ....
    4. ....
    5. QObject::connect(pushButton1, SIGNAL(clicked()), this, SLOT(changeProperties()));
    6. }
    7.  
    8. void MainWindow::changeProperties()
    9. {
    10. .....
    11. .....
    12. /*QFont f declared in .h file*/
    13. f.setPointSize(10);
    14. f.setBold(false);
    15. f.setWeight(5);
    16. pushButton1->setFont(f);
    17. pushButton1->setText("Changed Property");
    18. }
    To copy to clipboard, switch view to plain text mode 
    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
    Last edited by jpn; 28th March 2008 at 18:48. Reason: missing [code] tags

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Problem with setFont for a PushButton

    Does the slot get called? Does the button text change to "Changed Property"?
    J-P Nurmi

  3. #3
    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: Problem with setFont for a PushButton

    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.
    Last edited by aamer4yu; 28th March 2008 at 20:32.

  4. #4
    Join Date
    Jun 2006
    Location
    San Diego, USA
    Posts
    95
    Thanks
    9
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Problem with setFont for a PushButton

    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.

  5. #5
    Join Date
    Jun 2006
    Location
    San Diego, USA
    Posts
    95
    Thanks
    9
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Problem with setFont for a PushButton

    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.

  6. #6
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Problem with setFont for a PushButton

    Could you attach a simple compilable test application which reproduces the problem?
    J-P Nurmi

  7. #7
    Join Date
    Jun 2006
    Location
    San Diego, USA
    Posts
    95
    Thanks
    9
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Problem with setFont for a PushButton

    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.
    Attached Files Attached Files

  8. #8
    Join Date
    Jun 2006
    Location
    San Diego, USA
    Posts
    95
    Thanks
    9
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Problem with setFont for a PushButton

    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

  9. #9
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Problem with setFont for a PushButton

    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...
    J-P Nurmi

  10. #10
    Join Date
    Jun 2006
    Location
    San Diego, USA
    Posts
    95
    Thanks
    9
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Problem with setFont for a PushButton

    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

  11. #11
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Problem with setFont for a PushButton

    Quote Originally Posted by arunvv View Post
    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?
    J-P Nurmi

  12. #12
    Join Date
    Jun 2006
    Location
    San Diego, USA
    Posts
    95
    Thanks
    9
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Problem with setFont for a PushButton

    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.

  13. #13
    Join Date
    Jun 2006
    Location
    San Diego, USA
    Posts
    95
    Thanks
    9
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Problem with setFont for a PushButton

    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.

Similar Threads

  1. Pushbutton sizing problem on Mac OS
    By will49 in forum Qt Programming
    Replies: 5
    Last Post: 3rd October 2007, 21:26
  2. PushButton height problem
    By impeteperry in forum Qt Tools
    Replies: 4
    Last Post: 28th January 2007, 20:36
  3. Replies: 16
    Last Post: 7th March 2006, 15:57

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.