Blank PyQt5 Program - python

I'm trying to create a simple GUI using PyQt5, but whenever I run the program. all it displays is a blank window. How can get elements such as a pushbutton or the QLineEdit to actually appear in the window?
Any pointers would be appreciated as I am trying to create an application that can take a user input (a badge and ticket number in this case) then query a database for the tube properties and quantities before displaying the information as an output.
from PyQt5 import QtCore, QtWidgets
class Ui_MainWindow(object):
def __init__(self):
self.title = 'Tube Bender UI'
self.description = QtWidgets.QLabel('New Order Available')
self.badge = QtWidgets.QLineEdit()
self.ticket = QtWidgets.QLineEdit()
self.tubes = 0
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(800, 641)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(MainWindow.sizePolicy().hasHeightForWidth())
MainWindow.setSizePolicy(sizePolicy)
MainWindow.setMaximumSize(QtCore.QSize(800, 641))
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setMinimumSize(QtCore.QSize(800, 641))
self.centralwidget.setMaximumSize(QtCore.QSize(800, 641))
self.centralwidget.setObjectName("centralwidget")
self.horizontalLayoutWidget = QtWidgets.QWidget(self.centralwidget)
self.horizontalLayoutWidget.setGeometry(QtCore.QRect(0, 320, 801, 641))
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.horizontalLayoutWidget.sizePolicy().hasHeightForWidth())
#tubes = 0
def coil_id(self):
QtWidgets.QLineEdit(self)
return self.ticket
def page_description(self):
QtWidgets.QLineEdit(self)
return self.description
def page_title(self):
QtWidgets.QLineEdit(self)
return self.title
def badge_id(self):
QtWidgets.QLineEdit(self)
return self.badge
def tube_count(self):
QtWidgets.QLineEdit(self)
print(self.tubes)
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
MainPage = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show())
sys.exit(app.exec_()

Just have this small look on this tiny example, tried to be the simplest I could. There are much more to learn and some much more good practices not just through everything like that, but anyways, here it is:
import sys
from PyQt5.QtWidgets import QApplication
from PyQt5.QtWidgets import QHBoxLayout
from PyQt5.QtWidgets import QLabel
from PyQt5.QtWidgets import QLineEdit
from PyQt5.QtWidgets import QMainWindow
from PyQt5.QtWidgets import QVBoxLayout
from PyQt5.QtWidgets import QWidget
class MainWindow(QMainWindow):
layout_main = None
central_widget = None
lbl_name = None
lbl_value = None
input_name = None
input_value = None
def __init__(self):
super(MainWindow, self).__init__()
self.init_ui()
def init_ui(self):
#variables
self.layout_main = QVBoxLayout()
self.layout_labels = QHBoxLayout()
self.layout_inputs = QHBoxLayout()
self.central_widget = QWidget()
self.lbl_name = QLabel("name")
self.lbl_name.setFixedSize(100,50)
self.lbl_value = QLabel("Value")
self.lbl_value.setFixedSize(100, 50)
self.input_name = QLineEdit()
self.input_name.setFixedSize(100, 50)
self.input_value = QLineEdit()
self.input_value.setFixedSize(100, 50)
#style
self.layout_main.setContentsMargins(10, 10, 10, 10)
self.setMinimumSize(250,100)
#adding objects
self.layout_labels.addWidget(self.lbl_name)
self.layout_labels.addWidget(self.lbl_value)
self.layout_main.addLayout(self.layout_labels)
self.layout_inputs.addWidget(self.input_name)
self.layout_inputs.addWidget(self.input_value)
self.layout_main.addLayout(self.layout_inputs)
self.central_widget.setLayout(self.layout_main)
self.setCentralWidget(self.central_widget)
if __name__ == '__main__':
app = QApplication(sys.argv)
mw = MainWindow()
mw.show()
sys.exit(app.exec_())
You will see that later you will have to override many classes inheriting from qt classes and personalize one by one according to your need. just a tip ")

Related

When two widget animation commands run at start only one gets animated

I am trying hide two list widgets upon start by animating the maximum width to zero, then two buttons to toggle each widget to appear and disappear, this works fine, but not at start, only one of the two widget gets animated, the other just stays on, but the same command works fine when signaled by the push buttons.
Please suggest if there is any better approach to achieve the same effect or the reason behind it.
from PyQt6 import QtCore, QtGui, QtWidgets
from PyQt6.QtCore import QPropertyAnimation
class Ui_Form(object):
def setupUi(self, Form):
Form.setObjectName("Form")
Form.resize(640, 480)
self.horizontalLayout = QtWidgets.QHBoxLayout(Form)
self.horizontalLayout.setObjectName("horizontalLayout")
self.frame = QtWidgets.QFrame(Form)
self.frame.setFrameShape(QtWidgets.QFrame.Shape.StyledPanel)
self.frame.setFrameShadow(QtWidgets.QFrame.Shadow.Raised)
self.frame.setObjectName("frame")
self.verticalLayout = QtWidgets.QVBoxLayout(self.frame)
self.verticalLayout.setObjectName("verticalLayout")
self.pushButton = QtWidgets.QPushButton(self.frame)
self.pushButton.setObjectName("pushButton")
self.verticalLayout.addWidget(self.pushButton)
self.pushButton_2 = QtWidgets.QPushButton(self.frame)
self.pushButton_2.setObjectName("pushButton_2")
self.verticalLayout.addWidget(self.pushButton_2)
self.pushButton_3 = QtWidgets.QPushButton(self.frame)
self.pushButton_3.setObjectName("pushButton_3")
self.verticalLayout.addWidget(self.pushButton_3)
spacerItem = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Policy.Minimum, QtWidgets.QSizePolicy.Policy.Expanding)
self.verticalLayout.addItem(spacerItem)
self.horizontalLayout.addWidget(self.frame)
self.listWidget = QtWidgets.QListWidget(Form)
self.listWidget.setObjectName("listWidget")
self.horizontalLayout.addWidget(self.listWidget)
self.listWidget_2 = QtWidgets.QListWidget(Form)
self.listWidget_2.setObjectName("listWidget_2")
self.horizontalLayout.addWidget(self.listWidget_2)
self.listWidget_3 = QtWidgets.QListWidget(Form)
self.listWidget_3.setObjectName("listWidget_3")
self.horizontalLayout.addWidget(self.listWidget_3)
self.retranslateUi(Form)
QtCore.QMetaObject.connectSlotsByName(Form)
# Trying to Hide both widgets upon start, but one gets hidden
self.animate_listwidget2()
self.animate_listwidget3()
self.pushButton_2.clicked.connect(self.animate_listwidget2)
self.pushButton_3.clicked.connect(self.animate_listwidget3)
def retranslateUi(self, Form):
_translate = QtCore.QCoreApplication.translate
Form.setWindowTitle(_translate("Form", "Form"))
self.pushButton.setText(_translate("Form", "PushButton"))
self.pushButton_2.setText(_translate("Form", "toggle lw2"))
self.pushButton_3.setText(_translate("Form", "toggle lw3"))
def animate_listwidget2(self):
width = self.listWidget_2.width()
if width != 0:
width1 = 0
else:
width1 = 350
self.animation = QPropertyAnimation(self.listWidget_2, b'maximumWidth')
self.animation.setDuration(800)
self.animation.setStartValue(width)
self.animation.setEndValue(width1)
self.animation.setEasingCurve(QtCore.QEasingCurve.Type.Linear)
self.animation.start()
def animate_listwidget3(self):
width = self.listWidget_3.width()
if width != 0:
width1 = 0
else:
width1 = 350
self.animation = QPropertyAnimation(self.listWidget_3, b'maximumWidth')
self.animation.setDuration(800)
self.animation.setStartValue(width)
self.animation.setEndValue(width1)
self.animation.setEasingCurve(QtCore.QEasingCurve.Type.Linear)
self.animation.start()
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
Form = QtWidgets.QWidget()
ui = Ui_Form()
ui.setupUi(Form)
Form.show()
sys.exit(app.exec())
First of all you should not modify the code generated by QtDesigner since that could cause other bugs so to apply my solutions you have to restore the file and call it gui.py
The problem is that using the same attribute is destroying the previous animation.
There are several solutions such as changing the name of the attribute assigned to one of them (for example, changing the name of the second to self.animation2) but the implementation can still be improved since with the current one, animations are always being created unnecessarily since one is enough single for each QListWidget.
from PyQt6.QtCore import QEasingCurve, QPropertyAnimation
from PyQt6.QtWidgets import QApplication, QWidget
from gui import Ui_Form
class Form(QWidget):
def __init__(self, parent=None):
super().__init__(parent)
self.ui = Ui_Form()
self.ui.setupUi(self)
self.ui.pushButton_2.clicked.connect(self.animate_listwidget2)
self.ui.pushButton_3.clicked.connect(self.animate_listwidget3)
self.animation1 = self.build_animation(self.ui.listWidget_2)
self.animation2 = self.build_animation(self.ui.listWidget_3)
self.animate_listwidget2()
self.animate_listwidget3()
def build_animation(self, listwidget):
animation = QPropertyAnimation(listwidget, b"maximumWidth")
animation.setDuration(800)
animation.setEasingCurve(QEasingCurve.Type.Linear)
return animation
def start_animation(self, animation):
width = animation.targetObject().width()
animation.stop()
animation.setStartValue(width)
animation.setEndValue(0 if width != 0 else 350)
animation.start()
def animate_listwidget2(self):
self.start_animation(self.animation1)
def animate_listwidget3(self):
self.start_animation(self.animation2)
if __name__ == "__main__":
import sys
app = QApplication(sys.argv)
w = Form()
w.show()
sys.exit(app.exec())

