C ++ Qt Window Positioning

Does Qt have anything to offer for positioning windows similar to tooltips? (or any types of windows / widgets).

I want to be able to automatically update the position of the window so that it always stays on the screen (or, at least, is most suitable for it).

An example of the behavior I want can be seen in the standard Windows tooltips in the notification area. If the tooltip is large and it has part of it coming out of the screen, it will automatically move.

Obviously, I can write the code myself, but I'm looking for something that has already been written.

+4
source share
1 answer

I don't know if Qt has one single function that provides the widget completely inside the screen. But with QDesktopWidget, this is probably trivial.

void function RestrainWidgetToScreen(QWidget * w) { QRect screenRect = QDesktopWidget::availableGeometry(w); if(w->frameGeometry().left() < screenRect.left()) { w->move(screenRect.left() - w->frameGeometry().left(), 0); } else if(w->frameGeometry().right() > screenRect.right()) { w->move(screenRect.right() - w->frameGeometry().right(), 0); } if(w->frameGeometry().top() < screenRect.top()) { w->move(0, screenRect.top() - w->frameGeometry().top()); } else if(w->frameGeometry().bottom() < screenRect.bottom()) { w->move(0, screenRect.bottom() - w->frameGeometry().bottom()); } } 
+2
source

Source: https://habr.com/ru/post/1340775/


All Articles