move GroupBox position without menubar and tools in PyQt5 - python

I want to move the position of groupbox in window but menubar and tools are also moved.
how do I fix it and just move the position of GroupBox? (The move command does not work)
import sys
from PyQt5 import QtCore, QtGui, QtWidgets
class Window(QtWidgets.QMainWindow):
def __init__(self):
super(Window, self).__init__()
V = QtWidgets.QApplication.desktop().screenGeometry()
h, w, x, y = V.height(), V.width(), 1000, 600
self.setGeometry(h/4, w/20, x, y)
self.setFixedSize(x, y)
self.setWindowTitle('Main Window')
OpenFile = QtWidgets.QAction('Open', self)
OpenFile.setShortcut('Ctrl+O')
OpenFile.setStatusTip('Open Restore File...')
self.statusBar()
mainMenu = self.menuBar()
fileMenu = mainMenu.addMenu('File')
fileMenu.addAction(OpenFile)
self.home()
def home(self):
self.tools_in_home()
self.show()
def tools_in_home(self):
self.groupBox = QtWidgets.QGroupBox('Test')
self.groupBox.setFixedSize(800, 400)
self.setContentsMargins(100, 100, 100, 100) # <=== HERE
hBoxLayout = QtWidgets.QHBoxLayout()
self.groupBox.setLayout(hBoxLayout)
self.setCentralWidget(self.groupBox)
def run():
app = QtWidgets.QApplication(sys.argv)
GUI = Window()
sys.exit(app.exec_())
if __name__ == '__main__':
run()

Try it:
import sys
from PyQt5 import QtCore, QtGui, QtWidgets
class Window(QtWidgets.QMainWindow):
def __init__(self):
super(Window, self).__init__()
V = QtWidgets.QApplication.desktop().screenGeometry()
h, w, x, y = V.height(), V.width(), 1000, 600
self.setGeometry(h/4, w/20, x, y)
self.setFixedSize(x, y)
# +++ vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
centralWidget = QtWidgets.QWidget()
self.setCentralWidget(centralWidget)
self.grid = QtWidgets.QGridLayout(centralWidget)
left, top, right, bottom = 100, 100, 100, 100
centralWidget.setContentsMargins(left, top, right, bottom)
# +++ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
OpenFile = QtWidgets.QAction('Open', self)
OpenFile.setShortcut('Ctrl+O')
OpenFile.setStatusTip('Open Restore File...')
self.statusBar()
mainMenu = self.menuBar()
fileMenu = mainMenu.addMenu('File')
fileMenu.addAction(OpenFile)
self.home()
def home(self):
self.tools_in_home()
self.show()
def tools_in_home(self):
self.groupBox = QtWidgets.QGroupBox('Test')
self.groupBox.setFixedSize(800, 400)
self.grid.addWidget(self.groupBox)
def run():
app = QtWidgets.QApplication(sys.argv)
GUI = Window()
GUI.setWindowTitle('Main Window')
sys.exit(app.exec_())
if __name__ == '__main__':
run()
Update
import sys
from PyQt5 import QtCore, QtGui, QtWidgets
class Window(QtWidgets.QMainWindow):
def __init__(self):
super(Window, self).__init__()
V = QtWidgets.QApplication.desktop().screenGeometry()
h, w, x, y = V.height(), V.width(), 1000, 670 # 600
self.setGeometry(h/4, w/20, x, y)
self.setFixedSize(x, y)
# +++ vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
centralWidget = QtWidgets.QWidget()
self.setCentralWidget(centralWidget)
self.grid = QtWidgets.QGridLayout(centralWidget)
left, top, right, bottom = 50, 50, 50, 50
centralWidget.setContentsMargins(left, top, right, bottom)
# +++ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
OpenFile = QtWidgets.QAction('Open', self)
OpenFile.setShortcut('Ctrl+O')
OpenFile.setStatusTip('Open Restore File...')
self.statusBar()
mainMenu = self.menuBar()
fileMenu = mainMenu.addMenu('File')
fileMenu.addAction(OpenFile)
self.home()
def home(self):
self.tools_in_home()
self.show()
def tools_in_home(self):
self.groupBox = QtWidgets.QGroupBox('Test')
self.groupBox.setFixedSize(400, 200) #(800, 400)
self.grid.addWidget(self.groupBox, 0, 0)
# +++ vvvvv
self.groupBox1 = QtWidgets.QGroupBox('Test 1')
self.groupBox1.setFixedSize(400, 100)
self.groupBox2 = QtWidgets.QGroupBox('Test 2')
self.groupBox2.setFixedSize(400, 100)
self.groupBox3 = QtWidgets.QGroupBox('Test 3')
self.groupBox3.setFixedSize(400, 200)
self.grid.addWidget(self.groupBox1, 1, 0)
self.grid.addWidget(self.groupBox2, 1, 1)
self.grid.addWidget(self.groupBox3, 2, 1)
# +++ ^^^^^
def run():
app = QtWidgets.QApplication(sys.argv)
GUI = Window()
GUI.setWindowTitle('Main Window')
sys.exit(app.exec_())
if __name__ == '__main__':
run()

