PDA

View Full Version : QMdiSubWindow Questions



ericV
1st October 2009, 14:49
Hello all,

I am now working on a multi-widget MDI application and am trying to implement my own Subwindow, since i need it to have different behaviours depending on the widget that is set into it.

My problem is following, i have two widget types where i don't want the subwindow to have a title-bar, but i still want to be able to move and re-size it.
The only way i have found to remove the title-bar is to apply the Qt::FramlessWindowHint wich also removes the frame and so i lose the ability to re-size the window directly.

So i would like to write a re-size and Move event that handles the mouse click, move and release events from the widget.

I have successfully reimplemented these events directly on the widget, but i would rather have this handled directly by the subwindow.

I hope "you" can make sense of my rambling :cool:

Oh the widgets i am talking about are based on QFrame.

Thanks for reading, and i hope you can help.

Eric

TMan
1st October 2009, 15:38
You could sublcass QMdiSubWindow and implement the moveevent/resizeevent handlers there I guess.

However, probably someone will turn up in this thread with a better solution :)

ericV
1st October 2009, 15:52
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)
{
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);
}