<div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr">Il giorno mar 5 mar 2019 alle ore 16:31 Sibylle Koczian <<a href="mailto:nulla.epistola@web.de">nulla.epistola@web.de</a>> ha scritto:<br>> Am 05.03.2019 um 09:43 schrieb J Barchan:<br>> > I had to deal with this.  I did not take @Maurizio's approach.  I do not<br>> > know what his solution does about QDateEdit.setData/data() for an empty<br>> > date, and other things.  Until now I didn't know you could get at its<br>> > QLineEdit.  For my part I chose to have a QLineEdit plus an associated<br>> > ... button to its right which leads to a modal dialog.  I paste extracts<br>> > below, feel free to cannibalise it if you want my approach. If @Maurizio<br>> > wishes to criticize mine, that's fine, I will read and consider!<br><br>Well, Jonathan, your implementation seems fine, and, as long as it works, who am I to judge? ;-)</div><div dir="ltr"><div>The only issue in this case might be that you wouldn't be able to take advantage of the "automatic" systems used to fill/read the editor of a delegate, since the lineEdit is not publicly exposed, thus its methods won't be too.</div><div>By using parenting, you'll be able to keep all original methods of the QLineEdit and still have that extra button for "advanced" editing. This is useful even in non-delegate scenarios, as it will make coding easier by directly using the QLineEdit subclass.<br>Here's what I'd do (this is just a simple QLineEdit, obviously without the date implementation):</div><div><br></div><div><div><font face="monospace, monospace">class LineEditWithDotButton(QtWidgets.QLineEdit):</font></div><div><font face="monospace, monospace">    advancedEditRequested = QtCore.Signal(str)</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">    def __init__(self, *args, **kwargs):</font></div><div><font face="monospace, monospace">        QtWidgets.QLineEdit.__init__(self, *args, **kwargs)</font></div><div><font face="monospace, monospace">        self.editBtn = QtWidgets.QToolButton(self)</font></div><div><font face="monospace, monospace">        self.editBtn.setText('...')</font></div><div><span style="font-family:monospace,monospace">        self.editBtn.setCursor(QtCore.Qt.ArrowCursor)</span><br></div><div><font face="monospace, monospace">        self.editBtn.setFocusPolicy(QtCore.Qt.NoFocus)<br></font></div><div><font face="monospace, monospace">        self.margin = 4</font></div><div><span style="font-family:monospace,monospace">        l, t, r, b = self.getContentsMargins()</span><br></div><div><font face="monospace, monospace">        self.setContentsMargins(l, t, r + self.editBtn.sizeHint().width() + self.margin, b)</font></div><div><font face="monospace, monospace">        self.editBtn.clicked.connect(lambda: self.advancedEditRequested.emit(self.text())</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">    def showEvent(self, event):</font></div><div><font face="monospace, monospace">        self.moveEditButton()</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">    def resizeEvent(self, event):</font></div><div><font face="monospace, monospace">        self.moveEditButton()</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">    def moveEditButton(self):</font></div><div><font face="monospace, monospace">        self.editBtn.setFixedHeight(self.height())</font></div><div><font face="monospace, monospace">        self.editBtn.move(self.width() - self.getContentsMargins()[2] + self.margin, 0)</font></div><div><br></div></div><div>I've used a QToolButton as standard QPushButtons with text have the issue of fixed minimum size which could obviously be worked around, but since a QToolButton is fine enough for this case, there's no need to add more headaches. ;-)</div><div>The cursor is overridden, since the button is child of the line edit it would use the IBeamCursor and that's not very good for UX. There will be some space where the IBeamCursor is still active (the margin between the edit and the button), if you're not happy with it you can setMouseTracking(True) and use setCursor() in the mouseMoveEvent() implementation. I also used existing content margins, as the current style or (inherited) stylesheet might set them.</div><div><br></div><div>> I think in Maurizios approach much depends on the delegate that's used.<br></div><div><br></div><div>Yes, it is necessary to apply some "magic" to the delegate by letting it "talk" with the editor.<br>The basic idea is that if the setEditorData() argument contains an invalid date, it sets an internal bool property, which can be reset whenever the user types/select a valid date. That property can later be checked back in the setModelData, to avoid invalid submissions to the model.<br><br>Well, good luck ;-)</div><div><br></div><div>Maurizio<br><br>--<br>È difficile avere una convinzione precisa quando si parla delle ragioni del cuore. - "Sostiene Pereira", Antonio Tabucchi<br><a href="http://www.jidesk.net">http://www.jidesk.net</a></div></div></div></div></div></div></div>