qt - Custom ItemDelegate for QListView State_Selected -


i created customitemdelegate qstyleditemdelegate , i'm using paint() method give better qlistview.

if click on item, option.state never has state_selected, why that?
have selection model, single, row, , selection rectangle visible.

qdebug prints out these:

qstyle::state( "active | enabled" )  qstyle::state( "active | enabled | mouseover" )  

void syrupitemdelegate::paint(qpainter *painter, const qstyleoptionviewitem &option, const qmodelindex &index) const {      qrect rect = option.rect;    qdebug() << option.state;     if (option.state & qstyle::state_selected)    {        painter->drawroundedrect(option.rect,5,5);      painter->setpen(qpen(qpalette::highlightedtext ) );       if (option.state & qstyle::state_active)      {         painter->setbrush(qbrush(qpalette().highlight()));      } else             {                 //painter->setbrush(qbrush(qpalette().color(qpalette::inactive,                 //qpalette::highlight)));                 qlineargradient gradient(0, 0, 0, 100);                 gradient.setcolorat(0.0, qcolor(0,0,230));                 gradient.setcolorat(1.0, qcolor(250,250,250));                 painter->setbrush(gradient);             }       } else         painter->setpen(qpen(qpalette::text));     if ( !index.isvalid() )    return;     int row = index.row();    //  painter->save();    // painter->setrenderhint(qpainter::antialiasing,true);       qstring res =   index.sibling(row,syrupssqlmodel::syrup_nm_col_index).data().tostring();      qrectf rc(rect);      rc.settop(rc.top()+ padding);     rc.setleft(rc.left()+ 2* padding +  img_width);      qfont font = option.font;     font.setpointsize(font.pointsize()+4);     painter->setfont(font);      painter->drawtext(rc,res);      res = index.sibling(row,syrupssqlmodel::syrup_grp_col_index).data().tostring().tolower();      rc.settop(rect.top()+padding );     rc.setleft(rect.left()+padding );     painter->drawpixmap(rc.topleft(),qicon(":/prodgrp/"+res).pixmap(qsize(img_width,img_height)));      //syrupssqlmodel::formula_col_index:     //syrupssqlmodel::syrup_id_col_index:     //painter->restore();  } 

i'm using qt 5.0.2 32bit (win).

the problem in delegate class reimplemented editorevent() function badly. commented out sections , works.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -