Layouting in QT Designer



  • Hello guys,

    i have installed the Qt4.8.7 sdk in my VS2008 enviroment. No iam able to develop some Qt code. I have greated a simple QtApplication with QMainWindow. The layout of my gui is pure coded in cpp. I could use the Qt Designer to layout my gui elements but its ugly... an do it in the code too.

    Iam from the .NET WPF world, the its possible to do the layout via XAML. So i have find out, that its possible in Qt via QML to. But no the question. Its it possible to layout (with preview) my gui via QML in the QT Designer, like XAML in WPF?

    Sorry for my bad english


  • Qt Champions 2017

    My inputs. Qt 4.8.7 is very old Qt version. You can think of using the new Qt. Qt Widgets and QML(QtQuick) are different ways to write the UI.

    You can use the Qt Designer for creating the user interface. Designer is available for QtWIdgets and QML also. Unlike XAML, Qt Designer is not like you write something in XML and it will start the UI. When you do UI in Qt Designer, it creates the XML file only.



  • Good Morning , thank for replay:)

    Unfortunately i have to use the 4.8.7 Version because of 2008 C++ compatibility.

    My intension is, to create the ui layout via QML in QT Designer , and see the result directly (like XAML Rendering in Visual Studio). After i have do this, QT Diesinger can create me the layout code for my app (Moc compiler). Is this possible? Its very strange an need a lot of time , to layout the ui in code and ervery change need a new build and start the app to see se result



  • @Boris1980 said in Layouting in QT Designer:

    Good Morning , thank for replay:)
    Its very strange an need a lot of time , to layout the ui in code and ervery change need a new build and start the app to see se result

    no it doesn't QML code is interpreted code no need to recompile your whole application. You just need to reload your QML file

    I have this code inside my main.cpp that I'm calling when I press F5 inside my app. very handy to have:

    void clearAndReload( QQmlApplicationEngine &engine){
        for(QObject *obj : engine.rootObjects()){
            engine.rootObjects().removeOne(obj);
            obj->deleteLater();
        }
        engine.clearComponentCache();
        engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
    
        for(QObject *obj : engine.rootObjects()){
            QuickWindow *window = qobject_cast<QuickWindow*>(obj);
            if(window)QObject::connect(window, &QuickWindow::reloadQML, &engine,[&engine]{clearAndReload(engine);});
        }
    }
    
    {
    .....
    QQmlApplicationEngine engine;
    engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
    
    for(QObject *obj : engine.rootObjects()){
            //I have a custom root element class, normaly this should be QQuickWindow
            QuickWindow *window = qobject_cast<QuickWindow*>(obj);
            if(window) QObject::connect(window, &QuickWindow::reloadQML, &engine,[&engine]{clearAndReload(engine);});
        }
    
    ....
    

    My intension is, to create the ui layout via QML in QT Designer , and see the result directly (like XAML Rendering in Visual Studio). After i have do this, QT Diesinger can create me the layout code for my app (Moc compiler). Is this possible?

    The QtCreator allows for a preview of your QML files if you simply click, when you're inside the QML file onto the Design tab and you get that one. It won't show aynthing however if your QML-code does not have default sizes.


Log in to reply
 

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