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



  • 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?



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



  • 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!





  • 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.





  • [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.



  • 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()'"*



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



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



  • 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.



  • 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.



  • 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?



  • 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?



  • Nope. No idea.



  • 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?



  • 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.



  • 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.



  • 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.



  • 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".



  • I try do this too and nothing:

    @
    WidgetMCI *wMCI = new WidgetMCI( this );
    contentWidget->layout()->addWidget( wMCI );
    @



  • Sorry, my layout was missing the layout component to handle with added widget!



  • [quote author="dcbasso" date="1341259385"]Sorry, my layout was missing the layout component to handle with added widget![/quote]

    So... it is solved?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.