Related

pyqt5 - items in QHBoxLayout overlap?

I've seen several similar questions on items overlapping in (py)Qt, but I cannot for the life of me figure out why I get these overlapping elements (label and slider) inside a QHBoxLayout:
... with this code:
import sys
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *
class Example(QWidget):
def __init__(self):
super(Example, self).__init__()
self.initUI()
#pyqtSlot()
def onclick(self):
print("AAA")
# QApplication.processEvents()
setstr = ""
if self.btn_yrange.isChecked(): setstr = "yrange auto ON"
else: setstr = "yrange auto OFF"
self.btn_yrange.setText(setstr)
#self.btn_yrange.adjustSize()
def initUI(self):
self.col = QColor(0, 0, 0)
self.slider_hbox = QHBoxLayout()
self.btn_yrange = QPushButton('yrange auto OFF', self)
self.btn_yrange.setCheckable(True)
self.btn_yrange.clicked.connect(self.onclick)
self.slider_yrange = QSlider(Qt.Horizontal, self)
self.slider_yrange.setFocusPolicy(Qt.StrongFocus)
self.slider_yrange.setTickPosition(QSlider.TicksBothSides)
self.slider_yrange.setTickInterval(10)
self.slider_yrange.setSingleStep(1)
self.slider_hbox.addStretch(1)
self.slider_hbox.addWidget(self.btn_yrange, Qt.AlignRight)
self.slider_hbox.addStretch(1)
self.slider_hbox.addSpacing(10)
self.slider_hbox.addWidget(self.slider_yrange)
self.slider_hbox.addStretch(1)
self.setGeometry(300, 300, 280, 170)
self.setWindowTitle('Toggle button')
self.show()
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())
How do I force the label and the slider to be side-by-side?
Ok, got it - I saw http://zetcode.com/gui/pyqt5/layout/ - and realized, I had forgotten to add self.setLayout(self.slider_hbox) before self.setGeometry. So, now I get this:
... with this code:
import sys
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *
class Example(QWidget):
def __init__(self):
super(Example, self).__init__()
self.initUI()
#pyqtSlot()
def onclick(self):
print("AAA")
# QApplication.processEvents()
setstr = ""
if self.btn_yrange.isChecked(): setstr = "yrange auto ON"
else: setstr = "yrange auto OFF"
self.btn_yrange.setText(setstr)
#self.btn_yrange.adjustSize()
def initUI(self):
self.col = QColor(0, 0, 0)
self.slider_hbox = QHBoxLayout()
self.btn_yrange = QPushButton('yrange auto OFF', self)
self.btn_yrange.setCheckable(True)
#btn_yrange.move(10, 10)
#self.btn_yrange.clicked.connect(self.onclick)
self.btn_yrange.clicked.connect(self.onclick)
self.slider_yrange = QSlider(Qt.Horizontal, self)
self.slider_yrange.setFocusPolicy(Qt.StrongFocus)
self.slider_yrange.setTickPosition(QSlider.TicksBothSides)
self.slider_yrange.setTickInterval(10)
self.slider_yrange.setSingleStep(1)
#self.slider_hbox.addStretch(1)
self.slider_hbox.addWidget(self.btn_yrange, Qt.AlignRight)
#self.slider_hbox.addStretch(1)
self.slider_hbox.addSpacing(10)
self.slider_hbox.addWidget(self.slider_yrange)
#self.slider_hbox.addStretch(1)
self.setLayout(self.slider_hbox)
self.setGeometry(300, 300, 280, 170)
self.setWindowTitle('Toggle button')
self.show()
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())

