Qt Designer design a QTableWidget and make it a sub-class
-
I just don't get what Designer (in Creator) does/does not let me do.
Someone in this forum tried to answer this question chatting to me, but it got frustrating as they didn't seem to understand what I want to achieve. [Though "thank you" @that-person :) ] So I'm going to try to lay out what I want, as clearly and briefly as I can.
-
I want to design a
QTableWidget, and I want to do this in Designer as I will want to visually set it to have certain rows, columns, cell contents, and various fonts etc. Clear enough? -
And, I want to make that
QTableWidgetbe aclass MyTableWidget : QTableWidget. So that, multiple places in my code can gonew MyTableWidget, and get that table widget, together with its design-time rows/columns/cells/styles and whatever I add into the class later in code. Clear enough?
I cannot do this in Designer for 2 reasons:
-
When I go New File, template Qt Designer Form Class, the
QTableWidgetis not on offer in Available Widgets (only "container" ones are). So, I have to pick plain Widget here. -
This gives me a top-level
QWidget. I cannot either Promote, or Morph Into, this top-level widget fromQWidgetto eitherQTableWidgetorMyTableWidget.
So.... I look at the source in the
.uifile, and in the.cpp/.hfiles.-
I see
<widget name="MyTableWidget" class="QWidget">(.uifile) , andclass MyTableWidget : public QWidget(.h/.cppfiles). -
I manually change these from
QWidgettoQTableWidget. (Just changing the.uiline did not do it, needed to manually do.h&.cppfiles too.) But it took me ages to figure this is what I needed to do. -
Lo and behold, everything now works 100,000% like I want! I can still view/edit the
.uiin Designer, e.g. to add my cells, without it breaking. And code can goMyTableWidget instanceornew MyTableWidget.
My question: if Designer is quite happy with this, why in the world did I have to figure how to do this manually, why doesn't it just let me do this??
What I do not want to have to do is either of:
-
No, I don't want to go to the hassle of defined a Custom Widget for this, too much work given that I get just what I want with manual editing.
-
No, I do not want a top-level
QWidgetwhich has aQTableWidgetdragged onto it as a child. Why would I? It's not what I want, and the resulting would not give a sub-class ofMyTableWidget.
Am I supposed to make these changes manually, like I did, and that's just how it is? Why is this seemingly-simple requirement so abstruse to achieve? I want to design a top-level
QTableWidget, not some other widget which happens to have aQTableWidgetsomewhere on it.... -
-
I just don't get what Designer (in Creator) does/does not let me do.
Someone in this forum tried to answer this question chatting to me, but it got frustrating as they didn't seem to understand what I want to achieve. [Though "thank you" @that-person :) ] So I'm going to try to lay out what I want, as clearly and briefly as I can.
-
I want to design a
QTableWidget, and I want to do this in Designer as I will want to visually set it to have certain rows, columns, cell contents, and various fonts etc. Clear enough? -
And, I want to make that
QTableWidgetbe aclass MyTableWidget : QTableWidget. So that, multiple places in my code can gonew MyTableWidget, and get that table widget, together with its design-time rows/columns/cells/styles and whatever I add into the class later in code. Clear enough?
I cannot do this in Designer for 2 reasons:
-
When I go New File, template Qt Designer Form Class, the
QTableWidgetis not on offer in Available Widgets (only "container" ones are). So, I have to pick plain Widget here. -
This gives me a top-level
QWidget. I cannot either Promote, or Morph Into, this top-level widget fromQWidgetto eitherQTableWidgetorMyTableWidget.
So.... I look at the source in the
.uifile, and in the.cpp/.hfiles.-
I see
<widget name="MyTableWidget" class="QWidget">(.uifile) , andclass MyTableWidget : public QWidget(.h/.cppfiles). -
I manually change these from
QWidgettoQTableWidget. (Just changing the.uiline did not do it, needed to manually do.h&.cppfiles too.) But it took me ages to figure this is what I needed to do. -
Lo and behold, everything now works 100,000% like I want! I can still view/edit the
.uiin Designer, e.g. to add my cells, without it breaking. And code can goMyTableWidget instanceornew MyTableWidget.
My question: if Designer is quite happy with this, why in the world did I have to figure how to do this manually, why doesn't it just let me do this??
What I do not want to have to do is either of:
-
No, I don't want to go to the hassle of defined a Custom Widget for this, too much work given that I get just what I want with manual editing.
-
No, I do not want a top-level
QWidgetwhich has aQTableWidgetdragged onto it as a child. Why would I? It's not what I want, and the resulting would not give a sub-class ofMyTableWidget.
Am I supposed to make these changes manually, like I did, and that's just how it is? Why is this seemingly-simple requirement so abstruse to achieve? I want to design a top-level
QTableWidget, not some other widget which happens to have aQTableWidgetsomewhere on it....@JonB
I got no takers here :'( This topic ended up being discussed over at https://forum.qt.io/topic/121019/qt-designer-for-qtablewidget-sub-class. Where I accepted @Christian-Ehrlicher answer of:This is only possible with a designer plugin.
-