Qt World Summit: Register Today!

What should we use as a container

  • Hi everyone,

    there is often the the situation where you need kind of a container, where you just put multiple elements in to position them.

    But I was wondering what is the best element to do so. Btw. I use qt Quick controls .

    So there are the following elements:

    1. Rectangle
    2. Item
    3. Pane
    4. Page
    5. Container?

    So the first one draws a background unless I say color: "transparent", so probably not the best way to go. The thrid and fourth things have paddings and also a background, which might be good under some circumstances, but not always. Container seems prett logical, but it doesn't seem to work. And item works perfectly, but isn't very semantic. Item could be anything .

    So actually Container would be probably the best, but it doesn't work. At the moment I'm using Item. What do you use or consider as the best?

  • @Leon_2001 You would have to give an example of what you are trying to do, from what you mention it seems like Column or Row, which are positioner's, would be a better option inside a container, but your question is about containers themselves, but by themselves they just containers, and their use is more of a base, and you use each one differently depending on what you need to do, but it sounds like you might be better off looking at Layout and Views as tools for use with containers to add controls too.

    I look at it his way:

    Container: This is a base class, that you derive or extend from, it is a special use Container, when you do not want other methods implemented, and want to implement them yourself.

    Rectangle: Use this if you want content inside of a Rectangle, this is mostly for visual items.

    Item: Use this if you have an Item that requires more visual control than Rectangle.

    Pane: Use this inside a layout positioner, by it self it only defines a region.

    Page: Is a high level container control, that makes it easy to add content and add a header or footer.

    One container does not rule them all, by themselves they are just building blocks.

    If you look at examples of how to use them, you will find that you can use them all in the same example, this requires nesting, for example the top level tag defines what can be nested inside of it, for example you can add a Page, add a Column to that page, nesting it inside of it, then nest a Pane inside the Column, but your container will normally sit at the top level of your App, nested inside of it or outside of it, depending on what the top level container is, and how the file is structured, and is normally only referenced by ID inside the nested controls and containers, so it makes a good data source or model for data, and a Page can be the top level in file that your App uses, and can be added to navigation to open them and run that code, you can do this with Item and Rectangle as well as other containers, so they act as a module, making them reusable, which is the whole concept behind containers, and why you use each for a specific job you need to do, so you have to anchor these containers to their parents, and use methods to position them within that container, so you have to add layout and views to handle this fine-tuning of where you want lets say a Rectangle to go, because by itself, it can only define what size it is, as well as colors and text and other visual aspects, and you have to use offsets for padding and margins, so without some type of layout or view control, containers are very limited at how they can position things inside of them, so containers are the base, they have methods that give them functionality, they can be accessed using the dot operator or Qml Tag; for example text: "this", or thisID.text = "this", one is Qml the other is JavaScript, so if you want to know what something can do, just hit dot, and see its methods, and use controls, layout and views for fine-tuning.

    I hope that helps.

Log in to reply