PDA

View Full Version : adding QFrame around several widgets



Nfrancisj
28th January 2017, 02:20
Hi,
I have some widgets (see pic) and im trying to put a border around them all.
The code below is adding the border around all the widgets individually instead of globally.
What am I doing wrong? How to I get the result seem in the example image?

thanks


Class myFrame(QFrame):
def __init__(self):
super(myFrame, self).__init__()

self.setStyleSheet("border: 1px solid black")
self.label = QLabel('Tracker01')
self.setMinimumWidth(60)
self.label.setMaximumWidth(100)
self.colorSwatch = QFrame()
self.colorSwatch.setFixedWidth(20)
self.colorSwatch.setFixedHeight(20)
self.colorSwatch.setStyleSheet("border: 1px solid black")

self.X_LineEdit = QLineEdit()
self.Y_LineEdit = QLineEdit()
self.Z_LineEdit = QLineEdit()
self.X_LineEdit.setMaximumWidth(60)
self.Y_LineEdit.setMaximumWidth(60)
self.Z_LineEdit.setMaximumWidth(60)

self.X_Label = QLabel('x')
self.Y_Label = QLabel('y')
self.Z_Label = QLabel('z')
self.X_Label.setMaximumWidth(10)
self.Y_Label.setMaximumWidth(10)
self.Z_Label.setMaximumWidth(10)


self.CopyValues = QPushButton('Cp')
self.CreateCard = QPushButton('Cr')
self.MarkPoint = QPushButton('Mk')
self.CopyValues.setMaximumWidth(30)
self.CreateCard.setMaximumWidth(30)
self.MarkPoint.setMaximumWidth(30)

self.layout = QHBoxLayout()
self.layout.addWidget(self.label)
self.layout.addWidget(self.colorSwatch)
self.layout.addWidget(self.X_Label)
self.layout.addWidget(self.X_LineEdit)
self.layout.addWidget(self.Y_Label)
self.layout.addWidget(self.Y_LineEdit)
self.layout.addWidget(self.Z_Label)
self.layout.addWidget(self.Z_LineEdit)
self.layout.addWidget(self.CreateCard)
self.layout.addWidget(self.CopyValues)
self.layout.addWidget(self.MarkPoint)

self.setLayout(self.layout)


class myPanel(QDialog):
def __init__(self):
super(myPanel, self).__init__()

self.masterLayout = QGridLayout()
self.masterLayout.addWidget(myFrame(),0,0)
self.masterLayout.addWidget(myFrame(),1,0)
self.setLayout(self.masterLayout)


12304
12305

anda_skoa
28th January 2017, 08:16
You are setting a stylesheet without any class or object selector.
It also gets applied to the labels.

The outer frame is your frame class, the inner rectangles are the frames of the labels.

Cheers,
_

Nfrancisj
28th January 2017, 08:24
Oh..right! 😄

Thanks!