Im designed a form in qt designers
I also make my program frameless with using Qt::FramelessWindowHint
and Qt::WA_TranslucentBackground
currently I coded drag windows manually in my program in this way
bool Qt6Gui::eventFilter(QObject* obj, QEvent* event)
{
switch (event->type())
{
case QEvent::MouseButtonDblClick:
{
auto* mouseEvent = static_cast<QMouseEvent*>(event);
if (obj == ui.titleRightInfo && mouseEvent->buttons() & Qt::MouseButton::LeftButton)
QTimer::singleShot(250, this, &Qt6Gui::maximize_restore);
}
break;
case QEvent::MouseButtonPress:
{
if (obj == ui.titleRightInfo)
{
auto* mouseEvent = static_cast<QMouseEvent*>(event);
if (mouseEvent->buttons() & Qt::MouseButton::LeftButton)
{
mouse_pos = ui.titleRightInfo->mapToGlobal(mouseEvent->pos());
onMove = true;
}
}
}
break;
case QEvent::MouseMove:
{
if (obj == ui.titleRightInfo && onMove)
{
auto* mouseEvent = static_cast<QMouseEvent*>(event);
if (mouseEvent->buttons() & Qt::MouseButton::LeftButton)
{
auto glb_mousepos = ui.titleRightInfo->mapToGlobal(mouseEvent->pos());
auto delta = glb_mousepos - mouse_pos;
if (delta.x() || delta.y())
{
auto newpos = this->pos() + delta;
mouse_pos = glb_mousepos;
if (GLOBAL_STATE == 1)
maximize_restore();
this->move(newpos);
}
}
}
}
break;
case QEvent::MouseButtonRelease:
{
if (obj == ui.titleRightInfo && onMove)
{
auto pos = this->mapToGlobal(QPoint(0, 0));
if (pos.y() < 0)
{
auto old_pos = this->pos();
this->move(old_pos.x(), old_pos.y() - pos.y() + 1);
}
onMove = false;
}
}
break;
}
return QWidget::eventFilter(obj, event);
}
its working without any problem but its missing areo
and also Im resize my program using QSizeGrip
QSizeGrip* sizegrip = new QSizeGrip(ui.frame_size_grip);
sizegrip->setStyleSheet("width: 20px; height: 20px; margin 0px; padding: 0px;");
its working too but its usable only for one side of my program
my problem is I want to be able to use areo snap for resize my program (and also be able to resize it from all the edges), I found some solution (like this and this) but none of them worked as I excepted (maybe because I'm using designer ui file)
I want to know its possible to snap windows against other window and resize it when dragged to the edge of the screen like when we use normal window frame? and also resize it from all the edges freely?
thanks for help
after some more searching I finally found this on github its exactly what I wanted.