Results 1 to 7 of 7

Thread: How to change the font and color of entire Qt application at runtime?

  1. #1
    Join Date
    May 2009
    Posts
    31
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default How to change the font and color of entire Qt application at runtime?

    Hi
    I am building a desktop application using Qt4. I have multiple forms and multiple types of widgets on those forms. Now i have a requirement to allow the user to change the color and font of entire application at run-time ( without restarting the application). I am really not sure how to achieve this. please suggest.

  2. #2
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to change the font and color of entire Qt application at runtime?

    void QApplication::setFont ( const QFont & font, const char * className = 0 ) [static]

    set to the qpplication of your font .. try this one ... but not sure ..
    "Behind every great fortune lies a crime" - Balzac

  3. #3
    Join Date
    May 2009
    Posts
    31
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to change the font and color of entire Qt application at runtime?

    hey it didnt worked...what i did is..i took one ui..and added one lable and pushbutton to it.
    On click of pushbutton i activated a slot "test()" in which i called QApplication::setFont().
    but it only chnages the color of pushButton not the entire form.

    my code is here:

    ColorMode::ColorMode(QWidget *parent)
    : QWidget(parent)
    {
    ui.setupUi(this);
    connect(ui.pushButton, SIGNAL(clicked()),this, SLOT(test()));
    }

    void ColorMode::test()
    {
    QFont font("Times", 15, QFont::Bold);
    QApplication::setFont(font);
    }

    any suggestions???

  4. #4
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to change the font and color of entire Qt application at runtime?

    Can you check that you slot is being called or not. Because this should work.

  5. #5
    Join Date
    May 2009
    Posts
    31
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to change the font and color of entire Qt application at runtime?

    hey..it checked..the slot is getting called for sure but its only changing the font of pushButton not for the label.

  6. #6
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to change the font and color of entire Qt application at runtime?

    Can you add more test buttons to your UI. So we can find out whats wrong with QLabel. Why only label's font is not getting changed.

  7. #7
    Join Date
    Jul 2009
    Posts
    139
    Thanks
    13
    Thanked 59 Times in 52 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to change the font and color of entire Qt application at runtime?

    Assumably, the label is not being updated because it is not being redrawn. Try, the updateAllWidgets function shown at QApplication::allWidgets

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.