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. Drawing rectangle and line using ui.label
Forum Updated to NodeBB v4.3 + New Features

Drawing rectangle and line using ui.label

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
8 Posts 2 Posters 1.4k Views 1 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.
  • MontanaroM Offline
    MontanaroM Offline
    Montanaro
    wrote on last edited by Montanaro
    #1

    Hi
    i can draw rectangle using QML. For example:

    *import QtQuick 2.0

    Rectangle {
    width: 100
    height: 100
    color: "red"
    x: 5
    y:10
    }*

    but how i can draw rectangle into Ui ?
    using: ui.mylabel.setText("...") i can write
    but how i can draw ? rectangle, line … ?

    thanks

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

      What is "ui" you are referring to? Some other QML file? Or qml.ui file? Can you post it's contents?

      (Z(:^

      1 Reply Last reply
      0
      • MontanaroM Offline
        MontanaroM Offline
        Montanaro
        wrote on last edited by Montanaro
        #3

        I posted my code here:
        https://forum.qt.io/topic/98911/qml-swipeview-and-state-machine

        the problem is drawing rectangle in label.
        I use: ui->label->setText("ISTRUCTION1 \n"); to write.
        But how i can draw ? for example rectangle ?

        I have to draw rectangle and to write a text.
        My code is good for text but not for drawing.
        (i have to build a form. My task is similar to this: https://media.istockphoto.com/photos/yes-and-no-boxes-with-red-checkmark-on-no-picture-id185009675 )

        So I have two choice:

        1. drawing rectangle without qml but with method

        2. drawing rectangle with qml, for example using this code:

        *SwipeView {
        id: view

        currentIndex: 1
        anchors.fill: parent
        
        Item {
            id: firstPage
        }
        Item {
            id: secondPage
        }
        Item {
            id: thirdPage
        }
        

        }

        PageIndicator {
        id: indicator

        count: view.count
        currentIndex: view.currentIndex
        
        anchors.bottom: view.bottom
        anchors.horizontalCenter: parent.horizontalCenter
        

        }*

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

          If you want to add a checkbox, you can do this:

          Row {
           Text {
              width: contentWindth
              text: "Some text"
            }
            Rectangle {
              width: 15
              height: width
              border.width: 1
            }
          }
          

          There are many other ways to achieve this, too. There is a built-in CheckBox element, for instance.

          (Z(:^

          MontanaroM 1 Reply Last reply
          0
          • sierdzioS sierdzio

            If you want to add a checkbox, you can do this:

            Row {
             Text {
                width: contentWindth
                text: "Some text"
              }
              Rectangle {
                width: 15
                height: width
                border.width: 1
              }
            }
            

            There are many other ways to achieve this, too. There is a built-in CheckBox element, for instance.

            MontanaroM Offline
            MontanaroM Offline
            Montanaro
            wrote on last edited by
            #5

            @sierdzio no i dont want to add checkbox.
            . i want a slide show.
            When i push button or combination of buttons, i want ad immagine with text.
            for example:
            i push esc/enter button and left arrow , i go ahead.
            i push esc/enter button esc and right arrow, i go back.
            i push button left arrow without button esc or right, nothing must be happened.
            i push esc/enter button, i storage i pressed button.
            these are my cases.
            so i build a state machine.
            but i dont connect my state machine in cpp with qml.

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

              So what that story about drawing a line or a text for? I'm sorry but I can't help you if I don't even know what the question is...

              If you want to spawn some QML components based on changes in your state machine, you can use:

              • Loader component
              • Qt.createComponent
              • instantiate custom QQuickItem from C++ and push it to the scene

              If you need to learn more abour state transitions, check out https://doc.qt.io/qt-5/qml-tutorial3.html

              But I have a feeling that you want something else entirely...

              (Z(:^

              1 Reply Last reply
              0
              • MontanaroM Offline
                MontanaroM Offline
                Montanaro
                wrote on last edited by
                #7

                thanks for info, i following that.

                "So what that story about drawing a line or a text for?"
                well, if you see my code, you can see that i show a label with text.
                the instruction is "ui.label.setText("my text") but text is not enough for my task. I need a rectangle (to check) near the text. So i asked there is some instruction (ui.label.draw...)

                sierdzioS 1 Reply Last reply
                0
                • MontanaroM Montanaro

                  thanks for info, i following that.

                  "So what that story about drawing a line or a text for?"
                  well, if you see my code, you can see that i show a label with text.
                  the instruction is "ui.label.setText("my text") but text is not enough for my task. I need a rectangle (to check) near the text. So i asked there is some instruction (ui.label.draw...)

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

                  @Montanaro said in Drawing rectangle and line using ui.label:

                  well, if you see my code, you can see that i show a label with text.

                  I don't have time to research your project. Please paste relevant parts here.

                  the instruction is "ui.label.setText("my text") but text is not enough for my task. I need a rectangle (to check) near the text. So i asked there is some instruction (ui.label.draw...)

                  That's why I suggested using a CheckBox, that is that it's for. A text element is capable of displaying text, not drawing shapes. You need to change your UI to fit your drawing needs.

                  (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