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. Creating double Widgets
Forum Updated to NodeBB v4.3 + New Features

Creating double Widgets

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 583 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.
  • F Offline
    F Offline
    FleeXo
    wrote on last edited by FleeXo
    #1

    Hey,
    Im very new to Qt. Now I followed the Qt Code Editor Example and wanted adapt this example to an ui form. But now it is getting
    created twice. Once with the right logic and once just blank.
    Maybe someone can help me and teach me what I am doing wrong.
    I would really appreciate it.
    Here are the sources: https://github.com/tzAcee/qt_IDE Everything about the editor is in the editor.cpp/.h

    Greetings
    Maxim

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      Hi and welcome to the forums

      Your custom editor is also a PlainTextWidget so i think maybe you were meant to use the promotion feature
      to have that editor in UI become your custom widget/editor

      The code you have simply create a new Editor and use the existing
      "Editor" as parent.
      QPlainTextEdit a = ui->centralwidget->findChild<QPlainTextEdit>("editor");
      _editor = new Editor(a);
      This just create a new one. And as you see is put inside the Editor you already have on UI form.

      Lets try Promotion. ( which is a Creator feature that lets you use custom widgets)
      First
      remove lines
      // QPlainTextEdit a = ui->centralwidget->findChild<QPlainTextEdit>("editor");
      // _editor = new Editor(a);
      then
      go to Editor.H, ctor

      Editor(QPlainTextEdit *parent = nullptr);

      This says parent will be QPlainTextEdit but that wont work. so
      Change it to
      Editor(QWidget *parent = nullptr);
      also change in .CPP ! ( Editor::Editor(QWidget *parent) : QPlainTextEdit(parent) )

      Then go to Mainwindow.ui
      right click the Editor widget and select "Promote To" menu item

      Then add the info (editor.h and Editor)
      alt text
      and press ADD
      Then Press Promote
      Then Press oK

      Then rebuild all
      and now when you run the Widget in UI becomes your custom widget
      alt text

      Hope this explains well enough, else ask :)

      changed project
      https://www.dropbox.com/s/j002mgft8iipml1/qt_IDE-master.zip?dl=0

      F 1 Reply Last reply
      2
      • mrjjM mrjj

        Hi and welcome to the forums

        Your custom editor is also a PlainTextWidget so i think maybe you were meant to use the promotion feature
        to have that editor in UI become your custom widget/editor

        The code you have simply create a new Editor and use the existing
        "Editor" as parent.
        QPlainTextEdit a = ui->centralwidget->findChild<QPlainTextEdit>("editor");
        _editor = new Editor(a);
        This just create a new one. And as you see is put inside the Editor you already have on UI form.

        Lets try Promotion. ( which is a Creator feature that lets you use custom widgets)
        First
        remove lines
        // QPlainTextEdit a = ui->centralwidget->findChild<QPlainTextEdit>("editor");
        // _editor = new Editor(a);
        then
        go to Editor.H, ctor

        Editor(QPlainTextEdit *parent = nullptr);

        This says parent will be QPlainTextEdit but that wont work. so
        Change it to
        Editor(QWidget *parent = nullptr);
        also change in .CPP ! ( Editor::Editor(QWidget *parent) : QPlainTextEdit(parent) )

        Then go to Mainwindow.ui
        right click the Editor widget and select "Promote To" menu item

        Then add the info (editor.h and Editor)
        alt text
        and press ADD
        Then Press Promote
        Then Press oK

        Then rebuild all
        and now when you run the Widget in UI becomes your custom widget
        alt text

        Hope this explains well enough, else ask :)

        changed project
        https://www.dropbox.com/s/j002mgft8iipml1/qt_IDE-master.zip?dl=0

        F Offline
        F Offline
        FleeXo
        wrote on last edited by
        #3

        @mrjj Thank you very much it just works fine.
        The hint with the promoting feature was just amazing!

        mrjjM 1 Reply Last reply
        1
        • F FleeXo

          @mrjj Thank you very much it just works fine.
          The hint with the promoting feature was just amazing!

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @FleeXo
          Super :)
          The docs just in case
          https://doc.qt.io/qt-5/designer-using-custom-widgets.html

          Also note we have dynamic properties.
          So you can add new properties in Designer and read at runtime in code.
          That makes it possible to be able to tweak custom widgets design time without having to write a full-blown
          plugin to have them truly as custom widgets as the other std. widgets.

          alt text

          I love the Promotion feature and use alot :)

          F 1 Reply Last reply
          2
          • mrjjM mrjj

            @FleeXo
            Super :)
            The docs just in case
            https://doc.qt.io/qt-5/designer-using-custom-widgets.html

            Also note we have dynamic properties.
            So you can add new properties in Designer and read at runtime in code.
            That makes it possible to be able to tweak custom widgets design time without having to write a full-blown
            plugin to have them truly as custom widgets as the other std. widgets.

            alt text

            I love the Promotion feature and use alot :)

            F Offline
            F Offline
            FleeXo
            wrote on last edited by
            #5

            @mrjj I will definitly give it a try, thank you :)

            1 Reply Last reply
            1

            • Login

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