def __init__(self): super().__init__() self.setWindowTitle("My App") pagelayout = QVBoxLayout() button_layout = QHBoxLayout() self.stacklayout = QStackedLayout() pagelayout.addLayout(button_layout) pagelayout.addLayout(self.stacklayout) btn = QPushButton("red") btn.pressed.connect(self.activate_tab_1) button_layout.addWidget(btn) self.stacklayout.addWidget(Color("red")) btn = QPushButton("green") btn.pressed.connect(self.activate_tab_2) button_layout.addWidget(btn) self.stacklayout.addWidget(Color("green")) btn = QPushButton("yellow") btn.pressed.connect(self.activate_tab_3) button_layout.addWidget(btn) self.stacklayout.addWidget(Color("yellow")) widget = QWidget() widget.setLayout(pagelayout) self.setCentralWidget(widget)
def __init__(self): super().__init__() self.setWindowTitle('My App') pagelayout = QVBoxLayout() button_layout = QHBoxLayout() self.stacklayout = QStackedLayout() pagelayout.addLayout(button_layout) pagelayout.addLayout(self.stacklayout) btn = QPushButton('red') btn.pressed.connect(self.activation_tab_0) button_layout.addWidget(btn) self.stacklayout.addWidget(Color('red')) btn = QPushButton('green') btn.pressed.connect(self.activation_tab_1) button_layout.addWidget(btn) self.stacklayout.addWidget(Color('green')) btn = QPushButton('blue') btn.pressed.connect(self.activation_tab_2) button_layout.addWidget(btn) self.stacklayout.addWidget(Color('blue')) btn = QPushButton('yellow') btn.pressed.connect(self.activation_tab_3) button_layout.addWidget(btn) self.stacklayout.addWidget(Color('yellow')) widget = QWidget() widget.setLayout(pagelayout) self.setCentralWidget(widget)
def __init__(self): super().__init__() self.setWindowTitle('My App') layout = QHBoxLayout() layout.addWidget(Color('red')) layout.addWidget(Color('green')) layout.addWidget(Color('blue')) widget = QWidget() widget.setLayout(layout) self.setCentralWidget(widget)
def __init__(self): super().__init__() self.setWindowTitle("QColor demo") layout = QVBoxLayout() layout.addWidget(Color("green")) layout.addWidget(Color("blue")) layout.addWidget(Color("red")) widget = QWidget() widget.setLayout(layout) self.setCentralWidget(widget)
def __init__(self): super(MainWindow, self).__init__() self.setWindowTitle("My App") layout = QHBoxLayout() layout.addWidget(Color("red")) layout.addWidget(Color("green")) layout.addWidget(Color("blue")) widget = QWidget() widget.setLayout(layout) self.setCentralWidget(widget)
def __init__(self): super().__init__() self.setWindowTitle('My App') layout = QGridLayout() layout.addWidget(Color('red'), 0, 0) layout.addWidget(Color('green'), 1, 0) layout.addWidget(Color('blue'), 1, 1) layout.addWidget(Color('purple'), 2, 1) widget = QWidget() widget.setLayout(layout) self.setCentralWidget(widget)
def __init__(self): super().__init__() self.setWindowTitle("My App") layout = QGridLayout() layout.addWidget(Color("red"), 0, 0) layout.addWidget(Color("green"), 1, 0) layout.addWidget(Color("blue"), 1, 1) layout.addWidget(Color("purple"), 2, 1) widget = QWidget() widget.setLayout(layout) self.setCentralWidget(widget)
def __init__(self): super().__init__() self.setWindowTitle("My App") widget = Color("red") self.setCentralWidget(widget)
def __init__(self): super(MainWindow, self).__init__() layout = QStackedLayout() layout.addWidget(Color("red")) layout.addWidget(Color("green")) layout.addWidget(Color("blue")) layout.addWidget(Color("yellow")) layout.setCurrentIndex(3) widget = QWidget() widget.setLayout(layout) self.setCentralWidget(widget)
def __init__(self): super().__init__() self.setWindowTitle("My App") layout = QStackedLayout() layout.addWidget(Color("red")) layout.addWidget(Color("green")) layout.addWidget(Color("blue")) layout.addWidget(Color("yellow")) layout.setCurrentIndex(1) widget = QWidget() widget.setLayout(layout) self.setCentralWidget(widget)
def __init__(self): super().__init__() self.setWindowTitle("a0") self.setFixedSize(500,300) layout1 = QHBoxLayout() layout2 = QVBoxLayout() layout3 = QVBoxLayout() layout2.addWidget(Color("red")) layout2.addWidget(Color("purple")) layout2.addWidget(Color("green")) layout3.addWidget(Color("red")) layout3.addWidget(Color("black")) layout3.addWidget(Color("green")) layout1.addLayout(layout2) layout1.addLayout(layout3) layout1.addWidget(Color("green")) layout1.setContentsMargins(0,0,0,0) layout1.setSpacing(20) widget = QWidget() widget.setLayout(layout1) self.setCentralWidget(widget)
def __init__(self): super().__init__() self.setWindowTitle("QGridLayout ") self.setFixedSize(500, 300) layout = QGridLayout() layout.addWidget(Color("red"), 1, 0) layout.addWidget(Color("purple"), 0, 1) layout.addWidget(Color("green"), 1, 2) layout.addWidget(Color("blue"), 2, 1) layout.addWidget(Color("pink"), 1, 3) widget = QWidget() widget.setLayout(layout) self.setCentralWidget(widget)
def __init__(self): super(MainWindow, self).__init__() self.setWindowTitle("My App") layout = QVBoxLayout() layout.addWidget(Color('red')) widget = QWidget() widget.setLayout(layout) self.setCentralWidget(widget)
def __init__(self): super().__init__() self.setWindowTitle("MyApp") layout1 = QHBoxLayout() layout2 = QVBoxLayout() layout3 = QVBoxLayout() layout1.setContentsMargins(5,5,5,5) layout1.setSpacing(0) layout2.addWidget(Color("red")) layout2.addWidget(Color("yellow")) layout2.addWidget(Color("purple")) layout1.addLayout(layout2) layout1.addWidget(Color("green")) layout3.addWidget(Color("red")) layout3.addWidget(Color("purple")) layout1.addLayout(layout3) widget = QWidget() widget.setLayout(layout1) self.setCentralWidget(widget)
def __init__(self): super(MainWindow, self).__init__() self.setWindowTitle("My App") layout1 = QHBoxLayout() layout2 = QVBoxLayout() layout3 = QVBoxLayout() layout2.addWidget(Color("red")) layout2.addWidget(Color("yellow")) layout2.addWidget(Color("purple")) layout1.addLayout(layout2) layout1.addWidget(Color('green')) layout3.addWidget(Color("red")) layout3.addWidget(Color("purple")) layout1.addLayout(layout3) widget = QWidget() widget.setLayout(layout1) self.setCentralWidget(widget)
def __init__(self): super().__init__() self.setWindowTitle('My App') tabs = QTabWidget() tabs.setTabPosition(QTabWidget.West) tabs.setMovable(True) for color in ['red', 'green', 'blue', 'yellow']: tabs.addTab(Color(color), color) self.setCentralWidget(tabs)
def __init__(self): super().__init__() self.setWindowTitle("My App") tabs = QTabWidget() tabs.setTabPosition(QTabWidget.North) tabs.setMovable(True) for n, color in enumerate(["red", "green", "blue", "yellow"]): tabs.addTab(Color(color), color) self.setCentralWidget(tabs)
def __init__(self): super().__init__() self.setWindowTitle("QStackedLayout + Box DEMO") page_layout = QVBoxLayout() button_layout = QHBoxLayout() self.stackLayout = QStackedLayout() page_layout.addLayout( button_layout) # The page's button would be a vertical layout page_layout.addLayout(self.stackLayout) btn = QPushButton("red") btn.pressed.connect(self.tab_1_active) button_layout.addWidget(btn) btn = QPushButton("green") btn.pressed.connect(self.tab_2_active) button_layout.addWidget(btn) btn = QPushButton("blue") btn.pressed.connect(self.tab_3_active) button_layout.addWidget(btn) btn = QPushButton("purple") btn.pressed.connect(self.tab_4_active) button_layout.addWidget(btn) widget = QWidget() widget.setLayout(page_layout) self.setCentralWidget(widget) self.stackLayout.addWidget(Color("red")) self.stackLayout.addWidget(Color("green")) self.stackLayout.addWidget(Color("blue")) self.stackLayout.addWidget(Color("purple"))
def __init__(self): super().__init__() self.setWindowTitle('My Application') rgb = {0: "Red", 1: "Green", 2: "Blue"} tabs = QTabWidget() tabs.setTabPosition(QTabWidget.North) tabs.setMovable(True) for i, color in enumerate(["red", "green", "blue"]): tabs.addTab(Color(color), color) tabs.tabBarClicked.connect(lambda x: self.tab_clicked(x, dict=rgb)) tabs.currentChanged.connect(lambda x: self.tab_switched(x, dict=rgb)) self.setCentralWidget(tabs)
def __init__(self): super().__init__() self.setWindowTitle('My App') layout1 = QHBoxLayout() layout2 = QVBoxLayout() layout3 = QVBoxLayout() layout2.addWidget(Color('red')) layout2.addWidget(Color('yellow')) layout2.addWidget(Color('purple')) layout1.addLayout(layout2) layout1.addWidget(Color('green')) layout3.addWidget(Color('red')) layout3.addWidget(Color('purple')) layout1.addLayout(layout3) widget = QWidget() widget.setLayout(layout1) self.setCentralWidget(widget)
def __init__(self): super(MainWindow, self).__init__() self.setWindowTitle("My App") color = Color("red") self.setCentralWidget(color)
def __init__(self): super().__init__() self.setWindowTitle('My App') #layout = qtw.QVBoxLayout() # layout = qtw.QHBoxLayout() # # Nested layout # # W: ABC # # W.A: VBox # # W.B: widget # # W.C: VBox # W = qtw.QHBoxLayout() # A = qtw.QVBoxLayout() # B = Color('green') # C = qtw.QVBoxLayout() # # A.addWidget(Color('red')) # A.addWidget(Color('yellow')) # A.addWidget(Color('purple')) # # C.addWidget(Color('red')) # C.addWidget(Color('purple')) # # W.addLayout(A) # W.addWidget(B) # W.addLayout(C) # # W.setContentsMargins(5, 10, 15, 20) # W.setSpacing(1) # W = layout = qtw.QGridLayout() # layout.addWidget(Color('red'), 0, 0) # layout.addWidget(Color('green'), 1, 0) # layout.addWidget(Color('blue'), 1, 1) # layout.addWidget(Color('purple'), 2, 1) # W = layout = qtw.QStackedLayout() # # red = Color('red') # # layout.addWidget(red) # layout.addWidget(Color('green')) # layout.addWidget(Color('blue')) # layout.addWidget(Color('yellow')) # # # 2 ways to set # layout.setCurrentWidget(red) # red # #layout.setCurrentIndex(3) # yellow # # W: # # AAAA # # BBBB # # BBBB # # # # W: main widget # # W.A: buttons # # W.B: display area # # W = page_layout = qtw.QVBoxLayout() # A = button_layout = qtw.QHBoxLayout() # B = self.stack_layout = qtw.QStackedLayout() # # W.addLayout(A) # W.addLayout(B) # # btn = qtw.QPushButton('Red') # btn.clicked.connect(lambda: self.activate_tab(0)) # A.addWidget(btn) # B.addWidget(Color('red')) # # btn = qtw.QPushButton('Green') # btn.clicked.connect(lambda: self.activate_tab(1)) # A.addWidget(btn) # B.addWidget(Color('green')) # # btn = qtw.QPushButton('Blue') # btn.clicked.connect(lambda: self.activate_tab(2)) # A.addWidget(btn) # B.addWidget(Color('blue')) # # btn = qtw.QPushButton('Yellow') # btn.clicked.connect(lambda: self.activate_tab(3)) # A.addWidget(btn) # B.addWidget(Color('yellow')) # # B.setCurrentIndex(0) # # widget = qtw.QWidget() # widget.setLayout(W) widget = tabs = qtw.QTabWidget() tabs.setTabPosition(tabs.West) tabs.setMovable(True) for ind,color in enumerate(['red', 'green', 'blue', 'yellow']): tabs.addTab(Color(color), color) self.setCentralWidget(widget)