Have QScrollArea react on wheelEvent, also in space taken up by children?

Consider this example:
#!/usr/bin/env python
import sys,os
from PyQt5 import QtCore, QtWidgets, QtGui
from PyQt5.QtCore import Qt
class MainWindow(QtWidgets.QMainWindow):
class ScrollAreaWheel(QtWidgets.QScrollArea): # SO:9475772
def __init__(self, parent=None):
super(MainWindow.ScrollAreaWheel, self).__init__(parent)
self.parent = parent
def wheelEvent(self, event):
print("wheelEvent", event.angleDelta().y())
def __init__(self):
#~ self.do_init = QtCore.QEvent.registerEventType()
QtWidgets.QMainWindow.__init__(self)
self.setMinimumWidth(1000)
self.setMinimumHeight(400)
self.frame1 = QtWidgets.QFrame(self)
self.frame1.setFrameShape(QtWidgets.QFrame.StyledPanel)
self.frame1layout = QtWidgets.QGridLayout(self.frame1)
self.frame1layout.setSpacing(0);
self.frame1layout.setContentsMargins(0,0,0,0);
self.frame1widget = QtWidgets.QWidget()
self.frame1widget.setLayout(QtWidgets.QGridLayout())
self.frame1layout.addWidget(self.frame1widget)
self.frame1scroll = MainWindow.ScrollAreaWheel(self) #QtWidgets.QScrollArea()
self.frame1scroll.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOn)
self.frame1scroll.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn)
self.frame1widget.layout().addWidget(self.frame1scroll, 0, 0) #, Qt.AlignCenter)
#self.frame1scrolllayout = QtWidgets.QHBoxLayout(self.frame1scroll)
self.frame1scrolllayout = QtWidgets.QGridLayout(self.frame1scroll)
self.frame1scroll.setWidget(self.frame1scrolllayout.widget())
self.frame1scroll.setWidgetResizable(True)
self.frame1scroll.setAlignment(Qt.AlignCenter)
self.frame1label = QtWidgets.QLabel()
self.frame1scrolllayout.addWidget(self.frame1label, 0, 0, Qt.AlignCenter) ##
pixmap = QtGui.QPixmap(200, 100)
pixmap.fill(Qt.red)
self.frame1label.setPixmap(pixmap)
self.frame2 = QtWidgets.QFrame(self)
self.frame2.setFrameShape(QtWidgets.QFrame.StyledPanel)
self.frame2layout = QtWidgets.QHBoxLayout(self.frame2)
self.frame2layout.setSpacing(0);
self.frame2layout.setContentsMargins(0,0,0,0);
self.frame2scroll = QtWidgets.QScrollArea(self)
self.frame2scroll.setWidgetResizable(True)
self.frame2widget = QtWidgets.QWidget()
self.frame2widget.setLayout(QtWidgets.QGridLayout())
self.frame2scroll.setWidget(self.frame2widget)
self.frame2layout.addWidget(self.frame2scroll)
self.mainwid = QtWidgets.QWidget()
self.mainwid.setLayout(QtWidgets.QGridLayout())
self.setCentralWidget(self.mainwid)
self.splitter1 = QtWidgets.QSplitter(Qt.Horizontal)
self.splitter1.addWidget(self.frame1)
self.splitter1.addWidget(self.frame2)
self.splitter1.setSizes([600, 600]); # equal splitter at start
self.mainwid.layout().addWidget(self.splitter1)
self.mainwid.layout().update()
if __name__ == "__main__":
app = QtWidgets.QApplication([])
main = MainWindow()
main.show()
sys.exit(app.exec_())
It generates this (Ubuntu 18.04):
I want to use mousewheel only on the left QScrollArea, for which I've made a separate class. However, its wheelEvent fires only when I'm outside the red box, not when I hover over it. How can I make ScrollAreaWheel.wheelEvent fire even when mouse is over the child label (the red box)?
You are the QLabel placing on top of the QScrollArea instead of placing it inside, visually it is the same but at the level of events it is not.
from PyQt5 import QtCore, QtGui, QtWidgets
class ScrollAreaWheel(QtWidgets.QScrollArea):
def wheelEvent(self, event):
print("wheelEvent", event.angleDelta().y())
class MainWindow(QtWidgets.QMainWindow):
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent)
self.setMinimumSize(1000, 400)
frame1 = QtWidgets.QFrame(frameShape=QtWidgets.QFrame.StyledPanel)
scrollarea1 = ScrollAreaWheel(widgetResizable=True)
scrollarea1.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn)
scrollarea1.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn)
widget1 = QtWidgets.QWidget()
scrollarea1.setWidget(widget1)
label_lay = QtWidgets.QGridLayout(widget1)
lay1 = QtWidgets.QVBoxLayout(frame1)
lay1.addWidget(scrollarea1)
pixmap = QtGui.QPixmap(200, 100)
pixmap.fill(QtCore.Qt.red)
label = QtWidgets.QLabel(pixmap=pixmap)
label_lay.addWidget(label, 0, 0, QtCore.Qt.AlignCenter)
#==============================
frame2 = QtWidgets.QFrame(frameShape=QtWidgets.QFrame.StyledPanel)
scrollarea2 = QtWidgets.QScrollArea(widgetResizable=True)
scrollarea2.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn)
scrollarea2.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn)
widget2 = QtWidgets.QWidget()
scrollarea2.setWidget(widget2)
splitter = QtWidgets.QSplitter(QtCore.Qt.Horizontal)
splitter.addWidget(frame1)
splitter.addWidget(frame2)
splitter.setSizes([600, 600])
self.setCentralWidget(splitter)
if __name__ == '__main__':
import sys
app = QtWidgets.QApplication(sys.argv)
w = MainWindow()
w.resize(640, 480)
w.show()
sys.exit(app.exec_())

