The problem is how do I generate a move/resize Event in my subwindow from my widget or without the frame?
I have the following code in one of my Widgets. Right now it handles the moving of the widget with its parent and seting the proper resize cursors when hovering the edges.
But Idealy i would like to ignore the event here and handle it in the subwindow...
Im not sure if I can do that. I will try to give that a try tomorrow
void DisplayComponent
::mousePressEvent(QMouseEvent *me
) {
me->accept(); // do not propagate
if(me->buttons() == Qt::LeftButton)
{
if(canResize){
return QWidget::resizeEvent(dynamic_cast<QResizeEvent
*>
(me
));
}
isMoving = true;
if (parentWidget()->isWindow())
offset = me->globalPos() - pos();
else
offset = me->pos();
}
}
void DisplayComponent
::mouseReleaseEvent(QMouseEvent *me
) {
me->accept(); // do not propagate
if(isMoving)
{
isMoving = false;
}
}
{
me->accept(); // do not propagate
if (isMoving)
{
if (parentWidget()->isWindow())
parentWidget()->move(me->globalPos() - offset);
else
parentWidget()->move(parentWidget()->mapToParent(me->pos() - offset));
return;
}
canResize = false;
setCursor(Qt::ArrowCursor);
int mouseX = me->pos().x();
int mouseY = me->pos().y();
int frameTopLeft = frameWidth();
int frameBottom = rect().bottom() - frameWidth();
int frameRight = rect().right() - frameWidth();
if (mouseX < frameTopLeft)
{
canResize = true;
if (mouseY < frameTopLeft)
{
//isTopLeft();
setCursor(Qt::SizeFDiagCursor);
return;
}
if (mouseY > frameBottom)
{
//isBottomLeft();
setCursor(Qt::SizeBDiagCursor);
return;
}
//isLeft();
setCursor(Qt::SizeHorCursor);
return;
}
if (mouseX > frameRight)
{
canResize = true;
if (mouseY < frameTopLeft)
{
//isTopRight;
setCursor(Qt::SizeBDiagCursor);
return;
}
if (mouseY > frameBottom)
{
//isBottomRight;
setCursor(Qt::SizeFDiagCursor);
return;
}
//isRight;
setCursor(Qt::SizeHorCursor);
return;
}
if(mouseY < frameTopLeft)
{
//isTop;
canResize = true;
setCursor(Qt::SizeVerCursor);
return;
}
if(mouseY > frameBottom)
{
//isBottom;
canResize = true;
setCursor(Qt::SizeVerCursor);
return;
}
//isNormal;
canResize = false;
setCursor(Qt::ArrowCursor);
}
void DisplayComponent::mousePressEvent(QMouseEvent *me)
{
me->accept(); // do not propagate
if(me->buttons() == Qt::LeftButton)
{
if(canResize){
return QWidget::resizeEvent(dynamic_cast<QResizeEvent*> (me));
}
isMoving = true;
if (parentWidget()->isWindow())
offset = me->globalPos() - pos();
else
offset = me->pos();
}
}
void DisplayComponent::mouseReleaseEvent(QMouseEvent *me)
{
me->accept(); // do not propagate
if(isMoving)
{
offset = QPoint();
isMoving = false;
}
}
void DisplayComponent::mouseMoveEvent(QMouseEvent *me)
{
me->accept(); // do not propagate
if (isMoving)
{
if (parentWidget()->isWindow())
parentWidget()->move(me->globalPos() - offset);
else
parentWidget()->move(parentWidget()->mapToParent(me->pos() - offset));
return;
}
canResize = false;
setCursor(Qt::ArrowCursor);
int mouseX = me->pos().x();
int mouseY = me->pos().y();
int frameTopLeft = frameWidth();
int frameBottom = rect().bottom() - frameWidth();
int frameRight = rect().right() - frameWidth();
if (mouseX < frameTopLeft)
{
canResize = true;
if (mouseY < frameTopLeft)
{
//isTopLeft();
setCursor(Qt::SizeFDiagCursor);
return;
}
if (mouseY > frameBottom)
{
//isBottomLeft();
setCursor(Qt::SizeBDiagCursor);
return;
}
//isLeft();
setCursor(Qt::SizeHorCursor);
return;
}
if (mouseX > frameRight)
{
canResize = true;
if (mouseY < frameTopLeft)
{
//isTopRight;
setCursor(Qt::SizeBDiagCursor);
return;
}
if (mouseY > frameBottom)
{
//isBottomRight;
setCursor(Qt::SizeFDiagCursor);
return;
}
//isRight;
setCursor(Qt::SizeHorCursor);
return;
}
if(mouseY < frameTopLeft)
{
//isTop;
canResize = true;
setCursor(Qt::SizeVerCursor);
return;
}
if(mouseY > frameBottom)
{
//isBottom;
canResize = true;
setCursor(Qt::SizeVerCursor);
return;
}
//isNormal;
canResize = false;
setCursor(Qt::ArrowCursor);
}
To copy to clipboard, switch view to plain text mode
Bookmarks