Il ya longtemps, j'ai essayé de trouver une méthode pour coller la fenêtre QDialog à l'écran des frontières pour mes petits projets comme Skype Windows le faire, mais j'ai échoué. Peut-être que je regardais ce code pas au bon endroit, alors maintenant je regarde la solution ici, sur la pile! :)Comment coller QDialog à l'écran Bordures comme Skype faire?
Alors, est-ce que quelqu'un a un accord avec une sorte de code, des liens, des échantillons?
À mon avis, nous devons réimplémenter fonction QDialog moveEvent, comme ci-dessous, mais ce code ne fonctionne pas ne:
void CDialog::moveEvent(QMoveEvent * event) {
QRect wndRect;
int leftTaskbar = 0, rightTaskbar = 0, topTaskbar = 0, bottomTaskbar = 0;
// int top = 0, left = 0, right = 0, bottom = 0;
wndRect = this->frameGeometry();
// Screen resolution
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();
// Snap to screen border
// Left border
if (posX >= -m_nXOffset + leftTaskbar &&
posX <= leftTaskbar + m_nXOffset) {
//left = leftTaskbar;
this->move(leftTaskbar, posY);
return;
}
// Top border
if (posY >= -m_nYOffset &&
posY <= topTaskbar + m_nYOffset) {
//top = topTaskbar;
this->move(posX, topTaskbar);
return;
}
// Right border
if (posX + wndWidth <= screenWidth - rightTaskbar + m_nXOffset &&
posX + wndWidth >= screenWidth - rightTaskbar - m_nXOffset) {
//right = screenWidth - rightTaskbar - wndWidth;
this->move(screenWidth - rightTaskbar - wndWidth, posY);
return;
}
// Bottom border
if (posY + wndHeight <= screenHeight - bottomTaskbar + m_nYOffset &&
posY + wndHeight >= screenHeight - bottomTaskbar - m_nYOffset) {
//bottom = screenHeight - bottomTaskbar - wndHeight;
this->move(posX, screenHeight - bottomTaskbar - wndHeight);
return;
}
QDialog::moveEvent(event);
}
Merci.
@Patrice Bernassola: Merci pour votre réponse. Je pense que je dois mettre à jour mon échantillon, car il est plus prêt pour les tests/éditions ... Comme je suis un utilisateur linux depuis longtemps, dans KDE il y a des solutions globales pour ce cas: toutes les fenêtres/boîtes de dialogue peuvent être collées aux frontières de Windows, alors peut-être c'est une bonne idée de regarder dans les sources de KDE ... – mosg