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

Qt-interest Archive, October 2007
QTreeView and custom widgets


Message 1 in thread

Hi,

I have been investigating the model/view method however I'm a bit stuck on a
particular piece of implementation I would like to do. I want to have a
custom widget, however I don't want the double click to edit style as is
done with the Delegate classes. What I would like is that when I hover over
the widget, then it automatically switches into edit mode.

Specifically I would like a spinbox to appear that the user can interact
with, without having to double click to bring it up. They simple move the
mouse over the lineedit cell, and it will automatically become a spinbox.

Does anyone have an idea on how this can be implemented?

Ryan

--
 [ signature omitted ] 

Message 2 in thread

On Saturday 06 October 2007 05:49:15 Ryan Winter wrote:
> Specifically I would like a spinbox to appear that the user can interact
> with, without having to double click to bring it up. They simple move the
> mouse over the lineedit cell, and it will automatically become a spinbox.

You are probably looking for QWidget::enterEvent and QWidget::leaveEvent, 
respectively.

Regards
	Daniel

--
 [ signature omitted ] 

Message 3 in thread

Ryan Winter wrote:
> Hi,
>
> I have been investigating the model/view method however I'm a bit stuck on a
> particular piece of implementation I would like to do. I want to have a
> custom widget, however I don't want the double click to edit style as is
> done with the Delegate classes. What I would like is that when I hover over
> the widget, then it automatically switches into edit mode.
>
> Specifically I would like a spinbox to appear that the user can interact
> with, without having to double click to bring it up. They simple move the
> mouse over the lineedit cell, and it will automatically become a spinbox.
>
> Does anyone have an idea on how this can be implemented?
>
>   

In a subclass of QTreeView you could do the following:

MyTreeView::MyTreeView(QWidget* parent) :
    QTreeView(parent)
{
    setEditTriggers(QAbstractItemView::CurrentChanged);
}

MyTreeView::mouseMoveEvent(QMouseEvent* e)
{
    //Do the usual
    QTreeView::mouseMoveEvent(e);

    //Set current index to the one under the mouse
    setCurrentIndex( indexAt( me->pos() ) );
}


Good Luck,
--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 4 in thread

Justin Noel wrote:

> Ryan Winter wrote:
>> Hi,
>>
>> I have been investigating the model/view method however I'm a bit stuck
>> on a particular piece of implementation I would like to do. I want to
>> have a custom widget, however I don't want the double click to edit style
>> as is done with the Delegate classes. What I would like is that when I
>> hover over the widget, then it automatically switches into edit mode.
>>
>> Specifically I would like a spinbox to appear that the user can interact
>> with, without having to double click to bring it up. They simple move the
>> mouse over the lineedit cell, and it will automatically become a spinbox.
>>
>> Does anyone have an idea on how this can be implemented?
>>
>>   
> 
> In a subclass of QTreeView you could do the following:
> 
> MyTreeView::MyTreeView(QWidget* parent) :
>     QTreeView(parent)
> {
>     setEditTriggers(QAbstractItemView::CurrentChanged);
> }
> 
> MyTreeView::mouseMoveEvent(QMouseEvent* e)
> {
>     //Do the usual
>     QTreeView::mouseMoveEvent(e);
> 
>     //Set current index to the one under the mouse
>     setCurrentIndex( indexAt( me->pos() ) );
> }

Thanks Justin, I almost had it but I was using the calling edit function and
it didn't seem to work properly :| I also had to turn on mouse tracking. 

This is what I ended up with:

View::View(QWidget* parent)
    :
    QTreeView(parent)
{
    setMouseTracking(true);
    setEditTriggers(QAbstractItemView::CurrentChanged);

    connect(this, SIGNAL(entered(const QModelIndex&)),
            this, SLOT(setCurrentIndex(const QModelIndex&)));
}

--
 [ signature omitted ]