Community
3ds Max Programming
Welcome to Autodesk’s 3ds Max Forums. Share your knowledge, ask questions, and explore popular 3ds Max SDK, Maxscript and Python topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Pyside Translucent Window Feature Not Working

3 REPLIES 3
Reply
Message 1 of 4
Huston94
3982 Views, 3 Replies

Pyside Translucent Window Feature Not Working

This is a pretty superficial post but I figured I'd add it anyway and see what comes of it.

 

I have been wanting to create more unique, visually pleasing interfaces for a while now. One of the main things I would love to add to a small window is a translucent/transparent effect on just the background of the Window (not buttons and text and everything else on top). I searched for this and came up with a few suggestions but none of them worked they were the following:

 

 

Setting the widget's QtCore.Qt.WA_TranslucentBackground attribute to true:

      - This just turns the background black.

 

 

self.setAttribute(QtCore.Qt.WA_TranslucentBackground, True)

 

Setting the window opacity to a given value between 0.0 and 1.0:

     - This set the opacity for EVERYTHING in the window. Buttons, fields, text, and all. Not what I hoped for.

 

 

self.setWindowOpacity(.75)

 

And there were other suggestions that I didn't understand nor did I know how to implement. I would love to be able to use a png file with transparency for the widget background and have it show through. Not sure if this is possible or not or if Max would even allow for it but I figured I'd ask anyway. Thanks.

 

 

 

Here are some images for the look I want to go for.

 

 

29366523_10155682072407917_164112276633157632_o.jpg

 

Flat-UI-KIT.jpgzen_ui_kit-760x570.jpg

3 REPLIES 3
Message 2 of 4
drew.avis
in reply to: Huston94

This is an interesting question.  With PySide, you could override the paint event of a QWidget to control the transparency, but that no longer seems to be working with PySide2.  I wonder if you could do something in QML?  I'll have to try this out when I have a chance.

 

Drew



Drew Avis
Content Experience Designer
Message 3 of 4
Huston94
in reply to: drew.avis

Yeah the Paint Event thing was something else I saw while researching into this. I just don't really know what it is, how it works, or how to go about manipulating it. lol

Message 4 of 4
drew.avis
in reply to: Huston94

Alrighty, I have good news and bad news.  The good news is I have a demo that gives you a semi-transparent background and non-transparent child widgets in Pyside2 in Max.  The bad news is that this requires setting Qt.FramelessWindowHint, which means you can't easily move or resize the window (at least not using the native windowing system).  Anyway, here's the demo, maybe you can do something with it:

 

# Transparent PySide Widget
from PySide2 import QtGui, QtCore, QtWidgets
import MaxPlus

# protect from garbage collection:
class _GCProtector(object):
	widgets = []

def main():		
	w = TranspGui()
	w.run()

class TranspGui( QtWidgets.QWidget):
	def __init__(self, parent=MaxPlus.GetQMaxMainWindow()):		
		QtWidgets.QWidget.__init__(self)		
		self.setWindowFlags(QtCore.Qt.FramelessWindowHint) 
		self.setAttribute(QtCore.Qt.WA_TranslucentBackground)		

		emptylbl = QtWidgets.QLabel("",self)
		groupBox = QtWidgets.QGroupBox("Demo", self)
		main_layout = QtWidgets.QVBoxLayout()
	
		self.load_btn = QtWidgets.QPushButton("A Button")
		self.load_btn.setAutoFillBackground(True)
		main_layout.addWidget(self.load_btn)
		
		self.text_lbl = QtWidgets.QLabel("Transparent GUI")
		self.text_lbl.setSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
		self.text_lbl.setFixedSize(200,200)
		self.text_lbl.setWordWrap(True)
		main_layout.addWidget(self.text_lbl)
		
		self.image_lbl = QtWidgets.QLabel(self)
		main_layout.addWidget(self.image_lbl)
		# self.image_lbl.setFixedSize(200,300)

		self.prev_btn = QtWidgets.QPushButton("Another Button")
		main_layout.addWidget(self.prev_btn)	
		
		self.next_btn = QtWidgets.QPushButton("More Buttons")
		# self.next_btn.clicked.connect(self.click_next)
		main_layout.addWidget(self.next_btn)	
	
		self.close_btn = QtWidgets.QPushButton("Close")
		self.close_btn.clicked.connect(self.click_close)
		main_layout.addWidget(self.close_btn)	
		
		groupBox.setLayout(main_layout)	
		#groupBox.move(100,200)
		
		self.resize(400, 400)	
		_GCProtector.widgets.append(self)			
	
	
	def run(self):
		self.show()
		
	def click_close(self):
		self.hide()
	
	def paintEvent(self, e):
		super(TranspGui, self).paintEvent(e)
		painter = QtGui.QPainter()
		painter.begin(self)		
		painter.fillRect( 0, 0, self.width(), self.height(), QtGui.QColor( 0,0,0,200))
		painter.setCompositionMode(QtGui.QPainter.CompositionMode_Source)
		painter.end()

if __name__ == '__main__':
	main()


Drew Avis
Content Experience Designer

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report