Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 4

Qt-interest Archive, March 2002
owner-drawn controls?


Message 1 in thread

hey all,

I've been working with the QT eval for Windows for the last week or so, and
have not been able to find anything about implementing owner drawn controls.
I also looked in the list archives, but no mention of it, which I find
bizarre.

So anyway, what I'm trying to do is setup a QListView as an owner-drawn list
view, so that when a user selects a row, the whole row gets highlighted
(like in a list box) instead of just the first column.

I have a class inherited from QListView, and have implemented the paintEvent
method. I have the following code,

void CMyList::paintEvent( QPaintEvent * p_pevent)
{
   QPainter* painter = new QPainter( this );

   QRect rectSelected;
   QBrush brush( QColor(122, 122, 255));
   painter->fillRect( rectSelected = contentsRect(), brush);

   QListViewItem *pitem = selectedItem();
   if (pitem != NULL)
   {
      rectSelected = itemRect( pitem);
      rectSelected.setTop( rectSelected.top() + 16);
      rectSelected.setBottom( rectSelected.bottom() + 16);
      QBrush brush(::GetSysColor( COLOR_HIGHLIGHT)); // blue
      painter->fillRect( rectSelected, brush);
   }
}

this code doesn't seem to do anything except paint a small red box to the
top left corner of the row selected. The list view shows up just as if I
didn't even call this method (white bk, black text, etc...), plus there's
that red box off to the side. Now, in MFC, if you override OnDraw, and don't
do anything except what I've done here, the list is going to show up empty.
So, I'm wondering if I need to somehow tell the QListView to be owner drawn
(can't find a member method for that though) or am I overriding the wrong
method for painting? I did try to override
paint(QPainter* ) but it never got called.


Anyone know what I'm doing wrong?

Thanks,

Matt Harp


Message 2 in thread

Op maandag 11 maart 2002 23:35, schreef Matt Harp:
> hey all,

Hi,

>
> I've been working with the QT eval for Windows for the last week or so, and
> have not been able to find anything about implementing owner drawn
> controls. I also looked in the list archives, but no mention of it, which I
> find bizarre.
>
> So anyway, what I'm trying to do is setup a QListView as an owner-drawn
> list view, so that when a user selects a row, the whole row gets
> highlighted (like in a list box) instead of just the first column.

[SNIP]

Isn't QListView::setAllColumnsShowFocus(bool) just what you're looking for?

regards,

Klaas


Message 3 in thread

you don't want QListView::paintEvent(), you want QListViewItem::paintCell().

Take a look at the QtDesigner sources on how they do the drawing of the
cells in the property editor. It isn't complicated, but it's not very
obvious.

j


-----Original Message-----
From: Matt Harp [mailto:mharp@seapine.com]
Sent: Monday, March 11, 2002 2:35 PM
To: qtlist
Subject: owner-drawn controls?


hey all,

I've been working with the QT eval for Windows for the last week or so, and
have not been able to find anything about implementing owner drawn controls.
I also looked in the list archives, but no mention of it, which I find
bizarre.

So anyway, what I'm trying to do is setup a QListView as an owner-drawn list
view, so that when a user selects a row, the whole row gets highlighted
(like in a list box) instead of just the first column.

I have a class inherited from QListView, and have implemented the paintEvent
method. I have the following code,

void CMyList::paintEvent( QPaintEvent * p_pevent)
{
   QPainter* painter = new QPainter( this );

   QRect rectSelected;
   QBrush brush( QColor(122, 122, 255));
   painter->fillRect( rectSelected = contentsRect(), brush);

   QListViewItem *pitem = selectedItem();
   if (pitem != NULL)
   {
      rectSelected = itemRect( pitem);
      rectSelected.setTop( rectSelected.top() + 16);
      rectSelected.setBottom( rectSelected.bottom() + 16);
      QBrush brush(::GetSysColor( COLOR_HIGHLIGHT)); // blue
      painter->fillRect( rectSelected, brush);
   }
}

this code doesn't seem to do anything except paint a small red box to the
top left corner of the row selected. The list view shows up just as if I
didn't even call this method (white bk, black text, etc...), plus there's
that red box off to the side. Now, in MFC, if you override OnDraw, and don't
do anything except what I've done here, the list is going to show up empty.
So, I'm wondering if I need to somehow tell the QListView to be owner drawn
(can't find a member method for that though) or am I overriding the wrong
method for painting? I did try to override
paint(QPainter* ) but it never got called.


Anyone know what I'm doing wrong?

Thanks,

Matt Harp

--
 [ signature omitted ]