vcl/inc/qt5/QtBuilder.hxx |    1 +
 vcl/qt5/QtBuilder.cxx     |   14 ++++++++++----
 2 files changed, 11 insertions(+), 4 deletions(-)

New commits:
commit df39550839451ab6ad9b1fd722beb56c43bd5aa3
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Sat Nov 23 01:11:38 2024 +0100
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Sat Nov 23 10:49:13 2024 +0100

    tdf#130857 qt weld: Hide widget marked for deletion
    
    Add a helper method QtBuilder::deleteObject
    that takes care of marking no longer needed
    objects for deletion and use it in the 3 places
    so far calling QObject::deleteLater themselves.
    
    If the object marked for deletion is a widget,
    hide it as well, as it could otherwise still
    be "in the way".
    This was seen wit the edit (QLineEdit) of the editable
    combobox in the "File" -> "Properties" dialog,
    "General" tab (in a WIP branch for adding support
    for that dialog), where the unnecessary edit was
    shown on top of the combobox, hiding the combobox
    content + dropdown button.
    
    Change-Id: Ie299b80824c94d40cfac9f7962c9bd4ba95b446d
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/177057
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>
    Tested-by: Jenkins

diff --git a/vcl/inc/qt5/QtBuilder.hxx b/vcl/inc/qt5/QtBuilder.hxx
index 6f0459d55b0d..dd31c9999c42 100644
--- a/vcl/inc/qt5/QtBuilder.hxx
+++ b/vcl/inc/qt5/QtBuilder.hxx
@@ -84,6 +84,7 @@ public:
     virtual void set_response(std::u16string_view sID, short nResponse) 
override;
 
 private:
+    static void deleteObject(QObject* pObject);
     void setProperties(QObject* obj, stringmap& rProps);
     static void setLabelProperties(QLabel& rLabel, stringmap& rProps);
     void setSpinButtonProperties(QDoubleSpinBox& rSpinBox, stringmap& rProps);
diff --git a/vcl/qt5/QtBuilder.cxx b/vcl/qt5/QtBuilder.cxx
index 044e3ea9d421..d73800d02d0d 100644
--- a/vcl/qt5/QtBuilder.cxx
+++ b/vcl/qt5/QtBuilder.cxx
@@ -348,7 +348,7 @@ void QtBuilder::tweakInsertedChild(QObject* pParent, 
QObject* pCurrentChild, std
         // an editable GtkComboBox has an internal GtkEntry child,
         // but QComboBox doesn't need a separate widget for it, so
         // delete it
-        pCurrentChild->deleteLater();
+        deleteObject(pCurrentChild);
     }
 
     if (sType == "label")
@@ -362,8 +362,7 @@ void QtBuilder::tweakInsertedChild(QObject* pParent, 
QObject* pCurrentChild, std
                 // For QGroupBox, the title can be set directly. Therefore, 
take over the
                 // title from the label and delete the separate label widget 
again
                 pGroupBox->setTitle(pLabel->text());
-                pLabel->setParent(nullptr);
-                pLabel->deleteLater();
+                deleteObject(pLabel);
             }
         }
     }
@@ -526,6 +525,13 @@ void QtBuilder::set_response(std::u16string_view sID, 
short nResponse)
     
pPushButton->setProperty(QtInstanceMessageDialog::PROPERTY_VCL_RESPONSE_CODE, 
int(nResponse));
 }
 
+void QtBuilder::deleteObject(QObject* pObject)
+{
+    if (pObject->isWidgetType())
+        static_cast<QWidget*>(pObject)->hide();
+    pObject->deleteLater();
+}
+
 void QtBuilder::setProperties(QObject* pObject, stringmap& rProps)
 {
     if (QMessageBox* pMessageBox = qobject_cast<QMessageBox*>(pObject))
@@ -604,7 +610,7 @@ void QtBuilder::setProperties(QObject* pObject, stringmap& 
rProps)
                 // parentless GtkImage in .ui file is only used for setting 
button
                 // image, so the object is no longer needed after doing so
                 if (!pImageLabel->parent())
-                    pImageLabel->deleteLater();
+                    deleteObject(pImageLabel);
             }
             else if (rKey == u"label")
             {

Reply via email to