fix height/width
This commit is contained in:
parent
48fca35a78
commit
b215e0ecb3
@ -2,14 +2,14 @@ import json
|
|||||||
from datetime import date
|
from datetime import date
|
||||||
|
|
||||||
from qgis.PyQt.QtWidgets import (
|
from qgis.PyQt.QtWidgets import (
|
||||||
QDialog, QVBoxLayout, QHBoxLayout, QFormLayout,
|
QDialog, QVBoxLayout, QHBoxLayout, QFormLayout, QLayout,
|
||||||
QLabel, QLineEdit, QPushButton, QMessageBox, QComboBox,
|
QLabel, QLineEdit, QPushButton, QMessageBox, QComboBox,
|
||||||
QDateEdit, QSpinBox, QCheckBox, QScrollArea, QWidget,
|
QDateEdit, QSpinBox, QCheckBox, QScrollArea, QWidget,
|
||||||
QListWidget, QListWidgetItem, QInputDialog, QSizePolicy,
|
QListWidget, QListWidgetItem, QInputDialog, QSizePolicy,
|
||||||
QFrame, QGroupBox
|
QFrame, QGroupBox
|
||||||
)
|
)
|
||||||
from qgis.PyQt.QtCore import Qt, QDate
|
from qgis.PyQt.QtCore import Qt, QDate
|
||||||
from qgis.PyQt.QtGui import QFont, QColor
|
from qgis.PyQt.QtGui import QFont, QColor, QGuiApplication
|
||||||
from qgis.core import QgsCoordinateReferenceSystem, QgsCoordinateTransform, QgsProject
|
from qgis.core import QgsCoordinateReferenceSystem, QgsCoordinateTransform, QgsProject
|
||||||
from qgis.utils import iface
|
from qgis.utils import iface
|
||||||
|
|
||||||
@ -162,10 +162,52 @@ class SaisieDialog(QDialog):
|
|||||||
|
|
||||||
self.setWindowTitle("Animation – Saisie / Édition")
|
self.setWindowTitle("Animation – Saisie / Édition")
|
||||||
self.setMinimumWidth(720)
|
self.setMinimumWidth(720)
|
||||||
self.setMinimumHeight(820)
|
# Hauteur modérée : le formulaire long est dans un QScrollArea ; un minimum
|
||||||
|
# trop grand empêche le dialogue de tenir au-dessus de la barre des tâches.
|
||||||
|
self.setMinimumHeight(180)
|
||||||
|
# Permet d'agrandir / redimensionner librement (coins et bords) sur Windows.
|
||||||
|
self.setWindowFlags(
|
||||||
|
self.windowFlags() | Qt.WindowMinMaxButtonsHint
|
||||||
|
)
|
||||||
|
self._did_screen_fit = False
|
||||||
self._build_ui()
|
self._build_ui()
|
||||||
self._load_reference_data()
|
self._load_reference_data()
|
||||||
|
|
||||||
|
def showEvent(self, event):
|
||||||
|
super().showEvent(event)
|
||||||
|
if self._did_screen_fit:
|
||||||
|
return
|
||||||
|
self._did_screen_fit = True
|
||||||
|
screen = QGuiApplication.screenAt(self.frameGeometry().center())
|
||||||
|
if screen is None:
|
||||||
|
screen = QGuiApplication.primaryScreen()
|
||||||
|
if screen is None:
|
||||||
|
return
|
||||||
|
avail = screen.availableGeometry()
|
||||||
|
fh = self.fontMetrics().height()
|
||||||
|
margin = max(16, fh)
|
||||||
|
max_h = max(360, avail.height() - margin * 2)
|
||||||
|
max_w = max(560, avail.width() - margin * 2)
|
||||||
|
if self.minimumHeight() > max_h:
|
||||||
|
self.setMinimumHeight(max(340, max_h - fh * 2))
|
||||||
|
if self.minimumWidth() > max_w:
|
||||||
|
self.setMinimumWidth(max(400, max_w - fh))
|
||||||
|
target_h = min(max(self.height(), self.minimumHeight()), max_h)
|
||||||
|
target_w = min(max(self.width(), self.minimumWidth()), max_w)
|
||||||
|
self.resize(target_w, target_h)
|
||||||
|
fg = self.frameGeometry()
|
||||||
|
dx = dy = 0
|
||||||
|
if fg.right() > avail.right() - margin:
|
||||||
|
dx = avail.right() - margin - fg.right()
|
||||||
|
if fg.bottom() > avail.bottom() - margin:
|
||||||
|
dy = avail.bottom() - margin - fg.bottom()
|
||||||
|
if fg.left() + dx < avail.left() + margin:
|
||||||
|
dx = avail.left() + margin - fg.left()
|
||||||
|
if fg.top() + dy < avail.top() + margin:
|
||||||
|
dy = avail.top() + margin - fg.top()
|
||||||
|
if dx or dy:
|
||||||
|
self.move(fg.x() + dx, fg.y() + dy)
|
||||||
|
|
||||||
# -----------------------------------------------------------------------
|
# -----------------------------------------------------------------------
|
||||||
# Construction UI
|
# Construction UI
|
||||||
# -----------------------------------------------------------------------
|
# -----------------------------------------------------------------------
|
||||||
@ -199,12 +241,24 @@ class SaisieDialog(QDialog):
|
|||||||
# --- Zone scrollable du formulaire ---
|
# --- Zone scrollable du formulaire ---
|
||||||
scroll = QScrollArea()
|
scroll = QScrollArea()
|
||||||
scroll.setWidgetResizable(True)
|
scroll.setWidgetResizable(True)
|
||||||
|
scroll.setFrameShape(QFrame.StyledPanel)
|
||||||
|
scroll.setHorizontalScrollBarPolicy(Qt.ScrollBarAsNeeded)
|
||||||
|
scroll.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded)
|
||||||
|
scroll.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
|
||||||
container = QWidget()
|
container = QWidget()
|
||||||
self.fl = QFormLayout(container)
|
self.fl = QFormLayout(container)
|
||||||
self.fl.setLabelAlignment(Qt.AlignRight)
|
self.fl.setLabelAlignment(Qt.AlignRight)
|
||||||
self.fl.setSpacing(8)
|
self.fl.setSpacing(8)
|
||||||
|
# Sans cela, le QFormLayout impose la hauteur totale du formulaire au dialogue
|
||||||
|
# (barres de défilement inutiles, fenêtre non réductible sous la barre des tâches).
|
||||||
|
if hasattr(self.fl, "setSizeConstraint"):
|
||||||
|
self.fl.setSizeConstraint(QLayout.SetNoConstraint)
|
||||||
|
else:
|
||||||
|
# Qt 6 : SetNoConstraint supprimé — laisser la hauteur être pilotée par la zone de scroll.
|
||||||
|
container.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Ignored)
|
||||||
scroll.setWidget(container)
|
scroll.setWidget(container)
|
||||||
main_layout.addWidget(scroll)
|
main_layout.addWidget(scroll)
|
||||||
|
main_layout.setStretch(main_layout.indexOf(scroll), 1)
|
||||||
|
|
||||||
fl = self.fl
|
fl = self.fl
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user