how to display the range values in slider

Here is my code, i want to display the minimum and maximum range values for slider.I tried many ways but i didn't get anything.Can anyone please help me how to display the slider as shown in the bellow image.
Given bellow is my code:
from pyface.qt import QtGui, QtCore
import sys
class Example(QtGui.QWidget):
def __init__(self):
super(Example, self).__init__()
self.initUI()
def initUI(self):
self.vbox = QtGui.QVBoxLayout()
self.label3 = QtGui.QLabel()
self.slider = QtGui.QSlider()
self.slider.setMinimum(0)
self.slider.setMaximum(100)
self.slider.setTickPosition(QtGui.QSlider.TicksLeft)
self.slider.setOrientation(QtCore.Qt.Horizontal)
self.slider.setOrientation(QtCore.Qt.Horizontal)
self.vbox.addWidget(self.slider,QtCore.Qt.AlignBottom)
self.vbox.addWidget(self.label3)
self.setLayout(self.vbox)
self.setGeometry(300, 300, 300, 150)
self.slider.valueChanged.connect(self.valuechange)
self.show()
def valuechange(self):
txt = str(self.slider.value())
self.label3.setText(txt)
def main():
app = QtGui.QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
You can use 2 QLabels with QHBoxLayout and QVBoxLayout:
from pyface.qt import QtGui, QtCore
import sys
class Slider(QtGui.QSlider):
minimumChanged = QtCore.Signal(int)
maximumChanged = QtCore.Signal(int)
def setMinimum(self, minimum):
self.minimumChanged.emit(minimum)
super(Slider, self).setMinimum(minimum)
def setMaximum(self, maximum):
self.maximumChanged.emit(maximum)
super(Slider, self).setMaximum(maximum)
class Example(QtGui.QWidget):
def __init__(self):
super(Example, self).__init__()
self.initUI()
def initUI(self):
self.label = QtGui.QLabel(alignment=QtCore.Qt.AlignCenter)
self.slider = Slider(tickPosition=QtGui.QSlider.TicksLeft,
orientation=QtCore.Qt.Horizontal)
slider_vbox = QtGui.QVBoxLayout()
slider_hbox = QtGui.QHBoxLayout()
slider_hbox.setContentsMargins(0, 0, 0, 0)
slider_vbox.setContentsMargins(0, 0, 0, 0)
slider_vbox.setSpacing(0)
label_minimum = QtGui.QLabel(alignment=QtCore.Qt.AlignLeft)
self.slider.minimumChanged.connect(label_minimum.setNum)
label_maximum = QtGui.QLabel(alignment=QtCore.Qt.AlignRight)
self.slider.maximumChanged.connect(label_maximum.setNum)
slider_vbox.addWidget(self.slider)
slider_vbox.addLayout(slider_hbox)
slider_hbox.addWidget(label_minimum, QtCore.Qt.AlignLeft)
slider_hbox.addWidget(label_maximum, QtCore.Qt.AlignRight)
slider_vbox.addStretch()
self.slider.setMinimum(0)
self.slider.setMaximum(100)
vbox = QtGui.QVBoxLayout(self)
vbox.addLayout(slider_vbox)
vbox.addWidget(self.label)
self.setGeometry(300, 300, 300, 150)
self.slider.valueChanged.connect(self.label.setNum)
self.show()
def main():
app = QtGui.QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())
if __name__ == '__main__':
main()

