Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Adding Qt Widget class - starting with "layout"



  • I am following the GUI documentation and somehow missed ability to start the "form" with layout "form" and ended up with enclosed setting of new form having no layout layer.

    I am enclosing both MainWindow (test modified by me ) and the new class forms for comparison.

    Two questions
    what did I do wrong to miss the "layout" part of the tree?
    do I have to delete all from the new form and just start with desired "layout". as "form layout" AKA can I insert the "top (tree) layout" ?

    Also
    what is "central widget" and how it got into the tree?

    e071b33f-0547-4ab5-836b-aa5cf0efb91e-image.png



  • @AnneRanch

    First image:
    You have added an additional layout (vertical) on your centralWidget , which has no layout. Better set a vertical layout to your centralWidget instead of adding a new one.

    @AnneRanch said in Adding Qt Widget class - starting wiht "layout":

    what is "central widget" and how it got into the tree

    https://doc.qt.io/qt-5/qmainwindow.html#details

    @AnneRanch said in Adding Qt Widget class - starting wiht "layout":

    do I have to delete all from the new form and just start with desired "layout". as "form layout" AKA can I insert the "top (tree) layout" ?

    You can keep the centralWidget as it's the main container / main widget inside a QMainWindow


  • Moderators

    To add to what @Pl45m4 already said:

    what did I do wrong to miss the "layout" part of the tree?

    You probably dragged a layout from the widgets palette on the left side. This results in the hierarchy you see - creates an anonymous widget child and sets a layout on it. To set a layout directly on the centralWidget select it and press any of the layout icons on the top toolbar or right click and choose one of the options in "Lay out" menu.

    do I have to delete all from the new form and just start with desired "layout". as "form layout" AKA can I insert the "top (tree) layout" ?

    You can drag widgets around between layouts or you can right click on a layout and change it to something else via that same "Lay out" menu. To get rid of that extra level in your picture select tabWidget and drag it to the centralWidget, then delete verticalLayout, select centralWidget and then press one of the layout buttons on top toolbar.



  • @Pl45m4 Thanks for the link. As always - the hardest part of getting info is to have an idea WHERE to find it or what to search for,
    That IMHO it is a primary goal of forum and this one is exceptionally helpful in "directing traffic ".

    You have actually answered another question I have been struggling with since I started using Qt.
    Is there a "main window"?

    I am comparing my code to other program and that one has multiple windows.
    I am going to rebuild my test program from scratch and hopefully won't have many questions after I get the "main window" concept going,

    I hope it is OK to add to this , I do not want to be accused of reposting stuff.

    I am working on "main window" and trying to use Qt Designer , not code, to design one of the already present "status" bars.
    I cannot find how - there seems to be no GUI option to edit the bar.
    Any hit woudl be appreciated.

    Thanks



  • @AnneRanch
    It seems that you have many questions that are about fundamental Qt issues. That's ok. We all started somewhere. Can I suggest that instead of trying to figure this all out by yourself, there are a lot of tutorials on YouTube and other sources that can help you get over the initial learning hump. The ones from VoidRealms are a little aged, but are particularly good at illustrating a single concept. I'm sure there are others that may help.



  • @mranger90 I am sure no matter how reply it will not personal satisfy you.
    But out of courtesy - I wish not to engage in discussion about my ways of learning Qt. Fair?



  • @AnneRanch

    According to your "status bar" question.

    The status bar, as well as menu bar and centralWidget, is always there, if you create a new QMainWindow. If you didn't delete it, it should be accessible by statusBar() from inside your mainWindow class.

    You can set your own QWidget as statusBar or work with the default one (displaying status messages, logs, info.. etc).

    https://doc.qt.io/qt-5/qstatusbar.html

    Everything depends on what you want to do :)
    Reading the Qt Doc here and there may help, try things out, check out functions, signals and from your Qt Creators auto-complete function and play around a bit.
    If you have no experience with Qt / Qt Creator it might look a bit confusing and hard to understand, but actually (IMO) the QT stuff is pretty intuitive and easy to learn.
    (At least the 'basic' things like creating widgets, defining layouts, signals & slots mechanism and so on)

    One last advice :)
    The Qt Designer, where you've created your QTabWidget is nice to quickly create a simple GUI. But it will help a lot if you try to re-create the same GUI with code only.
    Everything that can be done with Qt Designer, can be done with code, but there are several things where you have to use code, because Qt Designer is limited to some straightforward drag'n'drop widgets and static behavior.



  • @Pl45m4
    Figured it out.
    Main Window is different than plain QWidget- with many default parts.
    Automation strikes again. All I have to do is RTFM!

    Still looking for a way to see how a QWidget class gets "associated " with form.


  • Moderators

    @AnneRanch said in Adding Qt Widget class - starting with "layout":

    Still looking for a way to see how a QWidget class gets "associated " with form.

    This might provide some insight: https://doc.qt.io/qt-5/uic.html


Log in to reply