Changing QIcon size in QStandardItemModel -
i trying make qtableview/qstandarditemmodel arbitrary sized qicons. in mwe below, have changed height of row using delegate. can't figure out how make use larger icon size in larger row. appreciated. note rows can same height long can set height. example, how make icons 50x50 in example below.
#include <qtgui> #include "test.h" ////////////////////////////////////////////////////////////////////////// // test.h file: //#include <qtgui> // //class mainwindow : public qmainwindow { // q_object // // public: // mainwindow(qwidget *parent = 0); //}; class itemdelegate : public qitemdelegate { public: itemdelegate() {} qsize sizehint ( const qstyleoptionviewitem &, const qmodelindex & ) const { return qsize(50,50); } }; mainwindow::mainwindow(qwidget *parent) : qmainwindow(parent) { qimage iconimage(100, 100, qimage::format_rgb32); iconimage.fill(0xf08080); const int array_height = 2; const int array_width = 2; qstandarditemmodel *model = new qstandarditemmodel( array_height, array_width ); model->setheaderdata( 1, qt::horizontal, qstring("icon") ); model->setheaderdata( 2, qt::horizontal, qstring("text") ); (int yy=0; yy < array_height; yy++ ) { qstandarditem *newiconitem = new qstandarditem; newiconitem->seticon( qpixmap::fromimage( iconimage ) ); model->setitem( yy, 0, newiconitem ); qstandarditem *newtypeitem = new qstandarditem( qstring("foo") ); model->setitem( yy, 1, newtypeitem ); } qtableview *table = new qtableview; itemdelegate *delegate = new itemdelegate(); table->setmodel(model); table->setitemdelegate(delegate); table->setselectionmode(qabstractitemview::singleselection); table->setselectionbehavior(qabstractitemview::selectrows); table->verticalheader()->setvisible(false); table->verticalscrollbar()->setvisible(false); table->resizerowstocontents(); table->resizecolumnstocontents(); qheaderview *headerview = table->horizontalheader(); headerview->setstretchlastsection(true); setcentralwidget( table ); } int main( int argc, char *argv[] ) { qapplication app(argc, argv); mainwindow win; win.show(); return app.exec(); }
Comments
Post a Comment