Results 1 to 5 of 5

Thread: font can not be changed

  1. #1
    Join Date
    Jul 2007
    Location
    Noida
    Posts
    46
    Thanks
    7
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default font can not be changed

    hi,
    I have created customized item which inherits from QGraphicsItem.I am drawing some text on such item by implementing paint() event. ( I can not use QGraphicsTextItem)
    To change text font i have kept m_textFont member vaiable.
    For this item i have created font toolbar from where i can change the font of the text.

    From toolbar when i change the font i am calling public method of my customized item where i am assigning selected font to m_textFont.

    But the problem is item does not allow me to assign selected font and it throws exception.

    Tell if i am doing anything wrong and what would be the correct way.

    Regards,
    Ashish
    Ashish Kumar Saryar

  2. #2
    Join Date
    Jan 2007
    Posts
    92
    Thanks
    14
    Thanked 1 Time in 1 Post

    Default Re: font can not be changed

    Did u try something like this inside the paint( ) function? So you can set the appropriate font.

    Qt Code:
    1. painter->setFont(QFont("Times", 18));
    2. QRectF rect(10.0, 20.0, 80.0, 60.0);
    3. painter->drawText(rect, Qt::AlignCenter, ("Qt by\nTrolltech"));
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jul 2007
    Location
    Noida
    Posts
    46
    Thanks
    7
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: font can not be changed

    I think you have not undertood my problem.

    If i need to chage the font at runtime then your code will not allow me that.Because you have hardcoded the font.

    I already mentioned that there is toolbar which has QFontComboBox which shows list of font.Selected font from this combobox is then i am trying to give it to my customized item.
    e.g.

    Qt Code:
    1. void customizedItem::setItemFont(QFont ft) // which is called from font toolbar
    2. {
    3. m_textFont = ft ; // at this point i m getting exception which i have pasted below
    4. }
    5.  
    6.  
    7. #if defined(QT_NO_EXCEPTIONS)
    8. receiver->qt_metacall(QMetaObject::InvokeMetaMethod, method, argv ? argv : empty_argv);
    9. #else
    10. try
    11. {
    12. receiver->qt_metacall(QMetaObject::InvokeMetaMethod, method, argv ? argv : empty_argv);
    13. }
    14. catch (...)
    15. {
    16. locker.relock();
    17.  
    18. QObjectPrivate::resetCurrentSender(receiver, &currentSender, previousSender);
    19.  
    20. --connectionLists->inUse;
    21. Q_ASSERT(connectionLists->inUse >= 0);
    22. if (connectionLists->orphaned && !connectionLists->inUse)
    23. delete connectionLists;
    24. throw;
    25. }
    26. #endif
    To copy to clipboard, switch view to plain text mode 

    Note : even i am unable to modify any member variable my cusomized item in this setItemFont() method . i.e same exeption as above

    Is anything i doing wrong.
    Thanks
    Last edited by jpn; 28th May 2008 at 13:11. Reason: missing [code] tags
    Ashish Kumar Saryar

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

    Default Re: font can not be changed

    Quote Originally Posted by ashishsaryar View Post
    I think you have not understood my problem.

    If i need to chage the font at runtime then your code will not allow me that.Because you have hardcoded the font.

    Is anything i doing wrong.
    Thanks
    I think what user_mail07 meant was (using your setItemFont() function to set the font):
    Qt Code:
    1. painter->setFont(m_textFont);
    2. QRectF rect(10.0, 20.0, 80.0, 60.0); // or whatever box you need
    3. painter->drawText(rect, Qt::AlignCenter, ("Qt by\nTrolltech")); // or whatever text you need
    To copy to clipboard, switch view to plain text mode 

    Vycke

  5. #5
    Join Date
    Jul 2007
    Location
    Noida
    Posts
    46
    Thanks
    7
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: font can not be changed

    Sorry ...I got my mistake .

    I did nt set Item Flag to be IsItemFocusable .

    This is the reason , i am unable to modify any member variable of this Class .
    Ashish Kumar Saryar

Similar Threads

  1. Font size of a spinbox
    By SailinShoes in forum Qt Programming
    Replies: 6
    Last Post: 5th May 2008, 14:29
  2. Font size calculation when painting in a QImage
    By Ishark in forum Qt Programming
    Replies: 3
    Last Post: 15th July 2007, 22:22
  3. Automatic font selection
    By NTwoO in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 27th April 2007, 12:40
  4. Font not Antialiasing
    By ChasW in forum Qt Programming
    Replies: 6
    Last Post: 21st January 2007, 18:12
  5. Qt renders wrong font
    By durbrak in forum Qt Programming
    Replies: 8
    Last Post: 2nd November 2006, 14:36

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.