Pushbutton is not being responsive

i'm pretty new to python and PyQt5.
My goal is to use a "Push Button" to move to the next widget in the "Stacked Layout". However, it's not being responsive, and it appears that it won't enter the function in order to move on to the next widget.
I have no idea wether its the inheritance i've messed up on, or something else. Any guidance is really appreciated. Thank you!
from PyQt5 import QtCore, QtGui, QtWidgets
class Menu(QtWidgets.QWidget):
def setupUI(self, Main):
Main.setObjectName("Main")
Main.setFixedSize(900, 500)
self.width = 900
self.height = 500
self.setFixedSize(self.width, self.height)
self.menu = QtWidgets.QStackedLayout()
self.welcomeMenu = QtWidgets.QWidget()
self.mainMenu = QtWidgets.QWidget()
self.welcomeUi()
self.menuUi()
self.menu.addWidget(self.welcomeMenu)
self.menu.addWidget(self.mainMenu)
def welcomeUi(self):
#Button for entering portal
self.entrBtn = QtWidgets.QPushButton(self.welcomeMenu)
self.entrBtn.setGeometry(QtCore.QRect(25,150,200,50))
self.entrBtn.setText("To the menu screen!")
#Having welcome text
self.welcomeText = QtWidgets.QLabel(self.welcomeMenu)
self.welcomeText.setGeometry(QtCore.QRect(30, 120, 480, 200))
self.welcomeText.setAlignment(QtCore.Qt.AlignLeading|QtCore.Qt.AlignLeft|QtCore.Qt.AlignTop)
self.welcomeText.setText("Welcome!")
def menuUi(self):
self.text = QtWidgets.QLabel(self.mainMenu)
self.text.setGeometry(QtCore.QRect(30, 120, 480, 200))
self.text.setText("test")
class Main(QtWidgets.QMainWindow, Menu):
def __init__(self):
super(Main, self).__init__()
self.setupUI(self)
self.entrBtn.clicked.connect(self.menuWindow)
def menuWindow(self):
self.menu.setCurrentWidget(self.mainMenu)
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
m = Main()
sys.exit(app.exec_())
The problem is simple: QLabel is on top of the button so it will block all mouse events. The simple solution is to put QPushButton on QLabel using raise_():
# ...
self.welcomeText.setText("Welcome!")
self.entrBtn.raise_()
But that solves the superficial problem, you have other bigger problem: You should not inherit from 2 QWidget, also the Main is not shown. It is better to rewrite the code as follows:
from PyQt5 import QtCore, QtGui, QtWidgets
class MainWindow(QtWidgets.QMainWindow):
def __init__(self, parent=None):
super().__init__(parent)
self.welcomeMenu = QtWidgets.QWidget()
self.mainMenu = QtWidgets.QWidget()
self.fill_welcomeUi()
self.fill_menuUi()
self.stacked_lay = QtWidgets.QStackedLayout()
self.stacked_lay.addWidget(self.welcomeMenu)
self.stacked_lay.addWidget(self.mainMenu)
central_widget = QtWidgets.QWidget()
self.setCentralWidget(central_widget)
central_widget.setLayout(self.stacked_lay)
self.entrBtn.clicked.connect(self.menuWindow)
self.resize(640, 480)
def menuWindow(self):
self.stacked_lay.setCurrentWidget(self.mainMenu)
def fill_welcomeUi(self):
#Button for entering portal
self.entrBtn = QtWidgets.QPushButton(self.welcomeMenu)
self.entrBtn.setGeometry(QtCore.QRect(25,150,200,50))
self.entrBtn.setText("To the menu screen!")
#Having welcome text
self.welcomeText = QtWidgets.QLabel(self.welcomeMenu)
self.welcomeText.setGeometry(QtCore.QRect(30, 120, 480, 200))
self.welcomeText.setAlignment(QtCore.Qt.AlignLeading|QtCore.Qt.AlignLeft|QtCore.Qt.AlignTop)
self.welcomeText.setText("Welcome!")
self.entrBtn.raise_()
def fill_menuUi(self):
self.text = QtWidgets.QLabel(self.mainMenu)
self.text.setGeometry(QtCore.QRect(30, 120, 480, 200))
self.text.setText("test")
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
m = MainWindow()
m.show()
sys.exit(app.exec_())

