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 Gui Application, alingment and/or anchoring...
Forum Updated to NodeBB v4.3 + New Features

QT Gui Application, alingment and/or anchoring...

Scheduled Pinned Locked Moved General and Desktop
23 Posts 4 Posters 13.7k 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.
  • D Offline
    D Offline
    dcbasso
    wrote on last edited by
    #1

    Hello everyone, I'm trying to anchor some elements (link a tabWidget) inside the widget with VerticalLayout, but my tabWidget don't expand/anchor with the widget element.
    And the same think to widget, is not anchored with your parent (MainWindow/CentralWidget), and the widget to resize when I resize the mainWindow.

    How can I make elements/widgets to be anchors with your parents and auto-resize with the parent..
    Can anyone understand my problem?

    1 Reply Last reply
    0
    • ZlatomirZ Offline
      ZlatomirZ Offline
      Zlatomir
      wrote on last edited by
      #2

      Use add your widgets into a "layout":http://qt-project.org/doc/qt-4.8/layout.html

      https://forum.qt.io/category/41/romanian

      1 Reply Last reply
      0
      • D Offline
        D Offline
        dcbasso
        wrote on last edited by
        #3

        It's possible to create an application with using .ui files and make some .ui works like a component?

        I mean:

        UI:
        Main.ui
        MenuBar.ui
        Login.ui
        Settings.ui

        I want to add to my Main.ui the login.ui, and after the user do the login on the system show the MenuBar.ui and if select the option settings on my MenuBar I load the Settings.ui side-by-side with Menu.ui.

        If it's possible... How can I make that? Some examples, videos... anything that can Helps me to create my application using QT.

        Thanks all!

        1 Reply Last reply
        0
        • D Offline
          D Offline
          DerManu
          wrote on last edited by
          #4

          This might get you started:
          http://qt-project.org/doc/qt-4.8/qtuitools.html
          http://qt-project.org/doc/qt-4.8/quiloader.html#details
          http://qt-project.org/doc/qt-4.8/qformbuilder.html#details

          1 Reply Last reply
          0
          • A Offline
            A Offline
            andre
            wrote on last edited by
            #5

            Unfortunately, you cannot directly use a .ui as a component in another .ui. What you can do, is use the (or simply a) base class of the component you want to have in your form, and use the "widget promotion":/doc/qt-4.8/designer-using-custom-widgets.html#promoting-widgets feature of Qt Designer.

            1 Reply Last reply
            0
            • D Offline
              D Offline
              dcbasso
              wrote on last edited by
              #6

              http://qt-project.org/doc/qt-4.8/quiloader.html#details
              http://qt-project.org/doc/qt-4.8/qformbuilder.html#details

              I can't use this 2 class, the compiler give me an error everytime.

              1 Reply Last reply
              0
              • A Offline
                A Offline
                andre
                wrote on last edited by
                #7

                [quote author="dcbasso" date="1341232276"]http://qt-project.org/doc/qt-4.8/quiloader.html#details
                http://qt-project.org/doc/qt-4.8/qformbuilder.html#details

                I can't use this 2 class, the compiler give me an error everytime.[/quote]
                It would be so much easier to help you if you told us what error you are getting...

                Please consider that Qt is quite thoroughly tested, and is used by many of thousands of developers all over the world. That makes it likely (but of course, not guaranteed) that any error you run into are located in your code, not in Qt itself. I, at least, find that a helpful assumption when I'm debugging my applications.

                1 Reply Last reply
                0
                • D Offline
                  D Offline
                  dcbasso
                  wrote on last edited by
                  #8

                  Hi Andre! Thanks for the help, follow:

                  @#include <QFormBuilder>

                  void MainWindow::abrirMCI() {
                  QFormBuilder builder;
                  QFile file(":/forms/modulocentralinterface.ui");
                  file.open(QFile::ReadOnly);
                  QWidget *myWidget = builder.load( &file, this );
                  ui->contentWidget->layout()->addWidget( myWidget );
                  }@

                  This code returns this:
                  "QFormBuilder: No such file or directory"

                  @#include <QUiLoader>

                  void MainWindow::abrirMCI() {
                  QUiLoader loader;
                  QFile file(":/forms/modulocentralinterface.ui");
                  file.open(QFile::ReadOnly);
                  QWidget *myWidget = loader.load( &file, this );
                  ui->contentWidget->layout()->addWidget( myWidget );
                  }@

                  This code returns this:
                  "QUiLoader: No such file or directory"

                  I try this resources too:
                  @
                  #include "QtUiTools/QUiLoader"

                  void MainWindow::abrirMCI() {
                  QUiLoader loader;
                  QFile file(":/forms/modulocentralinterface.ui");
                  file.open(QFile::ReadOnly);
                  QWidget *myWidget = loader.load( &file, this );
                  ui->contentWidget->layout()->addWidget( myWidget );
                  }@

                  This code returns this:
                  "undefined reference to 'QUiLoader::QUiLoader(QObject)'
                  undefined reference to 'QUiLoader::load(QIODevice*, QWidget*)'
                  undefined reference to 'QUiLoader::~QUiLoader()'"*

                  1 Reply Last reply
                  0
                  • A Offline
                    A Offline
                    andre
                    wrote on last edited by
                    #9

                    That is because these classes are in the UiTools module. You should add this to your .pro file:
                    @
                    CONFIG += uitools
                    @

                    1 Reply Last reply
                    0
                    • D Offline
                      D Offline
                      dcbasso
                      wrote on last edited by
                      #10

                      Andre, where I can find this information (in docs and other stuffs)?

                      1 Reply Last reply
                      0
                      • A Offline
                        A Offline
                        andre
                        wrote on last edited by
                        #11

                        In the documentation, where I found it too!

                        However, I will admit that module information is not always easy to find, and in fact in this case I made a mistake here: uitools contains the QUiLoader class, but not the QFormBuilder class. The QFormBuilder class resides in the QtDesigner module, which you can add to your project using
                        @
                        CONFIG += designer
                        @

                        There is a reference to the uitools module in both the documentation of QFormBuilder and QUiLoader though, hence my confusion. The module page will give an overview of the classes in the module, and the .pro statement to use it.

                        1 Reply Last reply
                        0
                        • D Offline
                          D Offline
                          dcbasso
                          wrote on last edited by
                          #12

                          Thanks.
                          Now I can continue my study with QT!
                          I'm still trying to load the .ui on a widget component, it's not easy to do so.

                          1 Reply Last reply
                          0
                          • A Offline
                            A Offline
                            andre
                            wrote on last edited by
                            #13

                            It is not clear what you want to achieve to me. Why are you not using the "standard way":/doc/qt-4.8/designer-using-a-ui-file.html to use a .ui file?

                            1 Reply Last reply
                            0
                            • D Offline
                              D Offline
                              dcbasso
                              wrote on last edited by
                              #14

                              I have to many User Interface On My Application, and I was thinking to create a menu button and every button will change the contextWidget...
                              Undestand?

                              1 Reply Last reply
                              0
                              • A Offline
                                A Offline
                                andre
                                wrote on last edited by
                                #15

                                Nope. No idea.

                                1 Reply Last reply
                                0
                                • D Offline
                                  D Offline
                                  dcbasso
                                  wrote on last edited by
                                  #16

                                  Well...
                                  My application will have many screens... something about 23 screens (User Interface).
                                  It is complex to make all this screen on a single .ui file, and I was thinking to create a .ui file for every screen, because all screen will have many controls and elements (buttons, text area, comboBox and etc...)!

                                  So, my main UI (main.ui) will have the menu buttons on right side on screen and just want to change the "central elements" of this screen. This "central elements" I would to to load the .ui file on set on them...

                                  Undestand?

                                  1 Reply Last reply
                                  0
                                  • A Offline
                                    A Offline
                                    andre
                                    wrote on last edited by
                                    #17

                                    Ok, yes.

                                    Notice that those screens will then become separate classes. That may or may not be what you want; usually it is exactly what you want.

                                    You can use the method I pointed you to earlier to create these classes using your .ui files. Then, in your main file, you add these as pages in your view. I find it easiest to do that in code.

                                    1 Reply Last reply
                                    0
                                    • D Offline
                                      D Offline
                                      dcbasso
                                      wrote on last edited by
                                      #18

                                      The UiTools Approach

                                      @ QWidget* TextFinder::loadUiFile()
                                      {
                                      QUiLoader loader;

                                       QFile file&#40;":/forms/textfinder.ui"&#41;;
                                       file.open(QFile::ReadOnly);
                                      
                                       QWidget *formWidget = loader.load(&file, this);
                                       file.close();
                                      
                                       return formWidget;
                                      

                                      }@

                                      It's that you are saying?

                                      Thanks Andre, I was thinking that Was my Crazy Idea to make something like this, but Now I see that can be done in Qt.

                                      Thank you very much.

                                      1 Reply Last reply
                                      0
                                      • A Offline
                                        A Offline
                                        andre
                                        wrote on last edited by
                                        #19

                                        You probably don't need UiLoader or QFormBuilder. I have, in the 10 or so years I now work with Qt, only used these once or twice. If you've just started using Qt, chances are they really are not what you need.

                                        Just use the approach described in the first section of "the documentation":/doc/qt-4.8/designer-using-a-ui-file.html on how to use .ui files. This is also the standard way everything is created if you use File -> New File or Project -> Qt -> Qt Designer Form Class. Use that approach to create your pages. If you want to put all of those pages on a main form, use either code to create instances of your different widgets and add them to a tab widget on your main form, or add them from the main form .ui file using widget promotion.

                                        1 Reply Last reply
                                        0
                                        • D Offline
                                          D Offline
                                          dcbasso
                                          wrote on last edited by
                                          #20

                                          Sorry Andre, It's a very different concept for me and I'm not understanding how can I make this works....

                                          I try this:
                                          @
                                          WidgetMCI wMCI;
                                          ui->contentWidget->layout()->addWidget( &wMCI );
                                          @

                                          but another runtime error appers!
                                          I have used "File -> New File or Project -> Qt -> Qt Designer Form Class".

                                          1 Reply Last reply
                                          0

                                          • Login

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