Qt-interest Archive, December 2006
Highlight
Pages: Prev | 1 | 2 | Next
Message 16 in thread
Qt4.1.2 Open source edition
-----Original Message-----
From: Duane Hebert [mailto:spoo@xxxxxxxxx]
Sent: Friday, December 15, 2006 3:40 PM
To: qt-interest@xxxxxxxxxxxxx
Subject: Re: Highlight
"Jaya Meghani" <Jaya.Meghani@xxxxxxxxxx> wrote in message
news:9FA8DF11EDE77F4B92FBFF7E01DFE0F203F7D425@xxxxxxxxxxxxxxxxxxxxxx
>I have other requirements - to create a custom item delegate.
>I have set setSelectionBehavior(QAbstractItemView::SelectRows) for tree
>widget.
>But still it selects only the particular item.
Which version of Qt are you using? ISTR there was a version (maybe a
snapshot though) where if you had hidden columns the selection behavior
was broken.
>If we reimplement the paint method of delegate do we have to write the
>code to highlight the row based on selection
>QAbstractItemView::SelectRows
I would expect that if you take over the paint event, you would have to
deal with it. Also, just painting it to look like the row is selected
when the columns are actually getting selected may not be what you want.
Anyway, that seems like a lot to do to
get selectionBehavior to work. Maybe you should create a simple example
that demonstrates the problem and post it here or, better yet, send it
to the support trolls.
--
[ signature omitted ]
Message 17 in thread
"Jaya Meghani" <Jaya.Meghani@xxxxxxxxxx> wrote in message
news:9FA8DF11EDE77F4B92FBFF7E01DFE0F203F7D4E7@xxxxxxxxxxxxxxxxxxxxxx
>Qt4.1.2 Open source edition
Ok. Does this work as expected with a standard treeWidget with a standard
treeWidgetItem? With columns hidden?
--
[ signature omitted ]
Message 18 in thread
Yes. I tried a example program and hid one column but the selection
still selects the whole row.
-----Original Message-----
From: Duane Hebert [mailto:spoo@xxxxxxxxx]
Sent: Friday, December 15, 2006 4:12 PM
To: qt-interest@xxxxxxxxxxxxx
Subject: Re: Highlight
"Jaya Meghani" <Jaya.Meghani@xxxxxxxxxx> wrote in message
news:9FA8DF11EDE77F4B92FBFF7E01DFE0F203F7D4E7@xxxxxxxxxxxxxxxxxxxxxx
>Qt4.1.2 Open source edition
Ok. Does this work as expected with a standard treeWidget with a
standard treeWidgetItem? With columns hidden?
--
[ signature omitted ]
Message 19 in thread
"Jaya Meghani" <Jaya.Meghani@xxxxxxxxxx> wrote in message
news:9FA8DF11EDE77F4B92FBFF7E01DFE0F203F7D522@xxxxxxxxxxxxxxxxxxxxxx
>Yes. I tried a example program and hid one column but the selection
>still selects the whole row.
Ok. So it's something with the delegate then. Can't help
you much there as I haven't used that yet.
--
[ signature omitted ]
Message 20 in thread
On 15.12.06 15:19:01, Jaya Meghani wrote:
> I have other requirements - to create a custom item delegate.
> I have set setSelectionBehavior(QAbstractItemView::SelectRows) for tree
> widget.
> But still it selects only the particular item.
> If we reimplement the paint method of delegate do we have to write the
> code to highlight the row based on selection
> QAbstractItemView::SelectRows
How about looking at the standard item delegate, he does highlight the
whole row when SelectRows is set, so you could just look how he does it.
My guess would be that you have to calculate the proper rect yourself,
or the delegate gets a paint() call for each selected index in a row.
Andreas
--
[ signature omitted ]
Message 21 in thread
I looked at it..What it(qtitemdelegate.cpp) does is:
// draw the background color
if (option.showDecorationSelected && (option.state &
QStyle::State_Selected)) {
QPalette::ColorGroup cg = option.state & QStyle::State_Enabled
? QPalette::Normal :
QPalette::Disabled;
painter->fillRect(option.rect, option.palette.brush(cg,
QPalette::Highlight));
} else {
value = index.data(Qt::BackgroundColorRole);
if (value.isValid() && qvariant_cast<QColor>(value).isValid())
painter->fillRect(option.rect,
qvariant_cast<QColor>(value));
}
seems to be similar to what I am doing.
However if I call QItemDelegate::paint(painter,option,index); again in
my derived class's paint function, then it starts selecting whole row
but then,as expected all the display is garbled
-----Original Message-----
From: Andreas Pakulat [mailto:apaku@xxxxxx]
Sent: Friday, December 15, 2006 3:42 PM
To: qt-interest@xxxxxxxxxxxxx
Subject: Re: Highlight
On 15.12.06 15:19:01, Jaya Meghani wrote:
> I have other requirements - to create a custom item delegate.
> I have set setSelectionBehavior(QAbstractItemView::SelectRows) for
> tree widget.
> But still it selects only the particular item.
> If we reimplement the paint method of delegate do we have to write the
> code to highlight the row based on selection
> QAbstractItemView::SelectRows
How about looking at the standard item delegate, he does highlight the
whole row when SelectRows is set, so you could just look how he does it.
My guess would be that you have to calculate the proper rect yourself,
or the delegate gets a paint() call for each selected index in a row.
Andreas
--
[ signature omitted ]
Message 22 in thread
On Friday 15 December 2006 15:19, Jaya Meghani wrote:
> I have other requirements - to create a custom item delegate.
> I have set setSelectionBehavior(QAbstractItemView::SelectRows) for tree
> widget.
> But still it selects only the particular item.
> If we reimplement the paint method of delegate do we have to write the
> code to highlight the row based on selection
> QAbstractItemView::SelectRows
>
> void QtTreeViewDelegate::paint(QPainter * painter, const
> QStyleOptionViewItem & option, const QModelIndex & index) const
> {
> //I use this code in paint function.
>
> QRect qrect = option.rect;
> painter->fillRect(qrect, QBrush(COLOR_BACKGROUND));
> }
>
> Thanks
>
> -----Original Message-----
> From: Andreas Pakulat [mailto:apaku@xxxxxx]
> Sent: Friday, December 15, 2006 2:41 PM
> To: qt-interest@xxxxxxxxxxxxx
> Subject: Re: Highlight
>
> On 15.12.06 14:00:33, Jaya Meghani wrote:
> > I have subclass - class QtTreeViewDelegate : public QItemDelegate for
> > a QTreeWidget.
> >
> > For example if I click on row=0 and col=1, I get only that cell
> > highlighted. Whereas I want whole row (row=1) to be selected. How can
> > I achive this?
>
> As Justin already said no need to create a custom item delegate, just
> use the existing selection-behaviour functions.
>
> Andreas
>
> --
> You will be the victim of a bizarre joke.
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body. List archive and information:
> http://lists.trolltech.com/qt-interest/
I've found the drawBackground method pretty helpful in getting the selection
painting correct. I call that first, then paint whatever text I need to
display.
ry
--
[ signature omitted ]