PDA

View Full Version : QWidget movement



fakefish
6th April 2011, 16:03
Hello,
I am trying to catch the event when my window is being moved by the user.
I want to make my widget semi-visible while moving.

The moveevent only gives position updates not status.
And mouse events cannot be catched from title bar.
Qt::WA_PendingMoveEvent is also not set when moving the widget.

Please help,

high_flyer
6th April 2011, 16:24
The moveevent only gives position updates not status.
What do you mean by 'status'?

fakefish
7th April 2011, 07:20
moveEvent gives old and new positions but I couldn't finf a way to get the moving status.

high_flyer
7th April 2011, 12:41
What is 'moving status'?

BalaQT
7th April 2011, 12:57
hi,
@high_flyer,
i think , he wants to know
1)how to know, when the user started to move the window(this is pretty easy, moveEvent will help) (window move started)
2)how to know, user stops moving the window. (window move ended)

I want to make my widget semi-visible while moving.
his goal is to show a transparent window, when it is moved.

@fakefish:
just a hints, not the direct answer though, we can use moveevent and a timer or eventfilter to achieve the goal.(not the best logic though)
Bala

high_flyer
7th April 2011, 13:18
In that case you can use mouseReleaseEvent to know when user let go of the window.
mouseMoveEvent() will tell you when it started.

fakefish
7th April 2011, 13:51
In that case you can use mouseReleaseEvent to know when user let go of the window.
mouseMoveEvent() will tell you when it started.

Widget does not capture mouse events on the title bar.

Added after 17 minutes:


@fakefish:
just a hints, not the direct answer though, we can use moveevent and a timer or eventfilter to achieve the goal.(not the best logic though)
Bala

Thanks, I tried it does not seem bad, but its processor usage is huge :)

BalaQT
7th April 2011, 14:40
hi,

Thanks, I tried it does not seem bad, but its processor usage is huge

how about this, install a eventfilter and start the timer only at the window move event.



MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
bMove=false;
connect(&t,SIGNAL(timeout()),this,SLOT(Trans()));
t.setInterval(50);
installEventFilter(this);
}
bool MainWindow::eventFilter(QObject *obj, QEvent *evt)
{
bMove=false;
if(evt->type()==QEvent::Move)
{
bMove=true;
if(!t.isActive())
{
t.start();
}
}
}

void MainWindow::Trans()
{
if(bMove)
{
//make window transparent
}
else
{
t.stop();
//make window normal
}
}


not a straight forward solution, but hope it helps,
bala

fakefish
19th April 2011, 12:02
how about this, install a eventfilter and start the timer only at the window move event.

Thanks that also worked. The CPU usage increase caused by repainting transparent window, I believe.

Fakefish