I would like to remove the blank space that there is in the table I put in my layout:
I would like to have something like this:
This is my code:
import sys
from PyQt4 import QtGui
from PyQt4.QtGui import *
from PyQt4.QtSql import *
from PyQt4.QtCore import *
import sys
class Example(QMainWindow):
def __init__(self):
super(Example, self).__init__()
self.initUI()
def initUI(self):
self.resize(640, 480)
self.center()
self.setWindowTitle('')
self.setWindowIcon(QtGui.QIcon('icon.ico'))
exitAction = QtGui.QAction(QtGui.QIcon('exit.png'), '&Exit', self)
exitAction.setShortcut('Ctrl+Q')
exitAction.setStatusTip('Exit application')
exitAction.triggered.connect(QtGui.qApp.quit)
self.toolbar = self.addToolBar('Exit')
self.toolbar.addAction(exitAction)
menubar = self.menuBar()
fileMenu = menubar.addMenu('&File')
fileMenu.addAction(exitAction)
table = QTableWidget()
db = QSqlDatabase.addDatabase("")
db.setDatabaseName('xxx.db')
db.open()
query = QSqlQuery ("xxxx")
queryCount = QSqlQuery ("xxxx")
queryCount.next()
numberUserRow = queryCount.value(0).toInt()
table.setColumnCount(2)
table.setRowCount(numberUserRow[0])
table.setHorizontalHeaderItem(0, QTableWidgetItem("Post"));
table.setHorizontalHeaderItem(1, QTableWidgetItem("Data"));
MSG_POST = 3
DATA_SALVATAGGIO_POST = 4
index=0
while (query.next()):
table.setItem(index,0,QTableWidgetItem(query.value(MSG_POST).toString()))
table.setItem(index,1,QTableWidgetItem(query.value(DATA_SALVATAGGIO_POST).toString()))
index = index+1
self.statusBar().showMessage('Ready')
window = QWidget()
mainLayout = QGridLayout()
verticalLayout = QVBoxLayout()
horizontalLayout = QHBoxLayout()
horizontalLayout.addWidget(table)
verticalLayout.addLayout(horizontalLayout)
mainLayout.addLayout(verticalLayout,0,0)
window.setLayout(mainLayout)
self.setCentralWidget(window);
self.show()
def center(self):
qr = self.frameGeometry()
cp = QtGui.QDesktopWidget().availableGeometry().center()
qr.moveCenter(cp)
self.move(qr.topLeft())
def main():
app = QtGui.QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
I tried to put a button on the right of my table, and this helps me to resize the table itself. But I don't need to use a button, so how can I fix the width of my table?