July 24, 2012

Mr.Universe Mr.Universe
Ant Farmer
60 posts

[solved]QVariant to QFont

 

Hello,
can anybody tell me how I can cast a QVariant to QFont?
This QVariant was returned from QAbstractItemView::data(index, Qt::FontRole) and should contain a valid Font…
Unfortunately I have to use Qt 4.5.2, where the member QVariant::toFont() (or the corresponding constructor) does not exist.
Any idea?

2 replies

July 24, 2012

Andre Andre
Area 51 Engineer
6031 posts

Sure:

  1. QFont theFont = qvariant_cast<QFont>(myVariant);

or

  1. QFont theFont = myVariant.value<QFont>();

 Signature 

Looking for Qt developers to join our team @ i-Optics: https://qt-project.org/forums/viewthread/25393/

July 25, 2012

Mr.Universe Mr.Universe
Ant Farmer
60 posts

Works!
thanks

 
  ‹‹ Qt SDK discontinued?      Problems with compilation ››

You must log in to post a reply. Not a member yet? Register here!