PDA

View Full Version : mouseevent / clicked



Cremers
12th October 2014, 12:02
Hi,
I made a delegate for a qlistview, all works fine.
The widget that uses the delegate connects the clicked signal to a slot, works fine.
But since I added mousepress/release/move events in that delegate, the slot for the clicked signal doesn't fire anymore.

How do i fix this? Hopefully not by moving the clicked signal/slot to the delegate too, that would be inconvenient.

Thanks.

west
12th October 2014, 13:38
Show some code, the most important is how you "added mousepress/release/move events in that delegate".
I guess that you have to do sth like this:


bool MyClass::someEvent(Event e)
{
BaseClass::someEvent(e);
//Your code
}

Cremers
12th October 2014, 16:25
Hey thanks, indeed I'm looking for something like that.


/*------------------------------------------------------------------------------------*/
ListView::ListView(QWidget * parent) : QListView(parent)
{
//blabla
mousedown = false;
}
//----------------------------------------------------------------------------
void ListView::mousePressEvent(QMouseEvent * event)
{
mousepos = event->pos();
mousedown = true;
}
//----------------------------------------------------------------------------
void ListView::mouseReleaseEvent(QMouseEvent * event)
{
mousedown = false;
}
//----------------------------------------------------------------------------
void ListView::mouseMoveEvent(QMouseEvent * event)
{
if (mousedown)
{
// do the dirty deed
}
}


I guess in mousePressEvent() in need something like
QListView:: onclick(?);

ChrisW67
12th October 2014, 21:29
No, in mousePressEvent()/mouseReleaseEvent() you need to ensure the base class processing is called (exactly as west describes) because it is that processing that leads to the detection of a click event in the base class.


//----------------------------------------------------------------------------
void ListView::mousePressEvent(QMouseEvent * event)
{
QListView::mousePressEvent();
mousepos = event->pos();
mousedown = true;
}

There is nothing Qt specific about this basic C++ behaviour of overdden virtual functions (not delegates).

Cremers
13th October 2014, 09:22
Thanks that did the trick.