pyqt5 sizing correctly a tableview element in a tabbed widget

I'm not able to size correctly a table view element (self.table_View_1) inside a tab,
I tried different approaches like containers, layout and so on without reaching the objective.
The code refer to a model class that allows to show pandas data frame inside the table view.
here's the code:
import sys
import Mod_PX
from PandasModel import PandasModel
from PyQt5 import QtWidgets, QtCore, QtGui
from PyQt5.QtWidgets import QApplication, QPushButton, QHBoxLayout, QTabWidget, QVBoxLayout, QWidget, QMainWindow, QGroupBox
from PyQt5.QtCore import pyqtSlot
class ProgramWindow(QMainWindow):
def __init__(self):
QMainWindow.__init__(self)
self.setup_main_window()
self.set_window_layout()
def setup_main_window(self):
self.centralwidget = QWidget()
self.setCentralWidget(self.centralwidget)
self.resize( 800, 350 )
self.setWindowTitle( "ProjectX" )
def set_window_layout(self):
self.vbox_1 = QVBoxLayout(self.centralwidget)
self.hgroup_2 = QGroupBox()
self.hlayout_2 = QHBoxLayout()
self.hgroup_2.setLayout(self.hlayout_2)
self.btn_Analisi = QPushButton('Analisi', self)
self.btn_Help = QPushButton('Help')
self.btn_Wiz = QPushButton('Wizard')
self.btn_Analisi.clicked.connect(self.loadFile)
self.hlayout_2.addWidget(self.btn_Analisi)
self.hlayout_2.addWidget(self.btn_Help)
self.hlayout_2.addWidget(self.btn_Wiz)
self.vbox_1.addWidget(self.hgroup_2)
# Initialize tabs_1 screen
self.tabs_1 = QTabWidget()
self.tab1_1 = QWidget()
self.tab2_1 = QWidget()
self.tab3_1 = QWidget()
# Add tabs
self.tabs_1.addTab(self.tab1_1, "WWA")
self.tabs_1.addTab(self.tab2_1, "WTP")
self.tabs_1.addTab(self.tab3_1, "WTW")
# Add tabs to widget
self.vbox_1.addWidget(self.tabs_1)
# Initialize tabs_2 screen
self.tabs_2 = QTabWidget(self.tab1_1)
self.tab1_2 = QWidget()
self.tab2_2 = QWidget()
self.tabs_2.setTabPosition(QtWidgets.QTabWidget.West)
self.vbox_2 = QVBoxLayout(self.tab1_1)
# Add tabs
self.tabs_2.addTab(self.tab1_2, "Foglio 1")
self.tabs_2.addTab(self.tab2_2, "Foglio 2")
#Add tabs to widget
self.table_View_1 = QtWidgets.QTableView(self.tab1_2)
self.table_View_1.setObjectName("table_View_1")
font = QtGui.QFont()
font.setPointSize(10)
self.table_View_1.setFont(font)
self.table_View_1.setGeometry(0,0,self.tab1_2.width(),self.tab1_2.height())
self.vbox_2.addWidget(self.tabs_2)
self.show()
#pyqtSlot()
def loadFile(self):
df = Mod_PX.sheet_b()
model = PandasModel(df)
self.table_View_1.setModel(model)
def main():
app = QApplication(sys.argv)
programWindow = ProgramWindow()
programWindow.show()
sys.exit(app.exec_())
if __name__ == "__main__":
main()
Here the GUI with the table not correctly sized:
Thank you in advance for your support!
First you must correctly state the layouts and you should not use setGeometry since that is the task of the layouts. I have modified the structure of your code to have an order so at the end I point out the relationship between the layouts.
def set_window_layout(self):
#buttons
self.btn_Analisi = QtWidgets.QPushButton('Analisi')
self.btn_Help = QtWidgets.QPushButton('Help')
self.btn_Wiz = QtWidgets.QPushButton('Wizard')
# Initialize tabs_1 screen
self.tabs_1 = QtWidgets.QTabWidget()
self.tab1_1 = QtWidgets.QWidget()
self.tab2_1 = QtWidgets.QWidget()
self.tab3_1 = QtWidgets.QWidget()
# Add tabs
self.tabs_1.addTab(self.tab1_1, "WWA")
self.tabs_1.addTab(self.tab2_1, "WTP")
self.tabs_1.addTab(self.tab3_1, "WTW")
# Initialize tabs_2 screen
self.tabs_2 = QtWidgets.QTabWidget()
self.tab1_2 = QtWidgets.QWidget()
self.tab2_2 = QtWidgets.QWidget()
self.tabs_2.setTabPosition(QtWidgets.QTabWidget.West)
# Add tabs
self.tabs_2.addTab(self.tab1_2, "Foglio 1")
self.tabs_2.addTab(self.tab2_2, "Foglio 2")
self.table_View_1 = QtWidgets.QTableView()
font = QtGui.QFont()
font.setPointSize(10)
self.table_View_1.setFont(font)
# connections
self.btn_Analisi.clicked.connect(self.loadFile)
# layouts
vbox = QtWidgets.QVBoxLayout(self.centralwidget)
hgroup = QtWidgets.QGroupBox()
vbox.addWidget(hgroup)
hlay_group = QtWidgets.QHBoxLayout(hgroup)
hlay_group.addWidget(self.btn_Analisi)
hlay_group.addWidget(self.btn_Help)
hlay_group.addWidget(self.btn_Wiz)
vbox.addWidget(self.tabs_1)
lay = QtWidgets.QVBoxLayout(self.tab1_1)
lay.addWidget(self.tabs_2)
lay_tableview = QtWidgets.QVBoxLayout(self.tab1_2)
lay_tableview.addWidget(self.table_View_1)

