Results 1 to 12 of 12

Thread: changing QLabel font size(label created on the graphicsView)

  1. #1
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default changing QLabel font size(label created on the graphicsView)

    HI guys,

    I have created QLabel on the QGraphicsView widget, but I can't set the font size. HEre is the code I am using, and it's not changing the font( I have a standardt (point 12) font);
    Qt Code:
    1. m_textOCOG = new QLabel(m_view->viewport());
    2. QFont font("Helvetica", 20, QFont::Bold);
    3. m_textOCOG->setFont(font);
    4. m_textOCOG->setText("COG: N A");
    5. m_textOCOG->setGeometry(452,10,100,20);
    6. m_textOCOG->setFrameStyle(QFrame::NoFrame);
    7. m_textOCOG->show();
    To copy to clipboard, switch view to plain text mode 

    Any idea? Thank you beforehand.

    Maverick
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

  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: changing QLabel font size(label created on the graphicsView)

    I just tested and it works for me. What does this output?
    Qt Code:
    1. QFontInfo info(font);
    2. qDebug() << info.family() << info.pointSize();
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  3. #3
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: changing QLabel font size(label created on the graphicsView)

    easy question:
    What should there be included to use qDebug? Anything added to the .pro file?

    Maverick
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

  4. #4
    Join Date
    Aug 2006
    Location
    Bangalore,India
    Posts
    419
    Thanks
    37
    Thanked 53 Times in 40 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: changing QLabel font size(label created on the graphicsView)

    #include <QtCore/QtDebug>
    The biggest difference between time and space is that you can't reuse time.
    -- Merrick Furst

  5. #5
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: changing QLabel font size(label created on the graphicsView)

    "Helvetica" 20

    This is the result.

    Maverick
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

  6. #6
    Join Date
    Aug 2006
    Location
    Bangalore,India
    Posts
    419
    Thanks
    37
    Thanked 53 Times in 40 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: changing QLabel font size(label created on the graphicsView)

    This is what was expected right ?
    The biggest difference between time and space is that you can't reuse time.
    -- Merrick Furst

  7. #7
    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: changing QLabel font size(label created on the graphicsView)

    This works, right?
    Qt Code:
    1. // main.cpp
    2. #include <QtGui>
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6. QApplication a(argc, argv);
    7. QLabel* label = new QLabel("COG: N A", view.viewport());
    8. label->setFont(QFont("Helvetica", 20, QFont::Bold));
    9. view.show();
    10. return a.exec();
    11. }
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  8. #8
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: changing QLabel font size(label created on the graphicsView)

    Yes it works . Not working in "my" view though.

    Maverick
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

  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: changing QLabel font size(label created on the graphicsView)

    Then, are you by any chance adjusting the font of the label anywhere else? And which other widgets do you set a font explicitly?
    J-P Nurmi

  10. The following user says thank you to jpn for this useful post:

    maverick_pol (16th August 2007)

  11. #10
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: changing QLabel font size(label created on the graphicsView)

    I've tried changing the font size in the other "part" of the program and it works fine.
    Give me 10 minutes and I will find the stupid mistake of mine.

    All in all thank you for help.

    Maverick


    It looks like ... when I try to set the font outside the constructor it works fine. While my function setting the font is placed inside the constructor there is no "change in display" even though the qDebug says it has changed.
    Last edited by maverick_pol; 16th August 2007 at 14:59.
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

  12. #11
    Join Date
    Aug 2006
    Location
    Bangalore,India
    Posts
    419
    Thanks
    37
    Thanked 53 Times in 40 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: changing QLabel font size(label created on the graphicsView)

    Are you by any chance using static or global instances of QFont ?
    The biggest difference between time and space is that you can't reuse time.
    -- Merrick Furst

  13. #12
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: changing QLabel font size(label created on the graphicsView)

    I am using an (auto) local font object.

    Maverick
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

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.