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

Qt Creator: copy and paste widgets why is it so hard



  • Like in https://forum.qt.io/topic/69525/copying-combo-box-items-in-qt-designer

    Why it is such a hassle to duplicate a button or such?

    I have a widget X, in it button A. Copy button A, paste it into widget X... and no, error: "Cannot paste widgets. Designer could not find a container without a layout to paste into".

    So I have to break layout of X, paste into X, then set layout of X back to what it was? Why can't QtCreator do that on it's own?
    Also, on two steps it sends me back to top of the widgets tree list (if it is a long list especially) which is annoying as you need to find back where you were in the list...


  • Lifetime Qt Champion

    @egorski said in Qt Creator: copy and paste widgets why is it so hard:

    Why can't QtCreator do that on it's own?

    Where exactly in the layout should the Qt designer put the copied widget into? Random place?



  • @egorski said in Qt Creator: copy and paste widgets why is it so hard:

    So I have to break layout of X, paste into X, then set layout of X back to what it was?

    You can do easier than that, I believe. Calling @mrjj. He showed me how to do something about copy a widget via getting it into a list over at the left-hand side categories, and then I could drag it back as many tines as wanted. IIRC that let me copy widgets, hope I'm not wrong, he should come along and clarify :)



  • @Christian-Ehrlicher said in Qt Creator: copy and paste widgets why is it so hard:

    Where exactly in the layout should the Qt designer put the copied widget into? Random place?

    Yes.

    Putting it in any position (e.g. at any sort order when placing in Vertical/Horizontal/table layout, or any x,y inside the parent to which I paste it).

    Then I can easily move it to proper place.

    Or a bit better: put it always as last element - and possibly give user an small combo-box to configure where elements are pasted into: first, last, or ask.

    Then I have to only drag it once, now I have to break, unbreak, scroll the widgets view twice, and still put it to proper sorting order too.



  • @egorski said in Qt Creator: copy and paste widgets why is it so hard:

    Then I have to only drag it once, now I have to break, unbreak, scroll the widgets view twice, and still put it to proper sorting order too.

    ...which is why we need @mrjj to remind you/me what he showed me to avoid this...


  • Lifetime Qt Champion

    @egorski said in Qt Creator: copy and paste widgets why is it so hard:

    Yes.

    Feel free to provide a patch :)



  • @egorski
    Since for unknown reasons @mrjj did not come visit this thread to comment, I went off to remind myself how to do this in Qt Creator.

    You can copy & paste an existing widget, with its settings, in Designer. Despite the error message telling you you have to break & reform layout, but it's not obvious.

    1. Design your widget, set its size, properties etc..
    2. Drag it over to the left-hand list of existing widgets, and drop it onto an empty space there.
    3. At this point that list changes to have a new Scratchpad category at the bottom of the list.
    4. That category contains your widget, with its name.
    5. You can now drag that widget onto your design area as many times as you wish, creating a copy each time, with its properties.

    So it may not be obviously documented, but this is a canvenient way to copy & paste your widgets without messing with the existing layout.


  • Moderators

    @JonB That is indeed convenient, and hod I known this was a thing, I probably would still be using Designer for most stuff, instead of doing it by hand.

    Well, it helped developing my inner-eye visualisation skills :P



  • @J-Hilk
    I agree whole-heartedly!

    I too found it a pain that Designer does not allow copy/paste of widgets, despite @Christian-Ehrlicher's objections. For example, Visual Studio certainly does. (I don't recall whether it places the paste randomly, or it may attach an outline of the pasted control to the mouse cursor for you to put wherever you want.) This is not an uncommon feature to want!

    As I said earlier, I did not know about this Qt Designer Scratchpad feature until @mrjj showed me once. It may not be obvious or even elegant, but it sure is useful!


Log in to reply