Qt-interest Archive, January 2008
Help with drawing items in a model view
Pages: Prev | 1 | 2 | Next
Message 1 in thread
Hi all,
I've been bashing my head against a wall for too long now, so thought I'd
call for backup.
I'm using Model/View architecture to do some drawing. I'm using a QTreeView
to show my items, and a QAbstractItemModel to store the data.
Each of my items has 8 columns. The first 3 of these are read only. Of the
last 5, an icon will be drawn in 1 of them (updated when you select one).
This all works fine for me - you click in column 5, the icon goes in column
5. You click in column 7, the icon leaves column 5 and goes to column 7.
Nice.
If you click in column 1, 2 or 3, however, nothing should happen (and it
doesn't - the icon stays in the last column you clicked in). But then when
you click in, say, column 5, the icon is drawn in column 5 BUT REMAINS IN
WHATEVER COLUMN IT WAS IN BEFORE. If you do a full refresh, it works OK.
I've isolated it down to the fact that when you click in a column, it draws
the colunn you had last clicked in, and the column you just clicked in. So
when you click in column 1 it redraws the old column (which forces the icon
to be drawn), and then redraws column 1. When you click in column 5, it
redraws column 1 (which does nothing) and column 5 (which draws the icon
there), but never un-draws the icon in the old column.
I've tried forcing a full repaint of the row and not had any success. Is
there a way to configure the system so it won't try drawing when you click
in a column (so it ignores the click in column 1, for example)?
Any advice would be greatly appreciated.
Regards,
Darryl
Message 2 in thread
On 25.01.08 19:02:33, Darryl Hunter wrote:
> Hi all,
>
> I've been bashing my head against a wall for too long now, so thought I'd
> call for backup.
>
> I'm using Model/View architecture to do some drawing. I'm using a QTreeView
> to show my items, and a QAbstractItemModel to store the data.
>
> Each of my items has 8 columns. The first 3 of these are read only. Of the
> last 5, an icon will be drawn in 1 of them (updated when you select one).
> This all works fine for me - you click in column 5, the icon goes in column
> 5. You click in column 7, the icon leaves column 5 and goes to column 7.
> Nice.
>
> If you click in column 1, 2 or 3, however, nothing should happen (and it
> doesn't - the icon stays in the last column you clicked in). But then when
> you click in, say, column 5, the icon is drawn in column 5 BUT REMAINS IN
> WHATEVER COLUMN IT WAS IN BEFORE. If you do a full refresh, it works OK.
>
> I've isolated it down to the fact that when you click in a column, it draws
> the colunn you had last clicked in, and the column you just clicked in. So
> when you click in column 1 it redraws the old column (which forces the icon
> to be drawn), and then redraws column 1. When you click in column 5, it
> redraws column 1 (which does nothing) and column 5 (which draws the icon
> there), but never un-draws the icon in the old column.
>
> I've tried forcing a full repaint of the row and not had any success. Is
> there a way to configure the system so it won't try drawing when you click
> in a column (so it ignores the click in column 1, for example)?
Where's the small compileable example to reproduce this? Sorry, but from
your description its not clear how you implemented the show/hide of the
icon, which is an important information to give any advice.
Andreas
--
[ signature omitted ]
Message 3 in thread
On Friday 25 January 2008 08:02:33 Darryl Hunter wrote:
> If you click in column 1, 2 or 3, however, nothing should happen (and it
> doesn't - the icon stays in the last column you clicked in). But then when
> you click in, say, column 5, the icon is drawn in column 5 BUT REMAINS IN
> WHATEVER COLUMN IT WAS IN BEFORE. If you do a full refresh, it works OK.
This sounds like you are not emitting the dataChanged() signal with the
correct arguments. That is, the arguments do not cover the full range of
indices that have been updated. The view will only update the elements
corresponding to the indices that have been changed according to this signal.
Hope this helps,
Sean
--
[ signature omitted ]
Message 4 in thread
Sean, you're a legend! I knew it would be something simple.
I'm not actually overriding setData (which is when the docs state to emit
dataChanged()), but it's what I needed to force the redraw.
Thanks for your help.
Darryl
-----Original Message-----
From: Sean Harmer [mailto:sean.harmer@xxxxxxxxxxxxxxxxx]
Sent: Friday, 25 January 2008 9:27 PM
To: qt-interest@xxxxxxxxxxxxx
Subject: Re: Help with drawing items in a model view
On Friday 25 January 2008 08:02:33 Darryl Hunter wrote:
> If you click in column 1, 2 or 3, however, nothing should happen (and
> it doesn't - the icon stays in the last column you clicked in). But
> then when you click in, say, column 5, the icon is drawn in column 5
> BUT REMAINS IN WHATEVER COLUMN IT WAS IN BEFORE. If you do a full
refresh, it works OK.
This sounds like you are not emitting the dataChanged() signal with the
correct arguments. That is, the arguments do not cover the full range of
indices that have been updated. The view will only update the elements
corresponding to the indices that have been changed according to this
signal.
Hope this helps,
Sean
--
[ signature omitted ]
Message 5 in thread
Dear All
Is it possible to have a combo Box as Sub Menu?. I have an application in
which i created a pop up menu. In the sub Menu of the Pop Up Menu, i need
to display a list of strings which i will get from the data base at run
time based on selection in the pop up menu. I need to ask whether it is
possible to attach a combo box as sub Menu of a pop Up Menu?
Thanks alot all...
Rohit
--
[ signature omitted ]
Message 6 in thread
> Is it possible to have a combo Box as Sub Menu?.
No, I don't think so. QMenu has no method like menu->addWidget(comboBox);
Instead, the QToolBar does have. So you can do toolBar->addWidget(comboBox);
Lingfa
--
[ signature omitted ]
Message 7 in thread
Thanks for reply
BUt the menu is a pop up menu which appears on right clicking the muse
button. I can not attach it with Tool Bar.
>
>> Is it possible to have a combo Box as Sub Menu?.
>
> No, I don't think so. QMenu has no method like menu->addWidget(comboBox);
> Instead, the QToolBar does have. So you can do
> toolBar->addWidget(comboBox);
> Lingfa
>
>
> --
> 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 8 in thread
BTW, you do not need to attach a widget (QComboBox in this case) it to
anything, if that's what you want!? Just move() it to the position of the
context-menu event and show() it. You could close it on a focus-out event,
for example.
Just an idea...
HTH, René
On Fri January 25 2008 15:56, rohitj@xxxxxxxxxxxxxx wrote:
> Thanks for reply
>
> BUt the menu is a pop up menu which appears on right clicking the muse
> button. I can not attach it with Tool Bar.
>
> >> Is it possible to have a combo Box as Sub Menu?.
> >
> > No, I don't think so. QMenu has no method like menu->addWidget(comboBox);
> > Instead, the QToolBar does have. So you can do
> > toolBar->addWidget(comboBox);
> > Lingfa
> >
> >
> > --
> > 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
Thanks alot for this ised
Can you elaborate it a little more please.
Thanks
> BTW, you do not need to attach a widget (QComboBox in this case) it to
> anything, if that's what you want!? Just move() it to the position of the
> context-menu event and show() it. You could close it on a focus-out event,
> for example.
>
> Just an idea...
>
> HTH, René
>
> On Fri January 25 2008 15:56, rohitj@xxxxxxxxxxxxxx wrote:
>> Thanks for reply
>>
>> BUt the menu is a pop up menu which appears on right clicking the muse
>> button. I can not attach it with Tool Bar.
>>
>> >> Is it possible to have a combo Box as Sub Menu?.
>> >
>> > No, I don't think so. QMenu has no method like
>> menu->addWidget(comboBox);
>> > Instead, the QToolBar does have. So you can do
>> > toolBar->addWidget(comboBox);
>> > Lingfa
>> >
>> >
>> > --
>> > 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/
>
> --
> René Reucher
> Tel: +49 160 7115802
> FAX: +49 6359 205423
> rene.reucher@xxxxxxxxxxxxx
> http://www.batcom-it.net/
>
> If money can't buy happiness, I guess you'll just have to rent it.
>
> --
> 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 10 in thread
On Fri January 25 2008 17:35, rohitj@xxxxxxxxxxxxxx wrote:
> Thanks alot for this ised
>
> Can you elaborate it a little more please.
Well, you said you wanted to react on a right-click, which is equivalent to a
context-menu request. You need to either overload the protected virtual
function contextMenuEvent(QContextMenuEvent *). The QContextMenuEvent has the
position of the mouse-click.
http://doc.trolltech.com/4.3/qwidget.html#contextMenuEvent
or set the contextMenuPolicy of the respective widget to Qt::CustomContextMenu
and use the signal customContextMenuRequested(const QPoint &pos).
http://doc.trolltech.com/4.3/qwidget.html#contextMenuPolicy-prop
http://doc.trolltech.com/4.3/qwidget.html#customContextMenuRequested
Then create the the QComboBox (or derivate) with a parent of NULL, move() it
to the event's mouse position and show() it.
When you destroy the QComboBox, it should be close()'d automatically.
René
--
[ signature omitted ]
Message 11 in thread
Note that I'm not saying that this is a good way of programming menus with
Qt... a pop-up menu should be used the way it is meant to be. That is, you
should better use the QAction which is associated with the menu item. The
QMenu class has a hovered(QAction *) signal, which could be connected to a
slot which does the rest.
http://doc.trolltech.com/4.3/qmenu.html#hovered
The only drawback is that you don't receive the current mouse-position.
On Fri January 25 2008 17:52, R. Reucher wrote:
> On Fri January 25 2008 17:35, rohitj@xxxxxxxxxxxxxx wrote:
> > Thanks alot for this ised
> >
> > Can you elaborate it a little more please.
>
> Well, you said you wanted to react on a right-click, which is equivalent to
> a context-menu request. You need to either overload the protected virtual
> function contextMenuEvent(QContextMenuEvent *). The QContextMenuEvent has
> the position of the mouse-click.
>
> http://doc.trolltech.com/4.3/qwidget.html#contextMenuEvent
>
> or set the contextMenuPolicy of the respective widget to
> Qt::CustomContextMenu and use the signal customContextMenuRequested(const
> QPoint &pos).
>
> http://doc.trolltech.com/4.3/qwidget.html#contextMenuPolicy-prop
> http://doc.trolltech.com/4.3/qwidget.html#customContextMenuRequested
>
> Then create the the QComboBox (or derivate) with a parent of NULL, move()
> it to the event's mouse position and show() it.
>
> When you destroy the QComboBox, it should be close()'d automatically.
>
> René
--
[ signature omitted ]
Message 12 in thread
Yes you are right. I implemented in the same QAction way but i am confused
with QComboBox selection and appearence in the main view. I am trying that
it appears when user select a item in the Pop Up menu and menu stays there
till combo box Item selection is completed.And i dont know, how to close
the combo box after the selection of the item in the combo box is done!!!
> Note that I'm not saying that this is a good way of programming menus with
> Qt... a pop-up menu should be used the way it is meant to be. That is, you
> should better use the QAction which is associated with the menu item. The
> QMenu class has a hovered(QAction *) signal, which could be connected to a
> slot which does the rest.
>
> http://doc.trolltech.com/4.3/qmenu.html#hovered
>
> The only drawback is that you don't receive the current mouse-position.
>
> On Fri January 25 2008 17:52, R. Reucher wrote:
>> On Fri January 25 2008 17:35, rohitj@xxxxxxxxxxxxxx wrote:
>> > Thanks alot for this ised
>> >
>> > Can you elaborate it a little more please.
>>
>> Well, you said you wanted to react on a right-click, which is equivalent
>> to
>> a context-menu request. You need to either overload the protected
>> virtual
>> function contextMenuEvent(QContextMenuEvent *). The QContextMenuEvent
>> has
>> the position of the mouse-click.
>>
>> http://doc.trolltech.com/4.3/qwidget.html#contextMenuEvent
>>
>> or set the contextMenuPolicy of the respective widget to
>> Qt::CustomContextMenu and use the signal
>> customContextMenuRequested(const
>> QPoint &pos).
>>
>> http://doc.trolltech.com/4.3/qwidget.html#contextMenuPolicy-prop
>> http://doc.trolltech.com/4.3/qwidget.html#customContextMenuRequested
>>
>> Then create the the QComboBox (or derivate) with a parent of NULL,
>> move()
>> it to the event's mouse position and show() it.
>>
>> When you destroy the QComboBox, it should be close()'d automatically.
>>
>> René
>
> --
> René Reucher
> Tel: +49 160 7115802
> FAX: +49 6359 205423
> rene.reucher@xxxxxxxxxxxxx
> http://www.batcom-it.net/
>
> Positive, adj.:
> Mistaken at the top of one's voice.
> -- Ambrose Bierce, "The Devil's Dictionary"
>
> --
> 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 13 in thread
rohitj wrote:
> Yes you are right. I implemented in the same QAction way but
> i am confused
> with QComboBox selection and appearence in the main view. I
> am trying that
> it appears when user select a item in the Pop Up menu and
> menu stays there
> till combo box Item selection is completed.And i dont know,
> how to close
> the combo box after the selection of the item in the combo
> box is done!!!
Are you sure it is a good idea to put a combobox into a popup-menu?
i have my doubts here, because it will imho be very awkward to use.
Wouldn't it be better to put all the choices from the combobox into the
menu and make them all to act like a radiobutton (iirc this is supported
by QMenu)
Cheers,
Peter
--
[ signature omitted ]
Message 14 in thread
On Fri January 25 2008 18:26, Peter Prade wrote:
> Are you sure it is a good idea to put a combobox into a popup-menu?
> i have my doubts here, because it will imho be very awkward to use.
>
> Wouldn't it be better to put all the choices from the combobox into the
> menu and make them all to act like a radiobutton (iirc this is supported
> by QMenu)
That's a clean approach, I agree!
But he said that the items would come from a DB, so there's may be plenty of
them... and when a menu is bloated this way, I think it's also awkward to
use :).
Have fun, René
--
[ signature omitted ]
Message 15 in thread
Thanks....
BUt the items of the combo box can be 3000
> rohitj wrote:
>> Yes you are right. I implemented in the same QAction way but
>> i am confused
>> with QComboBox selection and appearence in the main view. I
>> am trying that
>> it appears when user select a item in the Pop Up menu and
>> menu stays there
>> till combo box Item selection is completed.And i dont know,
>> how to close
>> the combo box after the selection of the item in the combo
>> box is done!!!
>
> Are you sure it is a good idea to put a combobox into a popup-menu?
> i have my doubts here, because it will imho be very awkward to use.
>
> Wouldn't it be better to put all the choices from the combobox into the
> menu and make them all to act like a radiobutton (iirc this is supported
> by QMenu)
>
> Cheers,
> Peter
>
> --
> 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 ]
Pages: Prev | 1 | 2 | Next