Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt Designer for QTableWidget sub-class
Forum Updated to NodeBB v4.3 + New Features

Qt Designer for QTableWidget sub-class

Scheduled Pinned Locked Moved Solved General and Desktop
11 Posts 2 Posters 1.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Online
    J Online
    JonB
    wrote on 19 Nov 2020, 17:35 last edited by JonB
    #1

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

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 19 Nov 2020, 18:33 last edited by
      #4

      This is only possible with a designer plugin.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      J 1 Reply Last reply 19 Nov 2020, 18:36
      1
      • C Offline
        C Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on 19 Nov 2020, 17:46 last edited by
        #2

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

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        J 1 Reply Last reply 19 Nov 2020, 17:58
        1
        • C Christian Ehrlicher
          19 Nov 2020, 17:46

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

          J Online
          J Online
          JonB
          wrote on 19 Nov 2020, 17:58 last edited by JonB
          #3

          @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?

          1 Reply Last reply
          0
          • C Offline
            C Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on 19 Nov 2020, 18:33 last edited by
            #4

            This is only possible with a designer plugin.

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            J 1 Reply Last reply 19 Nov 2020, 18:36
            1
            • C Christian Ehrlicher
              19 Nov 2020, 18:33

              This is only possible with a designer plugin.

              J Online
              J Online
              JonB
              wrote on 19 Nov 2020, 18:36 last edited by JonB
              #5

              @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 :)

              1 Reply Last reply
              0
              • C Offline
                C Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on 19 Nov 2020, 18:46 last edited by
                #6

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

                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                Visit the Qt Academy at https://academy.qt.io/catalog

                J 1 Reply Last reply 19 Nov 2020, 19:05
                0
                • C Christian Ehrlicher
                  19 Nov 2020, 18:46

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

                  J Online
                  J Online
                  JonB
                  wrote on 19 Nov 2020, 19:05 last edited by JonB
                  #7

                  @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

                  1 Reply Last reply
                  0
                  • C Offline
                    C Offline
                    Christian Ehrlicher
                    Lifetime Qt Champion
                    wrote on 19 Nov 2020, 19:19 last edited by
                    #8

                    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.

                    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                    Visit the Qt Academy at https://academy.qt.io/catalog

                    J 1 Reply Last reply 19 Nov 2020, 19:29
                    0
                    • C Christian Ehrlicher
                      19 Nov 2020, 19:19

                      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.

                      J Online
                      J Online
                      JonB
                      wrote on 19 Nov 2020, 19:29 last edited by JonB
                      #9

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

                      1 Reply Last reply
                      0
                      • C Offline
                        C Offline
                        Christian Ehrlicher
                        Lifetime Qt Champion
                        wrote on 19 Nov 2020, 20:08 last edited by
                        #10

                        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?

                        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                        Visit the Qt Academy at https://academy.qt.io/catalog

                        J 1 Reply Last reply 19 Nov 2020, 20:26
                        0
                        • C Christian Ehrlicher
                          19 Nov 2020, 20:08

                          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?

                          J Online
                          J Online
                          JonB
                          wrote on 19 Nov 2020, 20:26 last edited by JonB
                          #11

                          @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 :)

                          1 Reply Last reply
                          0

                          1/11

                          19 Nov 2020, 17:35

                          • Login

                          • Login or register to search.
                          1 out of 11
                          • First post
                            1/11
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • Users
                          • Groups
                          • Search
                          • Get Qt Extensions
                          • Unsolved