Does Qt have a counterpart to flexbox?

I am developing a widget that allows users to choose answers, and I would like to arrange them in a specific layout. Check out this example: https://jsfiddle.net/yxs1bmq6/1/

Try resizing the window and observe how the boxes behave.

Is there a straightforward method to create a layout similar to this one?

Here is the HTML:

<div class="container">
  <div class="box">
  box1
  </div>
  <div class="box">
  box2
  </div>
  ...
</div>

And here is the CSS:

.container {
  display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: space-around;
    align-items: center;
    align-content: space-around;
  background-color: aqua;
  height: 500px;
}
.box {
  background-color: green;
  padding: 50px;
}

Answer №1

Absolutely, I have created a custom set of bindings for the Yoga layout engine. Utilizing flexboxes proves to be much more user-friendly compared to the standard Qt Quick layout tools. You can find the source code here.

https://i.sstatic.net/q9naM.png

import QtQuick 2.5
import QtQuick.Window 2.0

Window {
    visible: true
    height: 400
    width: 675
    Rectangle {
        anchors.fill: parent
        color: "cyan"
        Flex {
            height: parent.height
            width: parent.width

            flexDirection: "row"
            flexWrap: "wrap"
            justifyContent: "spaceAround"
            alignItems: "center"
            alignSelf: "center"
            alignContent: "stretch"

            Rectangle { color: "green"; height: 150; width: 150 }
            Rectangle { color: "green"; height: 150; width: 150 }
            Rectangle { color: "green"; height: 150; width: 150 }
            Rectangle { color: "green"; height: 150; width: 150 }
            Rectangle { color: "green"; height: 150; width: 150 }
            Rectangle { color: "green"; height: 150; width: 150 }
            Rectangle { color: "green"; height: 150; width: 150 }
        }
    }
}

Answer №2

It appears that there are possibilities to manipulate QML's grids using their flow properties.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

html: div broken

The HTML document reads as follows: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"& ...

What steps can I take to correct the footer positioning to appear below the sidebar?

I'm currently struggling with the placement of my sidebar on top of my footer, which is not where it belongs. I would like to move it to the bottom. Take a look at this image for a visual representation of what I'm aiming for. footer { paddi ...

What is the best way to show an element when hovering over another element?

I'm looking for a CSS-only solution (NO JQuery) to display a FontAwsome icon (<i class='fas fa-arrow-alt-circle-left fa-lg arrowbounce text-success hidearrowbounce'></i>) only when hovering over another element. However, despite ...

Arrays of functions in C++

Struggling with an array of functions here. When trying to assign the functions to the array in the default constructor of the class, I keep getting this error message: "void (GameObject::*)()" cannot be used to initialize an entity of type "AlarmFuncti ...

Is there a way to apply CSS to an image so that it appears to be resting on a surface like a 3D object

I need to create a 3D floor with cartoons placed on top. The floor has a grid where each cartoon is positioned. I want to maintain the same axis for both the floor and grid, but I need the images and text in each grid element to be at a 90-degree angle to ...

I'm looking for advice on transitioning from Windows programming to Linux programming in C/C++. Any suggestions?

Possible Duplicate: transitioning from Windows to Linux programming Seeking a reliable and concise resource for transitioning from Windows programming to Linux programming. I have basic programs running and have explored daemon architecture, but I&apo ...

Create a new variable and compile the sass/less file when it is requested

I'm exploring options to utilize Node.js or another server-side language to handle a specific type of request. For instance, receiving a request like this: The goal is to extract the value from the URL parameter and use it to dynamically update a var ...

Create unique list markers by utilizing the "::marker" and "content" properties

When attempting to create a list with custom list markers, I encountered an issue. An example from MDN is provided: li::marker { content: '✝ '; font-size: 1.2em; } <p>Group known as Mercury Seven:</p> <ul> <li& ...

CSS Flexibility in Action

Presently, my tab bar has a fixed look as shown here: https://codepen.io/cdemez/pen/WNrQpWp Including properties like width: 400px; etc... Upon inspecting the code, you'll notice that all the dimensions are static :-( Consequently, I am encountering ...

Center align `div 1` with CSS and right align `div 2`

Take a look at this code snippet: http://jsfiddle.net/zygnz/1/ <div class="container"> <div class="left"> LEFT </div> <div class="right"> RIGHT </div> </div> Is i ...

It appears that the query parameters are impacting the speed at which the page loads

I am currently developing a project on this platform. It is using c9.io, an innovative browser-based collaborative programming IDE. The index.php file includes the following script: <?php $path = ltrim($_SERVER['REQUEST_URI'], '/&ap ...

Adding a close icon to the mobile menu in Bootstrap 5: A step-by-step guide

As a newcomer to web development, I am currently working on creating a responsive/mobile menu with a close icon for Bootstrap 5. Despite my efforts and exploration, I have been unable to successfully add the close icon to the mobile menu. Any assistance i ...

Guide on transforming inline assembler code into a .asm file

Struggling with converting an inline assembler function to a .asm file? The x64 architecture lacks support for inline assembly, necessitating separate code. Here's the code snippet: #include <windows.h> #include <string> #include <iost ...

An unanticipated error occurred at **** Unauthorized access when attempting to read **** location

I encountered an error message saying: "Unhandled exception at 0x00d23737 in Test.exe: 0xC0000005: Access violation reading location 0x8a8c0344" This issue arises when running the code snippet below: int main(int argc, char* argv[]) { string My_String_Arr ...

What causes a logical negation of a value -2147483648 to produce a result of 1?

After creating an integer variable my_int_min and assigning it the value INT_MIN, my_int_min = -my_int_min = INT_MIN = -INT_MIN = -2147483648 I expected the expression !(-my_int_min & INT_MIN) to be 0, but it actually resulted in 1. Furthermore, !(-m ...

The fixed div width suddenly switches to 100% without warning

I'm struggling with a basic design issue. My goal is to align the purple div next to the yellow div. Both of these divs are nested inside the white div, and the white div is enclosed within the blue div. When I float the yellow and purple divs to the ...

Showcasing various images simultaneously within a table cell with the power of JavaScript

For my game project, I need to create an 8x8 table where multiple coins are displayed simultaneously for 3000 milliseconds at random positions. When the "Start" button is clicked, the coin display should continue for 1 minute. However, I am facing an issue ...

Perfectly aligning the Update Progress Animation in real-time

I am currently utilizing the Ajax UpdateProgress with a loading gif attached. The issue I am facing is how to ensure that the loading.gif always appears in the center of the screen, even if the user is at the very top or bottom of the page. Is there a meth ...

What is the correct way to horizontally center a Material icon within a div?

How do I correctly center a Material Design icon within a div to fix the gap issue? I have tried using text-align on the items div, but it hasn't worked. (Refer to screenshots for clarification) https://i.sstatic.net/eHuiR.png https://i.sstatic.net/nL ...

What is the best way to position a button under an h3 heading using the display flex

Inside my div, I have an h3 and a button. The div uses display:flex; with justify-content:center; and align-items:center;. However, the button ends up sticking to the right side of the h3. I attempted placing the button in its own div, but this caused a la ...