Q_OBJECT
public:
MyListView
( QWidget * parent
= 0,
const char * name
= 0, WFlags f
= 0 );
private:
QListViewItem *_highlighted;
protected:
void drawContentsOffset
( QPainter * p,
int ox,
int oy,
int cx,
int cy,
int cw,
int ch
);
private slots:
void highlightItem(QListViewItem *);
}
MyListView
( QWidget * parent,
const char * name, WFlags f
) : QListView ( parent, name, f
) { _highlighted = 0;
connect(this, SIGNAL(onItem(QListViewItem*)), this, SLOT(highlightitem(QListViewItem*)));
}
void MyListView::highlightItem(QListViewItem *item){
_highlighted = item;
updateContents();
}
void MyListView
::drawContentsOffset ( QPainter * p,
int ox,
int oy,
int cx,
int cy,
int cw,
int ch
){ // reimplement from QListView (for example copy & paste)
// there should be some loop there which iterates over items
// I assume that 'item' is a pointer to an item currently drawn
QColorGroup cg = //...
QColorGroup storecg = cg;
if(item==_highlighted){
cg.
setColor(QColorGroup
::Base,
QColor(255,
255,
0));
// could be Background not Base }
// do some stuff here probably
// eventually there will be a call like so:
item->paintCell(p, cg, ...);
// then you can restore the background
if(item==_highlighted){
cg = storecg;
}
// ...
}
class MyListView : public QListView {
Q_OBJECT
public:
MyListView ( QWidget * parent = 0, const char * name = 0, WFlags f = 0 );
private:
QListViewItem *_highlighted;
protected:
void drawContentsOffset ( QPainter * p, int ox, int oy, int cx, int cy, int cw, int ch );
private slots:
void highlightItem(QListViewItem *);
}
MyListView ( QWidget * parent, const char * name, WFlags f) : QListView ( parent, name, f ) {
_highlighted = 0;
connect(this, SIGNAL(onItem(QListViewItem*)), this, SLOT(highlightitem(QListViewItem*)));
}
void MyListView::highlightItem(QListViewItem *item){
_highlighted = item;
updateContents();
}
void MyListView::drawContentsOffset ( QPainter * p, int ox, int oy, int cx, int cy, int cw, int ch ){
// reimplement from QListView (for example copy & paste)
// there should be some loop there which iterates over items
// I assume that 'item' is a pointer to an item currently drawn
QColorGroup cg = //...
QColorGroup storecg = cg;
if(item==_highlighted){
cg.setColor(QColorGroup::Base, QColor(255,255,0)); // could be Background not Base
}
// do some stuff here probably
// eventually there will be a call like so:
item->paintCell(p, cg, ...);
// then you can restore the background
if(item==_highlighted){
cg = storecg;
}
// ...
}
To copy to clipboard, switch view to plain text mode
Bookmarks