Once upon a time, I tried to find a way to bind the QDialog window to the border screens for my small projects like Skype windows, but I failed. Maybe I was looking for this code in the wrong place, so now I'm looking for a solution here on the stack! :)
So, does anyone have a deal with some such code, links, samples?
In my opinion, we need to override the QDialog moveEvent function, as shown below, but this code does not work:
void CDialog::moveEvent(QMoveEvent * event) {
QRect wndRect;
int leftTaskbar = 0, rightTaskbar = 0, topTaskbar = 0, bottomTaskbar = 0;
wndRect = this->frameGeometry();
int screenWidth = QApplication::desktop()->width();
int screenHeight = QApplication::desktop()->height();
int wndWidth = wndRect.right() - wndRect.left();
int wndHeight = wndRect.bottom() - wndRect.top();
int posX = event->pos().x();
int posY = event->pos().y();
if (posX >= -m_nXOffset + leftTaskbar &&
posX <= leftTaskbar + m_nXOffset) {
this->move(leftTaskbar, posY);
return;
}
if (posY >= -m_nYOffset &&
posY <= topTaskbar + m_nYOffset) {
this->move(posX, topTaskbar);
return;
}
if (posX + wndWidth <= screenWidth - rightTaskbar + m_nXOffset &&
posX + wndWidth >= screenWidth - rightTaskbar - m_nXOffset) {
this->move(screenWidth - rightTaskbar - wndWidth, posY);
return;
}
if (posY + wndHeight <= screenHeight - bottomTaskbar + m_nYOffset &&
posY + wndHeight >= screenHeight - bottomTaskbar - m_nYOffset) {
this->move(posX, screenHeight - bottomTaskbar - wndHeight);
return;
}
QDialog::moveEvent(event);
}
Thank.
source
share