How to add a tab to QTabWidget using the button on the form?

I decided to write a visual form for my script.
The idea is to have a button that will add new tabs to QTabWidget. It does not work and I can not find a good example. I use PyQt5. Here's a piece of what I've tried:
import sys
from PyQt5.QtGui import QIcon
from PyQt5 import QtCore, QtWidgets
class mainForm(QtWidgets.QWidget):
def __init__(self):
super().__init__()
self.runUi()
def runUi(self):
self.resize(250, 150)
self.move(300, 300)
self.setWindowTitle('Let\'s Rock!')
self.setWindowIcon(QIcon('icon.png'))
self.setMaximumSize(QtCore.QSize(560, 522))
self.setMinimumSize(QtCore.QSize(560, 522))
groupBoxGD = QtWidgets.QGroupBox('Соединение с ГД', self)
groupBoxGD.setGeometry(QtCore.QRect(10, 10, 541, 151))
hrLWGDLink = QtWidgets.QWidget(groupBoxGD)
hrLWGDLink.setGeometry(QtCore.QRect(10, 10, 521, 31))
hrLGD = QtWidgets.QHBoxLayout(hrLWGDLink)
hrLGD.setContentsMargins(0, 0, 0, 0)
btnAddTab = QtWidgets.QPushButton(hrLWGDLink)
btnAddTab.setText('Add tab')
hrLGD.addWidget(btnAddTab)
tabWidget = QtWidgets.QTabWidget(groupBoxGD)
tabWidget.setGeometry(QtCore.QRect(10, 170, 541, 351))
btnAddTab.clicked.connect(self.addProjectTab)
self.show()
def addProjectTab(self):
tab = QtWidgets.QWidget()
#how add tab at this line?
if __name__ == '__main__':
app = QtWidgets.QApplication(sys.argv)
ui = mainForm()
sys.exit(app.exec_())
You have to use the addTab() function, but to do so from another class the QTabWidget object must be a member of the class. Also I made some changes in the design because the button was on the QTabWidget, covering the tabs.
from PyQt5 import QtCore, QtGui, QtWidgets
import sys
class mainForm(QtWidgets.QWidget):
def __init__(self):
super().__init__()
self.runUi()
def runUi(self):
self.resize(250, 150)
self.move(300, 300)
self.setWindowTitle('Let\'s Rock!')
self.setWindowIcon(QtGui.QIcon('icon.png'))
self.setMaximumSize(QtCore.QSize(560, 522))
self.setMinimumSize(QtCore.QSize(560, 522))
layout = QtWidgets.QVBoxLayout(self)
groupBoxGD = QtWidgets.QGroupBox('Соединение с ГД', self)
layout2 = QtWidgets.QVBoxLayout(groupBoxGD)
hrLWGDLink = QtWidgets.QWidget(groupBoxGD)
hrLGD = QtWidgets.QVBoxLayout(hrLWGDLink)
hrLGD.setContentsMargins(0, 0, 0, 0)
btnAddTab = QtWidgets.QPushButton(hrLWGDLink)
btnAddTab.setText('Add tab')
hrLGD.addWidget(btnAddTab)
self.tabWidget = QtWidgets.QTabWidget(hrLWGDLink)
hrLGD.addWidget(self.tabWidget)
layout2.addWidget(hrLWGDLink)
layout.addWidget(groupBoxGD)
btnAddTab.clicked.connect(self.addProjectTab)
def addProjectTab(self):
tab = QtWidgets.QWidget()
self.tabWidget.addTab(tab, "tab")
app = QtWidgets.QApplication(sys.argv)
w = mainForm()
w.show()
sys.exit(app.exec_())
Screenshot:

