0

I have a program with a few different widgets, one of which is a table. I wish to obtain the width of the headers of my table, to use for making more widgets to ensure that they are the same Width. (Width of the headers (QTableWidgetItem) varies depending on my program input, so I wish to be able to set the width of other widgets based on whatever the width is of the QTableWidgetItems for each execution)

I have looked a fair bit of documentation myself, but It seems as though there is no easy/obvious method such as .width() to obtain it?

I have tried using the methods from a similar question, such as:

width = mainWindow.frameGeometry().width()
height = mainWindow.frameGeometry().height()

but unfortunately I just get the error that the method isn't available for the QTableWidgetItem object

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
  • 1
    Possible duplicate of [Pyqt how to get a widget's dimensions](https://stackoverflow.com/questions/15204470/pyqt-how-to-get-a-widgets-dimensions) – Heini Oct 04 '19 at 13:08
  • Those solutions aren't working for me unfortunately, I already tried what was suggested in the other question – Jesse Hare Oct 04 '19 at 13:39
  • Try `my_table.horizontalHeaderItem(0).geometry().width()`. – Guimoute Oct 04 '19 at 14:10
  • [`table.horizontalHeader().sectionSize()`](https://doc.qt.io/qt-5/qheaderview.html#sectionSize). – ekhumoro Oct 04 '19 at 15:15
  • If my answer doesn't work for you please edit and update your code. Else mark it as answered please. – Heini Oct 06 '19 at 10:12

1 Answers1

0

The solution is width() or height() in self.YourTableNameHere.horizontalHeader().geometry().height()

Heini
  • 295
  • 2
  • 10