PDA

View Full Version : mouseMoveEvent show/hide



davidovv
4th March 2013, 01:01
i have widget that should contain stretched QTextEdit and a overlay widget with some buttons, something like this


________________________
| QTextEdit _____ |
| | | |
| |____| |
| |
| |
| |
| |
|_______________________|


(hope that picture looks right)

I have trouble implementing this simple behaviour:
if mouse is in the rect where widget widget with buttons should be, show widget with buttons
when the mouse leaves the rect, hide the widget
anyone tried to achive something similar?

ChrisW67
4th March 2013, 01:46
What have you actually tried?

If you actually hide() the widget then it is not there to receive and process mouse events; so you you cannot use the mouse events of the widget itself to show() it. You could use the mouse events of the widget containing the disappearing widget to make it reappear.

davidovv
4th March 2013, 09:50
I thought it would be simple like this


void MessageForm::mouseMoveEvent(QMouseEvent *mme)
{
if(mme->type() == QMouseEvent::MouseMove){
if(ui->actions->rect().contains(mme->pos())){
ui->actions->setVisible(true);
}
else{
ui->actions->setVisible(false);
}
}
}

i am not using mouse event of widget with buttons but from parent widget. The first problem was one overlay floating widget and one stretch widget. solved with


void MessageForm::resizeEvent(QResizeEvent* re) {
Q_UNUSED(re);
ui->actions->move(width() - ui->actions->width() - 20, 20 );
ui->textEdit->resize(this->size());
}

in form constructor i have


ui->setupUi(this);
setMouseTracking(true);
ui->textEdit->move(0,0);
ui->actions->setVisible(false);
resizeEvent(NULL);


but, of course, there is QTextEdit that takes mouse events. It doesnt feel right to reimplement QTextEdit (it is not realy text editing function what am i reimplementing), but it takes away mouse events i intended from form.
So i thought that i just made a blunder, and that i am doing it wrong. Maybe someone here acomplished same thing.
Or, Is there a way for parent widget tho know the mouse position if the mouse is over the widget itself and/or its children widgets?