Important: Please read the Qt Code of Conduct -

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.

    1. 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?

    2. And, I want to make that QTableWidget be a class MyTableWidget : QTableWidget. So that, multiple places in my code can go new 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:

    1. 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.

    2. This gives me a top-level QWidget. I cannot either Promote, or Morph Into, this top-level widget from QWidget to either QTableWidget or MyTableWidget.

    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) , and class MyTableWidget : public QWidget (.h/.cpp files).

    • I manually change these from QWidget to QTableWidget. (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 go MyTableWidget instance or new 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 a QTableWidget dragged onto it as a child. Why would I? It's not what I want, and the resulting would not give a sub-class of MyTableWidget.

    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 a QTableWidget somewhere on it....

  • @JonB
    I got no takers here :'( This topic ended up being discussed over at Where I accepted @Christian-Ehrlicher answer of:

    This is only possible with a designer plugin.

  • @JonB
    I got no takers here :'( This topic ended up being discussed over at Where I accepted @Christian-Ehrlicher answer of:

    This is only possible with a designer plugin.

Log in to reply