i'd know if it's possible store qpushbutton in qvariant. more precisely, trying use in qstandarditemmodel function setdata
. here's want :
qpushbutton* button = new qpushbutton("update"); setdata(index(0, 0), "button"); setdata(index(0, 1), button);
but obviously, doesn't work tried :
qvariant variant; variant.setvalue(button); setdata(index(0, 1), qvariant::fromvalue(variant));
and it's not working either. i'd without using qtableview (i know there setindexwidget in kind of view).
thanks in advance!
qvariant
needs metatype types can store. qt provides set of commonly used types, can extend it, using q_declare_metatype
macro:
#include <qpushbutton> #include <qvariant> q_declare_metatype(qpushbutton*) void foo() { qpushbutton *b1 = new qpushbutton("button"); qvariant v = qvariant::fromvalue(b1); qpushbutton *b2 = qvariant_cast<qpushbutton*>(v); }
note: if want use custom metatypes in queued slot connections or qmetamethod
, have call qregistermetatype<qpushbutton*>()
Comments
Post a Comment