+ Reply to Thread
Page 1 of 2 12 LastLast
Results 1 to 20 of 23

Thread: problem with Font changing

  1. #1
    Join Date
    Oct 2007
    Posts
    201
    Thanks
    19
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default problem with Font changing

    Hi All.
    In my application i'm changing the colour of window by applying .qss.
    but while applying default.qss UI's font is remaining un affected . but while applying Pagefold.qss font is getting changed from ariel-12 to default or some thing.
    i tried to solve like following
    QFont font("font: Arial", 12, QFont::System);
    qApp->setFont(font);
    bhut its changing whole application font.
    I need to change only QLabel font to arial-12.
    Can any body help me.
    Cheers,
    Phillip



    --- Please post the solution you got to solve your problem. It may help others.

  2. #2
    Join Date
    Feb 2008
    Posts
    47
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Post Re: problem with Font changing

    Try like QFont font("font: Arial", 12, QFont:referDefault);
    qApp->setFont(font);"

  3. #3
    Join Date
    Oct 2007
    Posts
    201
    Thanks
    19
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: problem with Font changing

    Quote Originally Posted by sonuani View Post
    Try like QFont font("font: Arial", 12, QFont:referDefault);
    qApp->setFont(font);"
    I tried like this. but its changing size of all the ui linked to main ui. But i wanna to change the letter font size of only one. and ui name is Base. How to do it?
    Cheers,
    Phillip



    --- Please post the solution you got to solve your problem. It may help others.

  4. #4
    Join Date
    Sep 2007
    Location
    Szczecin, Poland
    Posts
    153
    Thanks
    7
    Thanked 11 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: problem with Font changing

    Hi, why not using just

    Try like QFont font("font: Arial", 12, QFont:referDefault);
    ui.someLabel->setFont(font);

    or something like this to change font only for a widgets you need?


    qApp()->setFont will always change font for entire application and if i understood correctly, you need to change font only for several widgets, so you should use setFont method of those widgets.

    If you intend to change font in whole ui (not concrete widgets) u may use styleSheet.
    The simplest way to use a styleSheet is to open ui in qtdesigner, and paste something like

    QLabel{font: bold italic "Times New Roman"; font-size:16}

    in styleSheet Property of main ui's widget.
    See GrEEn (Graphics Effects Environment)
    http://sourceforge.net/project/platf...roup_id=232746
    a qt-based plugins oriented MDI image processing application(contains also qt plugins like styles & imageformats).

  5. #5
    Join Date
    Oct 2007
    Posts
    201
    Thanks
    19
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: problem with Font changing

    Quote Originally Posted by mchara View Post
    Hi, why not using just

    Try like QFont font("font: Arial", 12, QFont:referDefault);
    ui.someLabel->setFont(font);

    or something like this to change font only for a widgets you need?


    qApp()->setFont will always change font for entire application and if i understood correctly, you need to change font only for several widgets, so you should use setFont method of those widgets.

    If you intend to change font in whole ui (not concrete widgets) u may use styleSheet.
    The simplest way to use a styleSheet is to open ui in qtdesigner, and paste something like

    QLabel{font: bold italic "Times New Roman"; font-size:16}

    in styleSheet Property of main ui's widget.

    Thanx. I tried like this. but the programm is getting terminated abnormaly.
    Cheers,
    Phillip



    --- Please post the solution you got to solve your problem. It may help others.

  6. #6
    Join Date
    Sep 2007
    Location
    Szczecin, Poland
    Posts
    153
    Thanks
    7
    Thanked 11 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: problem with Font changing

    Which way did you tried?

    if u are setting widgets font with
    Try like QFont font("font: Arial", 12, QFont:referDefault);
    ui.someLabel->setFont(font);

    make sure it is done after setupUi() (in constructor) because setupUi() creates widgets in your ui - calling anything like ui.widget->method() before widget is initialized will cause crash.

    if this isn't a reason try give a bit more detailed description of crash you have.

    would be easier to find a solution if u would write anything about the problem
    so which method did u tried, when application crashes, where(maybe small part of code?), what debugger says etc.
    See GrEEn (Graphics Effects Environment)
    http://sourceforge.net/project/platf...roup_id=232746
    a qt-based plugins oriented MDI image processing application(contains also qt plugins like styles & imageformats).

  7. #7
    Join Date
    Oct 2007
    Posts
    201
    Thanks
    19
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: problem with Font changing

    Quote Originally Posted by mchara View Post
    Which way did you tried?

    if u are setting widgets font with
    Try like QFont font("font: Arial", 12, QFont:referDefault);
    ui.someLabel->setFont(font);

    make sure it is done after setupUi() (in constructor) because setupUi() creates widgets in your ui - calling anything like ui.widget->method() before widget is initialized will cause crash.

    if this isn't a reason try give a bit more detailed description of crash you have.

    would be easier to find a solution if u would write anything about the problem
    so which method did u tried, when application crashes, where(maybe small part of code?), what debugger says etc.
    I tried like following
    Ui::uiclassname ui; in .h
    in constructor
    setUp(this);
    and inside function
    i did like m_ui.centralwidget->setFont(font);

    and its terminating abruptly.
    Cheers,
    Phillip



    --- Please post the solution you got to solve your problem. It may help others.

  8. #8
    Join Date
    Sep 2007
    Location
    Szczecin, Poland
    Posts
    153
    Thanks
    7
    Thanked 11 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: problem with Font changing

    Let's be more precise, does your constuctor looks like this?

    // SomeClass constructor.
    SomeClass::SomeClass(QWidget *aParent)
    :QWidget(aParent)
    {
    ui.setupUi(this);
    QFont font("Arial", 16);
    ui.someWidget->setFont(font);
    ui.someWidget2->setFont(font);
    }


    because termination on ui.someWidget->setFont(font); call it's surely because ui.someWidget is not initialized correctly.

    and did you tried other way with styleSheet?
    See GrEEn (Graphics Effects Environment)
    http://sourceforge.net/project/platf...roup_id=232746
    a qt-based plugins oriented MDI image processing application(contains also qt plugins like styles & imageformats).

  9. #9
    Join Date
    Oct 2007
    Posts
    201
    Thanks
    19
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: problem with Font changing

    Quote Originally Posted by mchara View Post
    Let's be more precise, does your constuctor looks like this?

    // SomeClass constructor.
    SomeClass::SomeClass(QWidget *aParent)
    :QWidget(aParent)
    {
    ui.setupUi(this);
    QFont font("Arial", 16);
    ui.someWidget->setFont(font);
    ui.someWidget2->setFont(font);
    }


    because termination on ui.someWidget->setFont(font); call it's surely because ui.someWidget is not initialized correctly.

    and did you tried other way with styleSheet?
    I did like ui.setupUi(this);;
    QFont font("font: Arial", 12, QFont::PreferDefault);
    ui.centralwidget->setFont(font);
    Cheers,
    Phillip



    --- Please post the solution you got to solve your problem. It may help others.

  10. #10
    Join Date
    Oct 2007
    Posts
    201
    Thanks
    19
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: problem with Font changing

    Quote Originally Posted by mchara View Post
    Let's be more precise, does your constuctor looks like this?

    // SomeClass constructor.
    SomeClass::SomeClass(QWidget *aParent)
    :QWidget(aParent)
    {
    ui.setupUi(this);
    QFont font("Arial", 16);
    ui.someWidget->setFont(font);
    ui.someWidget2->setFont(font);
    }


    because termination on ui.someWidget->setFont(font); call it's surely because ui.someWidget is not initialized correctly.

    and did you tried other way with styleSheet?
    I did like ui.setupUi(this);;
    QFont font("font: Arial", 12, QFont::PreferDefault);
    ui.centralwidget->setFont(font);
    still same problem. font is not getting changed.
    Cheers,
    Phillip



    --- Please post the solution you got to solve your problem. It may help others.

  11. #11
    Join Date
    Sep 2007
    Location
    Szczecin, Poland
    Posts
    153
    Thanks
    7
    Thanked 11 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: problem with Font changing

    and what is centralWidget?
    See GrEEn (Graphics Effects Environment)
    http://sourceforge.net/project/platf...roup_id=232746
    a qt-based plugins oriented MDI image processing application(contains also qt plugins like styles & imageformats).

  12. #12
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    258
    Thanks
    22
    Thanked 18 Times in 15 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: problem with Font changing

    Quote Originally Posted by mchara View Post
    If you intend to change font in whole ui (not concrete widgets) u may use styleSheet.
    The simplest way to use a styleSheet is to open ui in qtdesigner, and paste something like
    It is possible to apply a Stylesheet to a single widget, or to a class of widgets, or to widgets with some certain properties:

    Qt Code:
    1. // applies to the QLabel object with the objectName "certain-label"
    2. QLabel#certain-label {
    3. color: blue;
    4. font-weight: bold;
    5. }
    To copy to clipboard, switch view to plain text mode 
    He could also call setStyleSheet on the widget to force a certain stylesheet for the widget after applying the other stylesheet on the application.

    Stylesheets can much more than this ...

  13. #13
    Join Date
    Dec 2007
    Location
    Austin, TX
    Posts
    40
    Thanks
    12
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: problem with Font changing

    Quote Originally Posted by phillip_Qt View Post
    I did like ui.setupUi(this);
    QFont font("font: Arial", 12, QFont::PreferDefault);
    ui.centralwidget->setFont(font);
    still same problem. font is not getting changed.
    Perhaps the problem is the font name here.... "font: Arial" is not "Arial"

    Vycke

  14. #14
    Join Date
    Oct 2007
    Posts
    201
    Thanks
    19
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: problem with Font changing

    Quote Originally Posted by vycke View Post
    Perhaps the problem is the font name here.... "font: Arial" is not "Arial"

    Vycke
    Sorry. i didnt understrand it. U mean instead of "font: Arial" i should write "Arial" only?
    Cheers,
    Phillip



    --- Please post the solution you got to solve your problem. It may help others.

  15. #15
    Join Date
    Sep 2007
    Location
    Szczecin, Poland
    Posts
    153
    Thanks
    7
    Thanked 11 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: problem with Font changing

    Quote Originally Posted by momesana View Post
    It is possible to apply a Stylesheet to a single widget, or to a class of widgets, or to widgets with some certain properties:

    Qt Code:
    1. // applies to the QLabel object with the objectName "certain-label"
    2. QLabel#certain-label {
    3. color: blue;
    4. font-weight: bold;
    5. }
    To copy to clipboard, switch view to plain text mode 
    He could also call setStyleSheet on the widget to force a certain stylesheet for the widget after applying the other stylesheet on the application.

    Stylesheets can much more than this ...
    Sure, but if i understood philip, he has several ui's in main window and want to change font only on several ui's so the best approach with stylesheets would be applying it on central widget of ui and let qt to propagate stylesheet to children.

    I tried to suggest such solution to philip, but he didn't checked it i think...
    So Philip, once again:
    try with

    ui.setupUi(this);
    QString styleSheet = "QLabel{font: bold italic "Arial"; font-size:16}";
    ui.centralwidget->setStyleSheet(styleSheet);
    See GrEEn (Graphics Effects Environment)
    http://sourceforge.net/project/platf...roup_id=232746
    a qt-based plugins oriented MDI image processing application(contains also qt plugins like styles & imageformats).

  16. #16
    Join Date
    Oct 2007
    Posts
    201
    Thanks
    19
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: problem with Font changing

    Quote Originally Posted by momesana View Post
    It is possible to apply a Stylesheet to a single widget, or to a class of widgets, or to widgets with some certain properties:

    Qt Code:
    1. // applies to the QLabel object with the objectName "certain-label"
    2. QLabel#certain-label {
    3. color: blue;
    4. font-weight: bold;
    5. }
    To copy to clipboard, switch view to plain text mode 
    He could also call setStyleSheet on the widget to force a certain stylesheet for the widget after applying the other stylesheet on the application.

    Stylesheets can much more than this ...
    Hi i tried like
    QLabel#m_funktion1
    {
    font : Arial 12x;
    }

    But getting compilation error.
    and also SetStyleSheet(QLabel#m_funktion1{font: Arial 12x}");
    is not working.
    Cheers,
    Phillip



    --- Please post the solution you got to solve your problem. It may help others.

  17. #17
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,425
    Thanks
    8
    Thanked 326 Times in 311 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: problem with Font changing

    Why dont u just set the stylesheet to the label u want ??

    my_label->setStyleSheet("font:Arial ; font-size: 12px");

  18. #18
    Join Date
    Sep 2007
    Location
    Szczecin, Poland
    Posts
    153
    Thanks
    7
    Thanked 11 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: problem with Font changing

    try with


    ui.setupUi(this);
    QString styleSheet = "QLabel{font: bold italic "Arial"; font-size:16}";
    ui.centralwidget->setStyleSheet(styleSheet);

    and you can also paste QLabel{font: bold italic "Arial"; font-size:16} in qt designer (styleSheet property of main widget) - tested it, works.

    Try to use styleSheet as is and if it will work adjust it to you need - then you'll be sure that problem is with approach or with stylesheet itself.
    See GrEEn (Graphics Effects Environment)
    http://sourceforge.net/project/platf...roup_id=232746
    a qt-based plugins oriented MDI image processing application(contains also qt plugins like styles & imageformats).

  19. #19
    Join Date
    Oct 2007
    Posts
    201
    Thanks
    19
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: problem with Font changing

    Quote Originally Posted by mchara View Post
    Sure, but if i understood philip, he has several ui's in main window and want to change font only on several ui's so the best approach with stylesheets would be applying it on central widget of ui and let qt to propagate stylesheet to children.

    I tried to suggest such solution to philip, but he didn't checked it i think...
    So Philip, once again:
    try with

    ui.setupUi(this);
    QString styleSheet = "QLabel{font: bold italic "Arial"; font-size:16}";
    ui.centralwidget->setStyleSheet(styleSheet);
    Thanx mchara very much. U are absolutly right. I've so many UIs. But i need to change only ceratin UI's font. Actually i'm chaning the colour by applyng qss file. there i "ve
    QLabel
    {
    color : white;
    font : Arial 12x;
    }
    But this one is not chaning the size.
    Inside code as u told i"ve added
    QString styleSheet ( "QLabel{font: bold italic; Arial; font-size:16}");
    ui.centralwidget->setStyleSheet(styleSheet);

    But this also not working.
    Cheers,
    Phillip



    --- Please post the solution you got to solve your problem. It may help others.

  20. #20
    Join Date
    Oct 2007
    Posts
    201
    Thanks
    19
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: problem with Font changing

    Quote Originally Posted by aamer4yu View Post
    Why dont u just set the stylesheet to the label u want ??

    my_label->setStyleSheet("font:Arial ; font-size: 12px");
    Thanx aamer. I tried like so, still same problem.
    Cheers,
    Phillip



    --- Please post the solution you got to solve your problem. It may help others.

+ Reply to Thread

Similar Threads

  1. Replies: 1
    Last Post: 25th December 2007, 10:35
  2. QMainWindow: problem changing centralWidget
    By Caius AĆ©robus in forum Qt Programming
    Replies: 6
    Last Post: 4th October 2007, 13:00
  3. changing QLabel font size(label created on the graphicsView)
    By maverick_pol in forum Qt Programming
    Replies: 11
    Last Post: 17th August 2007, 08:36
  4. Font Problem Porting from Windows to Linux
    By rajeshs in forum Qt Programming
    Replies: 1
    Last Post: 13th July 2007, 10:25
  5. Font Problem
    By prakash in forum Qt Programming
    Replies: 6
    Last Post: 13th April 2006, 16:53

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