Qt-interest Archive, December 2006
Highlight
Pages: Prev | 1 | 2 | Next
Message 1 in thread
Hi,
I have subclass - class QtTreeViewDelegate : public QItemDelegate for a
QTreeWidget.
In the paint function the option.rect gives the rect for a particular
trewidgetitem on which its clicked.
void paint(QPainter * painter, const QStyleOptionViewItem & option,
const QModelIndex & index) const;
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?
Thanks.
Message 2 in thread
Jaya,
Selection behavior and mode are properties of QAbstractItemView. You
can simply call setSelectionBehavior(QAbstractItemView::SelectRows) on
your QTreeView.
Good Luck,
--Justin
Jaya Meghani wrote:
>
> Hi,
>
> I have subclass - class QtTreeViewDelegate : public QItemDelegate for
> a QTreeWidget.
>
> In the paint function the option.rect gives the rect for a particular
> trewidgetitem on which its clicked.
>
> void paint(QPainter * painter, const QStyleOptionViewItem & option,
> const QModelIndex & index) const;
>
> 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?
>
> Thanks.
>
begin:vcard
begin:vcard
fn:Justin Noel
n:Noel;Justin
org:ICS;Engineering
adr:;;54B Middlesex Trpk;Bedford;MA;01730;USA
email;internet:justin@xxxxxxx
title:Sr. Consulting Engineer / Certified Qt Instructor
tel;work:(617) 621-0060
url:http://www.ics.com
version:2.1
end:vcard
Message 3 in thread
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
--
[ signature omitted ]
Message 4 in thread
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
--
[ signature omitted ]
Message 5 in thread
Jaya,
You can use inherited members of the options class to get the cell state
which includes if it is selected or not. You can then test and draw.
--Justin
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/
>
>
begin:vcard
begin:vcard
fn:Justin Noel
n:Noel;Justin
org:ICS;Engineering
adr:;;54B Middlesex Trpk;Bedford;MA;01730;USA
email;internet:justin@xxxxxxx
title:Sr. Consulting Engineer / Certified Qt Instructor
tel;work:(617) 621-0060
url:http://www.ics.com
version:2.1
end:vcard
Message 6 in thread
I am sorry didn't quite understand Do you mean this way??
if ((option.state & QStyle::State_Selected) ==
QStyle::State_Selected) {
QRect qrect = option.rect;
painter->fillRect(qrect, QBrush(COLOR_BACKGROUND));
}
The problem is option.rect gives you only the rect of current item not
row.
So do we need to calculate rect surrounding whole row and then call
fillRect?
Thanks for your quick replies...I am really stuck with this..
-----Original Message-----
From: Justin Noel [mailto:justin@xxxxxxx]
Sent: Friday, December 15, 2006 3:37 PM
To: qt-interest@xxxxxxxxxxxxx
Subject: Re: Highlight
Jaya,
You can use inherited members of the options class to get the cell state
which includes if it is selected or not. You can then test and draw.
--Justin
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/
>
>
--
[ signature omitted ]
Message 7 in thread
Jaya,
Do not try to paint other cells besides the one covered by the model
index give to you. Cells are painted independently of each other and
you will not be able to predict order. Imagine if you needed to scroll
horizontally... The first cell in the row may never get painted at all.
You want to let each delegate draw each cell independently. If a row is
selected via a row selection then all cells will get the selected state
and the delegate, if written correctly, will draw with the right
background color.
Note:QItemSelectionModel got a few extra methods to poll for row/col
selections in Qt 4.2. Its unrelated to your current problem, but a good
reason to upgrade if you are dealing with row selections.
--Justin
Jaya Meghani wrote:
> I am sorry didn't quite understand Do you mean this way??
>
> if ((option.state & QStyle::State_Selected) ==
> QStyle::State_Selected) {
> QRect qrect = option.rect;
> painter->fillRect(qrect, QBrush(COLOR_BACKGROUND));
> }
>
> The problem is option.rect gives you only the rect of current item not
> row.
> So do we need to calculate rect surrounding whole row and then call
> fillRect?
> Thanks for your quick replies...I am really stuck with this..
>
>
> -----Original Message-----
> From: Justin Noel [mailto:justin@xxxxxxx]
> Sent: Friday, December 15, 2006 3:37 PM
> To: qt-interest@xxxxxxxxxxxxx
> Subject: Re: Highlight
>
> Jaya,
>
> You can use inherited members of the options class to get the cell state
> which includes if it is selected or not. You can then test and draw.
>
> --Justin
>
> 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/
>>
>>
>>
>
> --
> 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/
>
>
begin:vcard
begin:vcard
fn:Justin Noel
n:Noel;Justin
org:ICS;Engineering
adr:;;54B Middlesex Trpk;Bedford;MA;01730;USA
email;internet:justin@xxxxxxx
title:Sr. Consulting Engineer / Certified Qt Instructor
tel;work:(617) 621-0060
url:http://www.ics.com
version:2.1
end:vcard
Message 8 in thread
I have on more question related to this.
I have a treewidget. I have a delegate for that.
Now I want to add a pushbutton in the column for each row of treewidget.
Can we do this?
-----Original Message-----
From: Justin Noel [mailto:justin@xxxxxxx]
Sent: Friday, December 15, 2006 4:16 PM
To: qt-interest@xxxxxxxxxxxxx
Subject: Re: Highlight
Jaya,
Do not try to paint other cells besides the one covered by the model
index give to you. Cells are painted independently of each other and
you will not be able to predict order. Imagine if you needed to scroll
horizontally... The first cell in the row may never get painted at all.
You want to let each delegate draw each cell independently. If a row is
selected via a row selection then all cells will get the selected state
and the delegate, if written correctly, will draw with the right
background color.
Note:QItemSelectionModel got a few extra methods to poll for row/col
selections in Qt 4.2. Its unrelated to your current problem, but a good
reason to upgrade if you are dealing with row selections.
--Justin
Jaya Meghani wrote:
> I am sorry didn't quite understand Do you mean this way??
>
> if ((option.state & QStyle::State_Selected) ==
> QStyle::State_Selected) {
> QRect qrect = option.rect;
> painter->fillRect(qrect, QBrush(COLOR_BACKGROUND)); }
>
> The problem is option.rect gives you only the rect of current item not
> row.
> So do we need to calculate rect surrounding whole row and then call
> fillRect?
> Thanks for your quick replies...I am really stuck with this..
>
>
> -----Original Message-----
> From: Justin Noel [mailto:justin@xxxxxxx]
> Sent: Friday, December 15, 2006 3:37 PM
> To: qt-interest@xxxxxxxxxxxxx
> Subject: Re: Highlight
>
> Jaya,
>
> You can use inherited members of the options class to get the cell
> state which includes if it is selected or not. You can then test and
draw.
>
> --Justin
>
> 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/
>>
>>
>>
>
> --
> 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/
>
>
--
[ signature omitted ]
Message 9 in thread
Jaya Meghani wrote:
> I have on more question related to this.
> I have a treewidget. I have a delegate for that.
> Now I want to add a pushbutton in the column for each row of treewidget.
>
> Can we do this?
>
>
Jaya,
You have two options:
1) Create a delegate the provides a pushbutton editor and fake
pushbutton graphics and use it on one column of your table. Your table
will look like this:
PB | Text | Text
2) You can make an delegate that paints a fake push button and text in
the same cell and look for events over the fake push button so you can
paint it with hover and pressed effects. Your table will look like this:
PB Text | Text | Text
You can use the QStyle API to draw fake widgets easily.
Setting per column delegates is not straight forward prior to Qt 4.2.
This will make you design and code sane when you want a different look
and feel per column. There is a whitepaper supplied by ICS the describes
a technique you can use. http://www.ics.com/developers/papers/
--Justin
P.S. You might want to create new thread for different questions even
when slight related. This makes the newsgroups and archives easier to use.
begin:vcard
begin:vcard
fn:Justin Noel
n:Noel;Justin
org:ICS;Engineering
adr:;;54B Middlesex Trpk;Bedford;MA;01730;USA
email;internet:justin@xxxxxxx
title:Sr. Consulting Engineer / Certified Qt Instructor
tel;work:(617) 621-0060
url:http://www.ics.com
version:2.1
end:vcard
Message 10 in thread
On 15.12.06 16:37:38, Jaya Meghani wrote:
> I have on more question related to this.
> I have a treewidget. I have a delegate for that.
> Now I want to add a pushbutton in the column for each row of treewidget.
In Editing or non-Editing mode? I guess the 2nd way, in which case you
should think about using QStandardItemModel and QTreeView instead of
QTreeWidget. Then you can use setIndexWidget.
Andreas
--
[ signature omitted ]
Message 11 in thread
Andreas Pakulat wrote:
> On 15.12.06 16:37:38, Jaya Meghani wrote:
>
>> I have on more question related to this.
>> I have a treewidget. I have a delegate for that.
>> Now I want to add a pushbutton in the column for each row of treewidget.
>>
>
> In Editing or non-Editing mode? I guess the 2nd way, in which case you
> should think about using QStandardItemModel and QTreeView instead of
> QTreeWidget. Then you can use setIndexWidget.
>
> Andreas
>
>
Note that setIndexWidget is not scalable and will be memory intensive
since you will need one actual widget per row. You are better off
drawing hundreds of rows with fake widgets with a delegate which
requires only one actual widget instance (possibly none at all).
--Justin
begin:vcard
begin:vcard
fn:Justin Noel
n:Noel;Justin
org:ICS;Engineering
adr:;;54B Middlesex Trpk;Bedford;MA;01730;USA
email;internet:justin@xxxxxxx
title:Sr. Consulting Engineer / Certified Qt Instructor
tel;work:(617) 621-0060
url:http://www.ics.com
version:2.1
end:vcard
Message 12 in thread
I agree with the memory intensive issue.
I basically need to have a icon/button on each row of a
QTreeWidget...click of which can be connected to a slot.
How can i do this?
I am working on existing code so cannot change treewidget->treeview.
Thanks guys for help....
-----Original Message-----
From: Justin Noel [mailto:justin@xxxxxxx]
Sent: Friday, December 15, 2006 4:59 PM
To: qt-interest@xxxxxxxxxxxxx
Subject: Re: Highlight
Andreas Pakulat wrote:
> On 15.12.06 16:37:38, Jaya Meghani wrote:
>
>> I have on more question related to this.
>> I have a treewidget. I have a delegate for that.
>> Now I want to add a pushbutton in the column for each row of
treewidget.
>>
>
> In Editing or non-Editing mode? I guess the 2nd way, in which case you
> should think about using QStandardItemModel and QTreeView instead of
> QTreeWidget. Then you can use setIndexWidget.
>
> Andreas
>
>
Note that setIndexWidget is not scalable and will be memory intensive
since you will need one actual widget per row. You are better off
drawing hundreds of rows with fake widgets with a delegate which
requires only one actual widget instance (possibly none at all).
--Justin
--
[ signature omitted ]
Message 13 in thread
Jaya Meghani wrote:
> I agree with the memory intensive issue.
> I basically need to have a icon/button on each row of a
> QTreeWidget...click of which can be connected to a slot.
> How can i do this?
> I am working on existing code so cannot change treewidget->treeview.
>
>
>
Easy using a delegate. Just impl the delegate such that it has:
signals:
buttonClicked(const QModelIndex&)
Detect when the button has been clicked (Via editor widget or events)
and emit this with your current index for flexibility. You can have a
slot handle this signal.
You do not want to connect to the button directly since it will lack the
knowledge of the row number.
You could subclass the QTreeWidget to encapsulate these interactions so
external interface of this tree/delegate combination is cleaner. So the
TreeWidget could have the signal in the format of rowButtonClicked(int row);
--Justin
begin:vcard
begin:vcard
fn:Justin Noel
n:Noel;Justin
org:ICS;Engineering
adr:;;54B Middlesex Trpk;Bedford;MA;01730;USA
email;internet:justin@xxxxxxx
title:Sr. Consulting Engineer / Certified Qt Instructor
tel;work:(617) 621-0060
url:http://www.ics.com
version:2.1
end:vcard
Message 14 in thread
Andreas Pakulat wrote:
> On 15.12.06 16:37:38, Jaya Meghani wrote:
>
>> I have on more question related to this.
>> I have a treewidget. I have a delegate for that.
>> Now I want to add a pushbutton in the column for each row of treewidget.
>>
>
> In Editing or non-Editing mode? I guess the 2nd way, in which case you
> should think about using QStandardItemModel and QTreeView instead of
> QTreeWidget. Then you can use setIndexWidget.
>
> Andreas
>
>
Andreas is right that you should be using the more industrial strength
QTreeView with a model. It will allow you to tune model performance in
the future and is not that much extra work.
--Justin
begin:vcard
begin:vcard
fn:Justin Noel
n:Noel;Justin
org:ICS;Engineering
adr:;;54B Middlesex Trpk;Bedford;MA;01730;USA
email;internet:justin@xxxxxxx
title:Sr. Consulting Engineer / Certified Qt Instructor
tel;work:(617) 621-0060
url:http://www.ics.com
version:2.1
end:vcard
Message 15 in thread
"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 ]
Pages: Prev | 1 | 2 | Next