Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Qt Designer for QTableWidget sub-class



  • Over in Tools a few days ago I posted Qt Designer design a QTableWidget and make it a sub-class, but sadly didn't get any further takers at all :'(

    So I'm going to try literally making this a "one-line" question. For any details read over there. All I want to know is:

    Using Qt Designer, interactively, is it possible to generate a .ui file which starts with these 4 lines (i.e. lines #3 & #4 are what I care about):

    <?xml version="1.0" encoding="UTF-8"?>
    <ui version="4.0">
     <class>MySubclassTableWidget</class>
     <widget class="QTableWidget" name="MySubclassTableWidget">
    

    [I can only achieve it by starting to design, say, a QWidget and then editing the .ui file manually.]


  • Lifetime Qt Champion

    This is only possible with a designer plugin.


  • Lifetime Qt Champion

    Yes, you have to promote the widget to your custom widget.



  • @Christian-Ehrlicher
    But Christian that is exactly what my question I referenced over in Tools (https://forum.qt.io/topic/120849/qt-designer-design-a-qtablewidget-and-make-it-a-sub-class) explains is not possible, and why I asked about it....

    Would you be kind enough to read it? The gist is note that I ask for the very start of the .ui file to be the widget-type I want, i.e. the top-level. Nothing else is acceptable. Show me how you can Promote any top-level widget in Designer, because I say I can't?


  • Lifetime Qt Champion

    This is only possible with a designer plugin.



  • @Christian-Ehrlicher
    Well now, that's the answer! Which is what I requested, even if it's not favourable :) At least I know.

    As I explain in the other thread, not being able to alter the top-level widget-type to any Qt widget I might want to sub-class is a shame. 'Coz I've proved how easy it is.. All I do is edit the .ui file, and I have to change the class-derived-from-name in the generated .cpp/.h files, and I do get exactly what I want for designing a sub-class, so why Designer doesn't allow something so useful I don't know :)


  • Lifetime Qt Champion

    Because a QTableWidget is no top-level widget. It can be used as this but should not in normal cases. :)



  • @Christian-Ehrlicher
    No, it is not. But what can I say? I want a class MyTableWidget : QTableWidget. And I want to design it in Designer. And I don't want to begin to go the hassle of wring a custom widget pluggy-thing.

    Thing is, with my couple of edits done, I can now do exactly this, designing it. So I think Designer is missing out, when it could allow it easily. But there you are, I have a workaround


  • Lifetime Qt Champion

    Sorry but a QTableWidget is no top-level widget. It needs at least some buttons to close the window so therefore use a QWidget, add your QTableWidget and you're done.



  • @Christian-Ehrlicher

    use a QWidget, add your QTableWidget and you're done.

    Oh dear, that's the whole point of what I don't want. I want to be able to go new MyTableWidget all over the place, as a re-usable component, and be able to call all QTableWidget methods on it. I'm not going to reflect all those out of my QWidget. I'm not going to expose the child QTableWidget publicly and tell the outside world to call its methods instead. I don't want to design a QWidget which happens to have my desired QTableWidget as a child inside it. I want to design a class derived from QTableWidget.

    It needs at least some buttons to close the window

    What window? I'm going to use it where I would use a QTableWidget. It won't be a "window" of its own. Sometimes I'll put it on some window or dialog, sometimes I'll use it inside a popup window, etc.

    I believe a Designer custom plugin-widget would allow just this. But I don't want to do that because it's more complex than I need. Nothing wrong with it, I'm just asking about doing it without.

    I'm sorry, but (politely) I don't understand how yours is the solution. And I don't understand (politely) what is difficult to understand or objectionable about what I'm trying to do. This is why I (tried to) describe it all very clearly over at https://forum.qt.io/topic/120849/qt-designer-design-a-qtablewidget-and-make-it-a-sub-class, we're going through the detail here now.

    Only by doing the couple of edits is it achievable, and despite what you say the resulting sub-class works great/as intended.


  • Lifetime Qt Champion

    Sorry but I still don't understand what you want. If you want a custom widget and edit your self-defined properties than you need a designer plugin. If you just want a customized QTableWidget to use somewhere else in your windows than propagate this in designer.
    What else can be done with your QTableWidget apart from those two options above?



  • @Christian-Ehrlicher
    No, I do not need to edit self-defined design-time properties. If I do want to put it onto another widget/window at design-time, I am quite happy with Promote. (Other times I create one dynamically from code.) I do understand that if I did want to expose new design-time properties to edit I would need a proper custom widget, with its code.

    But I just don't need that. I am designing a table, or tables, that has quite some design-time layout and content. Think of how much you can tailor on a QTableWidget at design-time. It has some fixed rows, fixed columns, headers, some of the cells are filled in at design-time. I want to drag out particular column widths. I have bolding on some items. And so on & so forth.

    Oh, and by the way, yes I do go back and change the content/layout over time. Please don't suggest copying & pasting onto other forms! (Your " than propagate this in designer"??)

    Yes, I absolutely could just write code for my class MyTableWidget, deriving from QTableWidget so I can access all those methods, and add my own for this table. And do all that design-time stuff in code. Then nobody would give me a hard time. But I want to use Designer for QTableWidget on it. Please!

    As I said before, settling for a top-level QWidget which has my desired QTableWidget as a child just does not give me my desired interface to the outside world of a class MyTableWidget : QTableWidget.

    Now I don't see what is hard to understand about this situation :)


Log in to reply