Controls from scratch
-
wrote on 16 Aug 2021, 15:31 last edited by
Hi,
Is making control from scratch - making all from rectangles etc. have any sense, its rally work faster in big apps? -
Hi,
Is making control from scratch - making all from rectangles etc. have any sense, its rally work faster in big apps?@qtprogrammer123 said in Controls from scratch:
Hi,
Is making control from scratch - making all from rectangles etc. have any sense, its rally work faster in big apps?Each
Item
orRectangle
you add constructs a new QObject and adds objects to drawing queue for the scene graph - so making custom components in this way is not "really faster" - it makes your app slower.Often, on desktops, it does not matter much, but on mobile and embedded platforms it can make a big difference.
The Quick Controls 2 are built in a different way - they are subclasses of QQuickItem and do their painting directly in C++ using OpenGL (or, nowadays, using RHI) - that's why they have such good performance when compared to Controls 1.
-
wrote on 17 Aug 2021, 09:11 last edited by qtprogrammer123
Ok thx, just in case i give example.
import QtQuick 2.0 Item { id: control property string text: '' property bool checked: false property real padding: 0.1 width: 30 + text.paintedWidth; height: 30 opacity: enabled && !mouseArea.pressed ? 1: 0.3 Rectangle { id: rectangle height: control.height * (1 - 2 * padding); width: height x: padding * control.height anchors.verticalCenter: parent.verticalCenter border.width: 2 border.color: mouseArea.pressed ? "gray" : "darkgray" radius: 0.2 * height color: checked ? (mouseArea.isEntred ? "#63d7ff" : "#4fc1e9") : (mouseArea.isEntred ? "#e1e6ef" : "#ccd1d9") Text { color: "white" visible: checked anchors.centerIn: parent text: '\u2713' font.pixelSize: parent.height - parent.border.width } } Text { id: text text: control.text anchors {left: rectangle.right; verticalCenter: rectangle.verticalCenter; margins: padding * control.height} font.pixelSize: 0.5 * control.height } MouseArea { id: mouseArea property bool isEntred: false hoverEnabled: true anchors.fill: parent onClicked: checked = !checked onEntered: isEntred = true onExited: isEntred = false } }
This will be slower at desktop app? Even i dont see it
-
Slower than what?
-
wrote on 17 Aug 2021, 11:48 last edited by
Than custom checkbox but made at qucik2 CheckBox base
CheckBox{ indicator... currentItem... }
-
I don't know. To notice any performance difference I guess you'd have to spawn 50 of them and test on some slow device. I guess custom-styled Controls 2 are going to be faster due to some optimizations they can do to drawing, but I don't really know this for sure.
To me it's more of a question of what do you prefer to use as a programmer, what will be easier to write and maintain.
1/6