PDA

View Full Version : font can not be changed



ashishsaryar
27th May 2008, 12:50
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

user_mail07
27th May 2008, 18:14
Did u try something like this inside the paint( ) function? So you can set the appropriate font.


painter->setFont(QFont("Times", 18));
QRectF rect(10.0, 20.0, 80.0, 60.0);
painter->drawText(rect, Qt::AlignCenter, ("Qt by\nTrolltech"));

ashishsaryar
28th May 2008, 07:35
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.


void customizedItem::setItemFont(QFont ft) // which is called from font toolbar
{
m_textFont = ft ; // at this point i m getting exception which i have pasted below
}


#if defined(QT_NO_EXCEPTIONS)
receiver->qt_metacall(QMetaObject::InvokeMetaMethod, method, argv ? argv : empty_argv);
#else
try
{
receiver->qt_metacall(QMetaObject::InvokeMetaMethod, method, argv ? argv : empty_argv);
}
catch (...)
{
locker.relock();

QObjectPrivate::resetCurrentSender(receiver, &currentSender, previousSender);

--connectionLists->inUse;
Q_ASSERT(connectionLists->inUse >= 0);
if (connectionLists->orphaned && !connectionLists->inUse)
delete connectionLists;
throw;
}
#endif


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

vycke
28th May 2008, 13:46
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):


painter->setFont(m_textFont);
QRectF rect(10.0, 20.0, 80.0, 60.0); // or whatever box you need
painter->drawText(rect, Qt::AlignCenter, ("Qt by\nTrolltech")); // or whatever text you need


Vycke

ashishsaryar
28th May 2008, 15:32
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 .