Is it possible to override designer double click functionality on a custom widget?

  • I've created a custom designer widget that inherits from QTableWidget. I'd like to override the double click functionality (that happens while you are in designer and that causes a pop up form that populates the table to appear) so that I can allow the user to select the columns AND column types (QLineEdit, QComboBox, QSpinBox, QCheckBox) to be used in the table.

    Currently, I assign this programmatically, but it would be much more convenient to do it via the designer. I can't seem to find anything revolving around the words "qt override designer double click functionality", at least nothing that actually pertains to the subject.

    Can anyone explain how or provide me to a link of said documentation?

  • Lifetime Qt Champion

    That's not possible.

  • Darn, I figured since widgets like QLineEdit, QTableWidget, QLabel, and QComboBox all have different double click functionalities within the designer that we would be able to override that within our custom widgets as well...

    Are we able to open a custom form when we set a Q_PROPERTY value for a custom widget in the designer that returns the value to set the property to?

    My objective here is to be able to select each column name and type (and type attributes such as min/max for SpinBox, ComboBox items, etc) for the table in the designer. Without one or the other I don't see any non-hardcoded way of achieving this.

  • Lifetime Qt Champion

    No, only the Qt-designer default editors are possible.

  • Darn, okay. Is there a list of these default editors anywhere so I can see what my options are?

  • Lifetime Qt Champion

    @KidTrent No, it's not - it's just the ones you've in the property editor, nothing more. It's just a simple tool to create uis, not a programming tool.

  • I've been playing around with the Q_PROPERTY macro in my custom widget just because this has to be possible in some way, and I found out very early that it is....

    The solution is quite simple, you can make a popup window appear in the designer through the Q_PROPERTY macro. The hard part, for me, was making the window allow the user to configure properties from objects derived of Q_OBJECT (done).

    What I did was, create a Q_PROPERTY that calls a function on WRITE that opens the custom window. The READ call simply outputs if there settings are set or not, in my case "Options Set" and "Options Not Set".

    Q_PROPERTY(QString options READ getOptions WRITE setOptions);

    There are a two quirks I'm currently working through right now with this solution:

    • You have to actually change the options string value, instead of just clicking the input, for the setOptions function to be called.
    • The same window appears to popup even if you are running the program and not in design mode...
    • The values used in the designer, don't persist into runtime... working on this now. I thought about this for some time, the .u file could maybe be modified to store the values in xml i need to look more into this... Either this or save/load to/from settings.

  • Lifetime Qt Champion

    @KidTrent said in Is it possible to override designer double click functionality on a custom widget?:

    The same window appears to popup even if you are running the program and not in design mode...

    Because properties are for run-time. The designer just use them to display you a simple ui to insert values for initialization phase (within setupUi) - nothing more.

  • I'm slowly starting to get a better understanding of how to accomplish what I need. I managed to correctly open the editor and override the actual "double click" functionality I was originally asking about. It is simple, but my mistake was thinking the double click functionality was just a double click... it actually runs the default item list in the task menu that appears when you right click the widget in the designer.

    Anyways, anyone looking to "override" the designers "double click" functionality on custom widgets you need to add a custom QDesignerTaskMenuExtension to your custom widget. Then you can have the window that opens up set the tables columns and column properties of your widget.

    Once I understood the idea, it took me like 5 minutes to implement (it looks scarier than it is). Qt has a pretty good example of this located here:

    Now I just have to figure out how to apply the results of my popup to the .ui file....

Log in to reply