QtabWidget and QMainWindow in one class

Is there a way to define the menubar in a QtabWidget class ?
I wrote a code for a destopapplication with pyqt5 and python 3.6. I would like to set the manuBar in the same class as the Tabs but my code returns qtabwidget has no attribute QMainWindow.
Here is my code:
import sys
from PyQt5 import QtWidgets, QtCore, QtPrintSupport, QtGui
from PyQt5.QtWidgets import *
class main_window(QTabWidget):
def __init__(self, parent=None):
super(QTabWidget, self).__init__(parent)
self.setGeometry(50, 50, 1100, 750)
self.setWindowTitle("Programm") #
self.centralWidget = QtWidgets.QWidget()
self.tabWidget = QtWidgets.QTabWidget(self.centralWidget)
self.tabWidget.setGeometry(QtCore.QRect(10, 10, 1200, 1000))
open_new_file = QAction('New', self)
mainMenu = self.menuBar()
fileMenu = mainMenu.addMenu('Projekt')
fileMenu.addAction(open_new_file)
self.table_widget = MyTableWidget(self)
self.setCentralWidget(self.table_widget)
self.show()
self.tab_v1 = QtWidgets.QWidget()
self.addTab(self.tab_v1, "Tab 1")
self.tab_v2 = QtWidgets.QWidget()
self.addTab(self.tab_v2, "Tab 2")
self.openFile = QPushButton("Choose Tab ", self.tab_v1)
self.openFile.setGeometry(QtCore.QRect(700, 25, 200, 30))
def main():
app = QApplication(sys.argv)
ex = main_window()
ex.show()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
QTabWidget can not have a QMenuBar, what you have to do is put the centralwidget of a QMainWindow to the QTabWidget.
import sys
from PyQt5 import QtCore, QtWidgets
class Main_window(QtWidgets.QMainWindow):
def __init__(self, parent=None):
super(Main_window, self).__init__(parent)
self.setGeometry(50, 50, 1100, 750)
self.setWindowTitle("Programm")
open_new_file = QtWidgets.QAction('New', self)
mainMenu = self.menuBar()
fileMenu = mainMenu.addMenu('Projekt')
fileMenu.addAction(open_new_file)
self.tabWidget = QtWidgets.QTabWidget()
self.setCentralWidget(self.tabWidget)
self.tab_v1 = QtWidgets.QWidget()
self.tabWidget.addTab(self.tab_v1, "Tab 1")
self.openFile =QtWidgets.QPushButton("Choose Tab ", self.tab_v1)
self.openFile.setGeometry(QtCore.QRect(700, 25, 200, 30))
self.tab_v2 = QtWidgets.QWidget()
self.tabWidget.addTab(self.tab_v2, "Tab 2")
def main():
app = QtWidgets.QApplication(sys.argv)
ex = Main_window()
ex.show()
sys.exit(app.exec_())
if __name__ == '__main__':
main()

