Best approach to extending QTableWidget
-
I want to create a widget that is a QTableWidget that has a button on top that hides or shows the table (think expand/collapse). What is my best approach to achieving this given I'd like to have the new object expose the QTableWidget attributes/methods but automatically have the button immediately above the horizontal header?
For instance if I simple subclass QTableWidget, how do I tie in to the underlying QTableWidgets rendering code to add the additional button?
-
@SGaist sure I could do it that way, but since there will be many tables each requiring the button I thought it would be more OO to have an extended QTableWidget that I still have access to all the underlying attributes and methods rather than having to add them all to a composed class and pass them through to the has-a QTableWidget.
@Captain-Haddock said in Best approach to extending QTableWidget:
rather than having to add them all to a composed class and pass them through to the has-a QTableWidget
You don't do it that way. Just expose the
QTableWidgetthrough atableWidget()method.It really is best here to make a composite widget IMO. A
QTableWidgetwidget should be that, not have an extra button widget added to it. -
I want to create a widget that is a QTableWidget that has a button on top that hides or shows the table (think expand/collapse). What is my best approach to achieving this given I'd like to have the new object expose the QTableWidget attributes/methods but automatically have the button immediately above the horizontal header?
For instance if I simple subclass QTableWidget, how do I tie in to the underlying QTableWidgets rendering code to add the additional button?
Hi,
Why do you need that button as part of the table widget rather than compose that with a QWidget, QVBoxLayout and QTableWidget ?
-
Hi,
Why do you need that button as part of the table widget rather than compose that with a QWidget, QVBoxLayout and QTableWidget ?
@SGaist sure I could do it that way, but since there will be many tables each requiring the button I thought it would be more OO to have an extended QTableWidget that I still have access to all the underlying attributes and methods rather than having to add them all to a composed class and pass them through to the has-a QTableWidget.
-
@SGaist sure I could do it that way, but since there will be many tables each requiring the button I thought it would be more OO to have an extended QTableWidget that I still have access to all the underlying attributes and methods rather than having to add them all to a composed class and pass them through to the has-a QTableWidget.
@Captain-Haddock said in Best approach to extending QTableWidget:
rather than having to add them all to a composed class and pass them through to the has-a QTableWidget
You don't do it that way. Just expose the
QTableWidgetthrough atableWidget()method.It really is best here to make a composite widget IMO. A
QTableWidgetwidget should be that, not have an extra button widget added to it. -
C Captain Haddock has marked this topic as solved on