Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Controls from scratch
Qt 6.11 is out! See what's new in the release blog

Controls from scratch

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
6 Posts 2 Posters 1.1k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • qtprogrammer123Q Offline
    qtprogrammer123Q Offline
    qtprogrammer123
    wrote on last edited by
    #1

    Hi,
    Is making control from scratch - making all from rectangles etc. have any sense, its rally work faster in big apps?

    Mam moc jak Harry Potter, w zębach mogę przenieść hotel.

    sierdzioS 1 Reply Last reply
    0
    • qtprogrammer123Q qtprogrammer123

      Hi,
      Is making control from scratch - making all from rectangles etc. have any sense, its rally work faster in big apps?

      sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      @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 or Rectangle 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.

      (Z(:^

      1 Reply Last reply
      0
      • qtprogrammer123Q Offline
        qtprogrammer123Q Offline
        qtprogrammer123
        wrote on last edited by qtprogrammer123
        #3

        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

        Mam moc jak Harry Potter, w zębach mogę przenieść hotel.

        1 Reply Last reply
        1
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

          Slower than what?

          (Z(:^

          1 Reply Last reply
          0
          • qtprogrammer123Q Offline
            qtprogrammer123Q Offline
            qtprogrammer123
            wrote on last edited by
            #5

            Than custom checkbox but made at qucik2 CheckBox base

            CheckBox{
            
               indicator...
            
              currentItem...
            
            }
            

            Mam moc jak Harry Potter, w zębach mogę przenieść hotel.

            1 Reply Last reply
            0
            • sierdzioS Offline
              sierdzioS Offline
              sierdzio
              Moderators
              wrote on last edited by
              #6

              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.

              (Z(:^

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved