import sys from PyQt4 import QtGui class Example(QtGui.QWidget): def __init__(self): super(Example, self).__init__() self.initUI() def initUI(self): hbox = QtGui.QHBoxLayout() label1 = QtGui.QLabel('Label 1') hbox.addWidget(label1) frame = QtGui.QFrame() frame.setFrameShape(QtGui.QFrame.VLine) frame.setFrameShadow(QtGui.QFrame.Sunken) hbox.addWidget(frame) label2 = QtGui.QLabel('Label 2') hbox.addWidget(label2) self.setLayout(hbox) self.setGeometry(300, 300, 250, 150) self.setWindowTitle('QFrame') self.show() def main(): app = QtGui.QApplication(sys.argv) ex = Example() sys.exit(app.exec_()) if __name__ == '__main__': main()
import sys from PyQt4 import QtGui class Example(QtGui.QWidget): def __init__(self): super(Example, self).__init__() self.initUI() def initUI(self): frame = QtGui.QFrame(self) frame.setFrameShape(QtGui.QFrame.Panel) frame.setFrameShadow(QtGui.QFrame.Raised) frame.setStyleSheet("background-color: #FFB6C1; border: 2px solid #A52A2A;") hbox = QtGui.QHBoxLayout() hbox.addWidget(frame) self.setLayout(hbox) self.setGeometry(300, 300, 250, 150) self.setWindowTitle('QFrame') self.show() def main(): app = QtGui.QApplication(sys.argv) ex = Example() sys.exit(app.exec_()) if __name__ == '__main__': main()This example creates a QFrame widget and sets its shape to a panel and its shadow to raised. It then sets a custom stylesheet that changes the background color and adds a border. Finally, it adds the widget to a QHBoxLayout and sets the layout. Package library: PyQt4