Application Development with Qt Creator, Third Edition by Lee Zhi Eng

Application Development with Qt Creator, Third Edition by Lee Zhi Eng

Author:Lee Zhi Eng [Lee Zhi Eng]
Language: eng
Format: epub, mobi
Tags: COM051070 - COMPUTERS / Programming Languages / C++, COM070000 - COMPUTERS / User Interfaces, COM051230 - COMPUTERS / Software Development and Engineering / General
Publisher: Packt
Published: 2020-01-31T13:30:58+00:00


This code creates a window of 360 pixels in height and width, and two rectangles. Qt places the first rectangle centered in the parent window, and it places the second rectangle to the right-hand side of the first one with the same top lines.

Anchoring doesn't just affect placement, but it can affect sizing too. Consider the following QML:

import QtQuick 2.12 import QtQuick.Window 2.12 Window { visible: true width: 360 height: 360 Rectangle { id: rect1 height: 100 width: 100 anchors.left: parent.left; anchors.verticalCenter: parent.verticalCenter color: "gray" } Rectangle { id: rect2 anchors.left: rect1.right anchors.top: rect1.top; anchors.bottom: rect1.bottom anchors.right: rect3.left color: "black" } Rectangle { id: rect3 height: 100 width: 100 anchors.right: parent.right; anchors.verticalCenter: parent.verticalCenter color: "gray" } }

This places two squares on either side of the parent window, with a rectangle stretched between the two squares. Note that the anchor.left parameter of rect2 is set to the rect1.right value, and anchor.right of rect2 is set to the rect3.left value. The following screenshot shows how it looks:



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.