[英]How to resize and areo snap frameless windows qt6
我在 qt 設計師設計了一個表格
我還使用Qt::FramelessWindowHint
FramelessWindowHint 和Qt::WA_TranslucentBackground
使我的程序無框架
目前我以這種方式在我的程序中手動編碼拖動 windows
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);
}
它的工作沒有任何問題,但它缺少區域
並且我使用 QSizeGrip 調整我的程序大小
QSizeGrip* sizegrip = new QSizeGrip(ui.frame_size_grip);
sizegrip->setStyleSheet("width: 20px; height: 20px; margin 0px; padding: 0px;");
它也可以工作,但僅可用於我程序的一側
我的問題是我希望能夠使用 areo snap 來調整我的程序的大小(並且還能夠從所有邊緣調整它的大小),我找到了一些解決方案(比如this和this )但它們都沒有像我一樣工作(也許因為我正在使用設計器 ui 文件)我想知道它是否可以將 windows 與其他 window 對齊並在拖動到屏幕邊緣時調整它的大小,就像我們使用普通 window 框架時一樣? 並且還可以自由地從所有邊緣調整它的大小?
感謝幫助
經過一番搜索,我終於在 github 上找到了它,這正是我想要的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.