I don't think there's a built-in method, however you can remove horizontal gridlines via stylesheets by disabling gridlines using setShowGrid(False)
and then drawing the vertical line borders with the QTableView::item
selector and the border-right
style like this:
tableWidget.setShowGrid(False)
tableWidget.setStyleSheet('QTableView::item {border-right: 1px solid #d6d9dc;}')
Here's a quick example
from PyQt5.QtWidgets import QApplication, QWidget, QTableWidget, QTableWidgetItem, QVBoxLayout
import sys
class Table(QWidget):
def __init__(self):
super().__init__()
self.setGeometry(0, 0, 300, 200)
self.create_table()
self.layout = QVBoxLayout()
self.layout.addWidget(self.tableWidget)
self.setLayout(self.layout)
self.show()
def create_table(self):
self.tableWidget = QTableWidget()
self.tableWidget.setRowCount(4)
self.tableWidget.setColumnCount(2)
self.tableWidget.setItem(0,0, QTableWidgetItem("Cell (1,1)"))
self.tableWidget.setItem(0,1, QTableWidgetItem("Cell (1,2)"))
self.tableWidget.setItem(1,0, QTableWidgetItem("Cell (2,1)"))
self.tableWidget.setItem(1,1, QTableWidgetItem("Cell (2,2)"))
self.tableWidget.setItem(2,0, QTableWidgetItem("Cell (3,1)"))
self.tableWidget.setItem(2,1, QTableWidgetItem("Cell (3,2)"))
self.tableWidget.setItem(3,0, QTableWidgetItem("Cell (4,1)"))
self.tableWidget.setItem(3,1, QTableWidgetItem("Cell (4,2)"))
self.tableWidget.move(0,0)
# Remove horizontal gridlines
self.tableWidget.setShowGrid(False)
self.tableWidget.setStyleSheet('QTableView::item {border-right: 1px solid #d6d9dc;}')
if __name__ == '__main__':
app = QApplication(sys.argv)
table = Table()
sys.exit(app.exec_())
Note: If you wanted to remove vertical gridlines, change the style from border-right
to border-bottom