What's the proper way to add a layout to a qtablewidget in pyqt?

I've already asked a similar question here but I'd like to know the proper way to add a layout to qtablewigets and also how could I put 2 table widgets in the same window, side by side if they both only had 3 columns.
Place the tables them within a QHBoxLayout.
Code:
import sys
from PyQt4 import QtGui
from PyQt4 import QtCore
class Window(QtGui.QWidget):
def __init__(self, parent=None):
super(Window, self).__init__(parent=parent)
QtGui.QTableWidget.setMinimumSize(self, 500, 500)
QtGui.QTableWidget.setWindowTitle(self, "Custom table widget")
self.table1 = QtGui.QTableWidget()
self.configureTable(self.table1)
self.table2 = QtGui.QTableWidget()
self.configureTable(self.table2)
self.buttonBox = QtGui.QDialogButtonBox(self)
self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
self.buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Cancel | QtGui.QDialogButtonBox.Ok)
self.verticalLayout = QtGui.QVBoxLayout(self)
self.horizontalLayout = QtGui.QHBoxLayout()
self.horizontalLayout.addWidget(self.table1)
self.horizontalLayout.addWidget(self.table2)
self.verticalLayout.addLayout(self.horizontalLayout)
self.verticalLayout.addWidget(self.buttonBox)
self.buttonBox.accepted.connect(self.close)
self.buttonBox.rejected.connect(self.close)
def configureTable(self, table):
rowf = 3
table.setColumnCount(3)
table.setRowCount(rowf)
table.setHorizontalHeaderItem(0, QtGui.QTableWidgetItem("col1"))
table.setHorizontalHeaderItem(1, QtGui.QTableWidgetItem("col2"))
table.setHorizontalHeaderItem(2, QtGui.QTableWidgetItem("col3"))
table.horizontalHeader().setStretchLastSection(True)
# table.verticalHeader().setStretchLastSection(True)
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
w = Window()
w.show()
sys.exit(app.exec_())
Images:

Categories

Resources