PDA

View Full Version : Mouse DoubleClick problem



mouni
8th August 2016, 15:28
hi,

i want when mouse double click on widget it should show central to window ..

and again double click i should go to prevoius position ...


i tried this



void Widget::mouseDoubleClickEvent(QMouseEvent *pEvent)
{
if(pEvent->MouseButtonDblClick )
{

QRect screenGeometry = QApplication::desktop()->screenGeometry();
int x = (screenGeometry.width() - this->width()) / 2;
int y = (screenGeometry.height()- this->height()) / 2;
this->move(x, y);
}
else
{
this->move(this->x(),this->y());
pEvent->accept();
}


}

First condition is working but second condition is not working can anybody give solution...

anda_skoa
8th August 2016, 16:25
MouseButtonDblClick is an enum value, its integer value is 176, which is always "true"

The code in the else branch also doesn't do anything other than explicitly accepting the event.
The move's arguments are the widget's current position.

Cheers,
_

mouni
8th August 2016, 16:49
then how can i set to previous position

mouni
8th August 2016, 16:55
hi,

i am setting my widget when mouse double click to center my system ...its working again when i double click it is not going to previous position how to set can anybody help

anda_skoa
8th August 2016, 16:55
Well, you need to store the old position before you move.

Cheers,
_

mouni
9th August 2016, 05:59
how can is store can you give some code ...

anda_skoa
9th August 2016, 08:49
Maybe you should first have a look at one or more C++ tutorials before attempting to create a full application.

Declaring and using member variables is something you just need to know

E.g. http://www.cplusplus.com/doc/tutorial/classes/

Cheers,
_

d_stranz
10th August 2016, 05:46
i am setting my widget when mouse double click to center my system

And think about what your current code is doing: You are handling a double-click event. It is always a double-click event, so it makes no sense to test to see if it is.

So in your event handler, not only do you need to save the current window position the first time through the handler (and of course, before you move the window to the center), but you also need to save the fact that it is the first double-click event. The next time, you check your variable to see "has there already been a double click event?" and if the answer is yes, you move the window back to the coordinates you saved during the first pass. You also reset your variable to say that you are ready for a new "first pass".

And as anda_skoa says, if you don't know how to write the code to implement that kind of logic, then you need to study some basic C++.

mouni
19th August 2016, 09:02
Hi ,


i am using frameless widget on top of mainwindow...

how to get startup position of frameless widget when when mouse double click ...

i am moving widget .... on top window...

when i double click it should go to previous position...

how to set....

Ginsengelf
19th August 2016, 09:27
Well, store the position before you move the widget, and move() it back to stored position when you double click.

Ginsengelf

mouni
19th August 2016, 10:35
can u send some code example for that