Vred 2024 can't set fixed width on button

Vred 2024 can't set fixed width on button

Bob.Bon2000
Collaborator Collaborator
264 Views
1 Reply
Message 1 of 2

Vred 2024 can't set fixed width on button

Bob.Bon2000
Collaborator
Collaborator

Hey

 

 

from PySide6.QtWidgets import *
w = QWidget()
lay = QGridLayout(w)

for a in range(0,3):
    btn = QPushButton(str(a))
    btn.setFixedWidth(5)
    btn.setFixedHeight(50)
    lay.addWidget(btn)
    
w.show()

 

 

How can I make it work? Its ignoring my fixed width request.


Thanks.

0 Likes
265 Views
1 Reply
Reply (1)
Message 2 of 2

__daniel.lincoln__
Autodesk
Autodesk

Hi Bob,

 

I understand this can be changed (overridden) by using setStyleSheet(...).

 

Here is an example:

from PySide6.QtWidgets import *
w = QWidget()
lay = QGridLayout(w)

button_width = [100, 200, 300]

for a in range(0,3):
    btn = QPushButton(str(button_width[a])+'px')
    btn.setFixedWidth(5)
    btn.setFixedHeight(50)
    
    btn.setStyleSheet('''
        QPushButton {
            ''' f'min-width:{button_width[a]}px;' '''
            }
        ''')
    lay.addWidget(btn)

w.show()

 vred_2024_button_width.png

0 Likes