remove widget bug

remove widget bug

elpie89
Advocate Advocate
1,055 Views
2 Replies
Message 1 of 3

remove widget bug

elpie89
Advocate
Advocate
import pymxs
from PySide2 import QtCore
from PySide2 import QtWidgets
import MaxPlus

class PyMaxDialog(QtWidgets.QDialog):
	def __init__(self, parent=MaxPlus.GetQMaxMainWindow()):
		super(PyMaxDialog, self).__init__(parent)
		self.setWindowTitle('Pyside Qt Window')
		self.initUI()
		
	def initUI(self):
		self.main_layout = QtWidgets.QVBoxLayout()
		self.label = QtWidgets.QLabel("Click button delete this text")
		self.main_layout.addWidget(self.label)

		delete_btn = QtWidgets.QPushButton("Delete")
		delete_btn.clicked.connect(self.remove_text)
		self.main_layout.addWidget(delete_btn)

		self.setLayout(self.main_layout)
		self.resize(250, 100)
	
	@QtCore.Slot()
	def remove_text(self):
		self.main_layout.removeWidget(self.label)
		pymxs.runtime.RedrawViews()		

def main():
	w = PyMaxDialog()
	w.show()

if __name__ == '__main__':
	main()

execute this code and click on the Delete button.

those are before/ and after images

3ae58377aceda5603b00c758bd355b519df877d0.png7f4a2d4c1b1f48166f9e93a870d14ac7b42d25cc.png

Is this normal?

for me, this looks like a bug

I tested this in max 2019 on two different machine

0 Likes
Accepted solutions (1)
1,056 Views
2 Replies
Replies (2)
Message 2 of 3

drew_avis
Autodesk
Autodesk
Accepted solution

I see the same thing on 2020.  However, I think this is expected PySide behaviour, not a bug, and other people see the same thing in non-3ds Max apps, eg:

https://stackoverflow.com/questions/9899409/pyside-removing-a-widget-from-a-layout

 

It looks like once you call removeWidget(), you are now responsible for deleting that widget (the layout no longer owns it).

 

I was able to fix your example by changing remove_text() to this:

	@QtCore.Slot()
	def remove_text(self):
		self.main_layout.removeWidget(self.label)
		self.label.deleteLater()
		self.update()

Hope that helps,

Drew



Drew Avis
Content Experience Designer
0 Likes
Message 3 of 3

elpie89
Advocate
Advocate

ok I didn't try with the deleteLater method

I used instead 

self.label.hide()
self.main_layout.removeWidget(self.label)
del(self.label)

It worked as well, anyway the default behavior is strange

Anyway, problem solved.

Thanks

 

0 Likes