force python pyside splitter to start window center

How can I force the splitter to be positioned in the center of the window at the start? As you can see in the code below it favors the right side because of the button being small. however I would like to have the splitter always appear in the middle of the window as shown in image two.
Current
Goal
import sys
from PySide import QtGui, QtCore
class Example(QtGui.QWidget):
def __init__(self):
super(Example, self).__init__()
self.initUI()
def initUI(self):
# formatting
self.resize(550, 400)
self.setWindowTitle("Cameras")
# widgets
self.ListA = QtGui.QTreeWidget()
self.ListB = QtGui.QTreeWidget()
self.Button = QtGui.QPushButton()
# layout Splitter
self.mainLayout = QtGui.QHBoxLayout(self)
self.mainLayout.setContentsMargins(5,5,5,5)
self.leftPanel = QtGui.QFrame(self)
# self.leftPanel.setFrameShape(QtGui.QFrame.StyledPanel)
self.leftPanelLayout = QtGui.QHBoxLayout(self.leftPanel)
self.leftPanelLayout.setContentsMargins(0,0,0,0)
self.leftPanelLayout.addWidget(self.ListA)
self.rightPanel = QtGui.QFrame(self)
# self.rightPanel.setFrameShape(QtGui.QFrame.StyledPanel)
self.rightPanelLayout = QtGui.QHBoxLayout(self.rightPanel)
self.rightPanelLayout.setContentsMargins(0,0,0,0)
self.rightPanelLayout.addWidget(self.Button)
self.splitter = QtGui.QSplitter(QtCore.Qt.Horizontal)
self.splitter.addWidget(self.leftPanel)
self.splitter.addWidget(self.rightPanel)
self.mainLayout.addWidget(self.splitter)
self.setGeometry(300, 300, 300, 200)
self.setWindowTitle('QtGui.QSplitter')
self.show()
def onChanged(self, text):
self.lbl.setText(text)
self.lbl.adjustSize()
def main():
app = QtGui.QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
Bam! got it.
import sys
from PySide import QtGui, QtCore
class Example(QtGui.QWidget):
def __init__(self):
super(Example, self).__init__()
self.initUI()
def initUI(self):
# formatting
self.resize(1000, 1000)
self.setWindowTitle("Cameras")
# widgets
self.ListA = QtGui.QTreeWidget()
self.ListB = QtGui.QTreeWidget()
self.Button = QtGui.QPushButton()
# layout Splitter
# QHBoxLayout
self.mainLayout = QtGui.QGridLayout(self)
self.mainLayout.setContentsMargins(5,5,5,5)
self.leftPanel = QtGui.QFrame(self)
# self.leftPanel.setFrameShape(QtGui.QFrame.StyledPanel)
self.leftPanelLayout = QtGui.QHBoxLayout(self.leftPanel)
self.leftPanelLayout.setContentsMargins(0,0,0,0)
self.leftPanelLayout.addWidget(self.ListA)
self.rightPanel = QtGui.QFrame(self)
# self.rightPanel.setFrameShape(QtGui.QFrame.StyledPanel)
self.rightPanelLayout = QtGui.QHBoxLayout(self.rightPanel)
self.rightPanelLayout.setContentsMargins(0,0,0,0)
self.rightPanelLayout.addWidget(self.Button)
self.splitter = QtGui.QSplitter(QtCore.Qt.Horizontal)
self.splitter.addWidget(self.leftPanel)
self.splitter.addWidget(self.rightPanel)
self.splitter.setCollapsible(0,False)
self.splitter.setCollapsible(1,False)
self.mainLayout.addWidget(self.splitter,0,0)
self.setWindowTitle('QtGui.QSplitter')
self.show()
self.set_panel_sizes(self.splitter)
def onChanged(self, text):
self.lbl.setText(text)
self.lbl.adjustSize()
def set_panel_sizes(self, ctrl):
width = ctrl.frameSize().width() / 2.0
ctrl.setSizes( [width,width] )
def main():
app = QtGui.QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())
if __name__ == '__main__':
main()

Categories

Resources