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
QTableWidget
be 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
QTableWidget
is 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 fromQWidget
to eitherQTableWidget
orMyTableWidget
.
So.... I look at the source in the
.ui
file, and in the.cpp
/.h
files.-
I see
<widget name="MyTableWidget" class="QWidget">
(.ui
file) , andclass MyTableWidget : public QWidget
(.h
/.cpp
files). -
I manually change these from
QWidget
toQTableWidget
. (Just changing the.ui
line did not do it, needed to manually do.h
&.cpp
files 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
.ui
in Designer, e.g. to add my cells, without it breaking. And code can goMyTableWidget instance
ornew 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
QWidget
which has aQTableWidget
dragged 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 aQTableWidget
somewhere 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
QTableWidget
be 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
QTableWidget
is 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 fromQWidget
to eitherQTableWidget
orMyTableWidget
.
So.... I look at the source in the
.ui
file, and in the.cpp
/.h
files.-
I see
<widget name="MyTableWidget" class="QWidget">
(.ui
file) , andclass MyTableWidget : public QWidget
(.h
/.cpp
files). -
I manually change these from
QWidget
toQTableWidget
. (Just changing the.ui
line did not do it, needed to manually do.h
&.cpp
files 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
.ui
in Designer, e.g. to add my cells, without it breaking. And code can goMyTableWidget instance
ornew 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
QWidget
which has aQTableWidget
dragged 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 aQTableWidget
somewhere 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.
-