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. What is the easiest way to desing an "edit mode" via my GUI in QtDesigner?
Forum Updated to NodeBB v4.3 + New Features

What is the easiest way to desing an "edit mode" via my GUI in QtDesigner?

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 3 Posters 858 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    Hey guys,

    How would you implement an "edit mode" in QT Designer? I have created my GUI. To view the data, I want the GUI to look like this:

    lesemodus.png

    To edit the data and thus the "edit mode" I would like to build the GUI like this:

    bearbeitungsmodus.png

    Currently I have built the GUI over a QStackWidget. As soon as I press the "Bearbeiten" button, the view is switched. What is bothering me about this now? Well I have in principle almost the same view twice with QLineEdits, QPlainTextEdit and QListView and so on and would have to add the data also correspondingly about a QDataWidgetMapper with both views.

    Therefore my question: Is there a better way to design such an "edit mode"?

    Thanks a lot for your tips!

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

      Hi,

      Create one editor widget and use it twice.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      ? 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        Create one editor widget and use it twice.

        ? Offline
        ? Offline
        A Former User
        wrote on last edited by A Former User
        #3

        @SGaist
        Thanks for the feedback. If I interpret this correctly I need to create a class in QT Creator e.g. "EditorWidget" and draw my GUI using the designer. At the end I have a .ui, .h and .cpp file. Now I have created a new object with EditorWidget *editor = new EditorWidget in my constructor of my MainWindow.cpp. My MainWindow contains a QStackWidget with a page and in this page a few things are created (see screenshot).

        exmple.png

        I have tried the following:

            ui->setupUi(this);
            editor = new EditorWidget;
            
            ui->stackedWidget->setCurrentIndex(0);
            ui->stackedWidget->insertWidget(0, editor);  //have tried index from 0 - 10 nothing happend
        

        But unfortunately my editor widget is not added to page 1.

        What else can I do? I still found this. Do I really have to implement it like this?
        https://stackoverflow.com/questions/23275909/adding-widgets-to-qt-designer

        JonBJ 1 Reply Last reply
        0
        • ? A Former User

          @SGaist
          Thanks for the feedback. If I interpret this correctly I need to create a class in QT Creator e.g. "EditorWidget" and draw my GUI using the designer. At the end I have a .ui, .h and .cpp file. Now I have created a new object with EditorWidget *editor = new EditorWidget in my constructor of my MainWindow.cpp. My MainWindow contains a QStackWidget with a page and in this page a few things are created (see screenshot).

          exmple.png

          I have tried the following:

              ui->setupUi(this);
              editor = new EditorWidget;
              
              ui->stackedWidget->setCurrentIndex(0);
              ui->stackedWidget->insertWidget(0, editor);  //have tried index from 0 - 10 nothing happend
          

          But unfortunately my editor widget is not added to page 1.

          What else can I do? I still found this. Do I really have to implement it like this?
          https://stackoverflow.com/questions/23275909/adding-widgets-to-qt-designer

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by JonB
          #4

          @Gabber
          That reference is for seeing a custom widget in Qt Designer. I assume your question is about the runtime behaviour when you run your application.

          Your code looks OK (though you should set the current index after you have inserted the widget rather than before).

          Start by checking you can see the EditorWidget OK without putting it on the QStackedWidget. Put some other Qt widget on your QStackedWidget, does that work?

          ? 1 Reply Last reply
          0
          • JonBJ JonB

            @Gabber
            That reference is for seeing a custom widget in Qt Designer. I assume your question is about the runtime behaviour when you run your application.

            Your code looks OK (though you should set the current index after you have inserted the widget rather than before).

            Start by checking you can see the EditorWidget OK without putting it on the QStackedWidget. Put some other Qt widget on your QStackedWidget, does that work?

            ? Offline
            ? Offline
            A Former User
            wrote on last edited by
            #5

            @JonB

            If I setCurrentIndex after the insertWidget statement it works. Unfortunately this is not what I want to achieve. A QStackWidget has "pages" (2 by default) in QtCreator and I want to add my editor widget to this page 1 with the designed widgets from MainWindow. How can I do that? Is it possible at all?

            JonBJ 1 Reply Last reply
            0
            • ? A Former User

              @JonB

              If I setCurrentIndex after the insertWidget statement it works. Unfortunately this is not what I want to achieve. A QStackWidget has "pages" (2 by default) in QtCreator and I want to add my editor widget to this page 1 with the designed widgets from MainWindow. How can I do that? Is it possible at all?

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by JonB
              #6

              @Gabber said in What is the easiest way to desing an "edit mode" via my GUI in QtDesigner?:

              If I setCurrentIndex after the insertWidget statement it works.

              Well that's good.

              I don't really know what you mean. If Designer automatically puts 2 pages in for you, and you don't want one of them, and you can't delete it at design-time, you can always delete it at runtime. You can insert your widget as a new page in its place if that's what you mean. OTOH, if you mean you already have a page, perhaps with some widgets, from design-time and you just want to add your widget onto that page, you won't want to be calling ui->stackedWidget->insertWidget().

              1 Reply Last reply
              0
              • ? Offline
                ? Offline
                A Former User
                wrote on last edited by
                #7

                @JonB

                Sorry for my poor explanation. My MainWindwo already contains a created GUI to which I want to add the EditorWidget. Here is a screenshot:

                editor.png
                As you can see on the right, the QStackWidget has a "firstPage". And to this "firstPage" I want to add my EditorWidget. How can I do that?

                Later I have to create a "secondPage" and add the EditorWidget there as well, which works via ui->stackWidget->addWidget(editor).

                JonBJ 1 Reply Last reply
                0
                • ? A Former User

                  @JonB

                  Sorry for my poor explanation. My MainWindwo already contains a created GUI to which I want to add the EditorWidget. Here is a screenshot:

                  editor.png
                  As you can see on the right, the QStackWidget has a "firstPage". And to this "firstPage" I want to add my EditorWidget. How can I do that?

                  Later I have to create a "secondPage" and add the EditorWidget there as well, which works via ui->stackWidget->addWidget(editor).

                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on last edited by JonB
                  #8

                  @Gabber
                  Something like ui->stackedWidget->firstPage()->modelLayout->addWidget(editor)? [Actually just ui->modelLayout->addWidget(editor) may work.]

                  In one case you are adding widget onto an existing page, in the other case you are adding widget as a new page on the stacked widget.

                  1 Reply Last reply
                  0
                  • ? Offline
                    ? Offline
                    A Former User
                    wrote on last edited by
                    #9

                    @JonB

                    Thank you very much for your tip! I have now managed it as follows: ui->firstPage->layout()->addWidget(editor);

                    My problem is solved. 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