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. Take "delete" & "add" RoundButton out of a selection zone
Forum Updated to NodeBB v4.3 + New Features

Take "delete" & "add" RoundButton out of a selection zone

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
4 Posts 2 Posters 309 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.
  • Y Offline
    Y Offline
    Yazid10
    wrote on last edited by
    #1

    I made a component named MultipleChoiceQuestion that creates dynamically instance of multiple choice question as you can see in the picture below :

    zone.PNG

    I would love to take the round buttons "-" and "+" out of the selection zone, i.e. only the title, checkboxes and TextEdit elements should remain in the rectangle when I'm selecting it.
    The rectangle border is blue when I'm clicking on the zone and grey when I'm clicking outside.

    Here is my code :

    import QtQuick
    import QtQuick.Window
    import QtQuick.Controls 2.5
    import QtQuick.Controls.Material 2.3
    import QtQml 2.3
    
    
    Rectangle {
        id: root
    
    
        property QtObject elementModel
        property bool selected: elementModel.selectedItem === root ? true : false
    
        ListModel {
            id: choiceModel
        }
    
        border.color: root.selected ? "blue" : "grey"
        radius: 5
        width: parent.width / 2
        height: column.height
    
        Column {
            id: column
    
            TextInput {
                id: title
    
                anchors.horizontalCenter: column.horizontalCenter
                font.pixelSize: 20
                text: "Title..."
            }
    
    
            Repeater {
                model: choiceModel.count
    
                Row {
                    id: row
    
                    RoundButton {
                        x: 100
                        width: 30
                        height: 30
                        anchors.verticalCenter: row.verticalCenter
    
                        text: "-"
                        visible: root.selected
    
                        onClicked:
                        {
                            choiceModel.remove(index,1)
                        }
                    }
    
                    CheckBox {
                        id: checkbox
    
                        anchors.verticalCenter: row.verticalCenter
    
                        checked: choiceModel.get(index).checked
    
                        onCheckedChanged:
                        {
                            choiceModel.get(index).checked = checked
                        }
                    }
    
                    TextEdit {
                        anchors.verticalCenter: checkbox.verticalCenter
                        verticalAlignment: TextEdit.AlignVCenter
    
                        width: root.width - 100
    
                        text: choiceModel.get(index).text
    
                        onTextChanged:
                        {
                            choiceModel.get(index).text = text
                        }
    
                        wrapMode: TextEdit.Wrap
    
                    }
    
                    Item {
                        id: space
                        width: 20
                        height: checkbox.height
                    }
                }
            }
    
            RoundButton {
                width: 30
                height: 30
                text: "+"
                visible: root.selected
    
                onClicked:
                {
                    choiceModel.append({ text: "New choice", checked: false })
                }
            }
        }
    
        MouseArea {
            id: mouseArea
    
            anchors.fill: root
    
            enabled: !root.selected
    
            onClicked: {
                if (!root.selected)
                {
                    elementModel.selectedItem = root
                }
            }
        }
    
        Component.onCompleted: {
            choiceModel.append({ text: "Choice 1", checked: false })
            choiceModel.append({ text: "Choice 2", checked: false })
            choiceModel.append({ text: "Choice 3", checked: false })
        }
    }
    
    sierdzioS 1 Reply Last reply
    0
    • Y Yazid10

      I made a component named MultipleChoiceQuestion that creates dynamically instance of multiple choice question as you can see in the picture below :

      zone.PNG

      I would love to take the round buttons "-" and "+" out of the selection zone, i.e. only the title, checkboxes and TextEdit elements should remain in the rectangle when I'm selecting it.
      The rectangle border is blue when I'm clicking on the zone and grey when I'm clicking outside.

      Here is my code :

      import QtQuick
      import QtQuick.Window
      import QtQuick.Controls 2.5
      import QtQuick.Controls.Material 2.3
      import QtQml 2.3
      
      
      Rectangle {
          id: root
      
      
          property QtObject elementModel
          property bool selected: elementModel.selectedItem === root ? true : false
      
          ListModel {
              id: choiceModel
          }
      
          border.color: root.selected ? "blue" : "grey"
          radius: 5
          width: parent.width / 2
          height: column.height
      
          Column {
              id: column
      
              TextInput {
                  id: title
      
                  anchors.horizontalCenter: column.horizontalCenter
                  font.pixelSize: 20
                  text: "Title..."
              }
      
      
              Repeater {
                  model: choiceModel.count
      
                  Row {
                      id: row
      
                      RoundButton {
                          x: 100
                          width: 30
                          height: 30
                          anchors.verticalCenter: row.verticalCenter
      
                          text: "-"
                          visible: root.selected
      
                          onClicked:
                          {
                              choiceModel.remove(index,1)
                          }
                      }
      
                      CheckBox {
                          id: checkbox
      
                          anchors.verticalCenter: row.verticalCenter
      
                          checked: choiceModel.get(index).checked
      
                          onCheckedChanged:
                          {
                              choiceModel.get(index).checked = checked
                          }
                      }
      
                      TextEdit {
                          anchors.verticalCenter: checkbox.verticalCenter
                          verticalAlignment: TextEdit.AlignVCenter
      
                          width: root.width - 100
      
                          text: choiceModel.get(index).text
      
                          onTextChanged:
                          {
                              choiceModel.get(index).text = text
                          }
      
                          wrapMode: TextEdit.Wrap
      
                      }
      
                      Item {
                          id: space
                          width: 20
                          height: checkbox.height
                      }
                  }
              }
      
              RoundButton {
                  width: 30
                  height: 30
                  text: "+"
                  visible: root.selected
      
                  onClicked:
                  {
                      choiceModel.append({ text: "New choice", checked: false })
                  }
              }
          }
      
          MouseArea {
              id: mouseArea
      
              anchors.fill: root
      
              enabled: !root.selected
      
              onClicked: {
                  if (!root.selected)
                  {
                      elementModel.selectedItem = root
                  }
              }
          }
      
          Component.onCompleted: {
              choiceModel.append({ text: "Choice 1", checked: false })
              choiceModel.append({ text: "Choice 2", checked: false })
              choiceModel.append({ text: "Choice 3", checked: false })
          }
      }
      
      sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      @Yazid10 said in Take "delete" & "add" RoundButton out of a selection zone:

      visible: root.selected

      Just negate the argument:

      visible: !root.selected
      

      (Z(:^

      Y 1 Reply Last reply
      0
      • sierdzioS sierdzio

        @Yazid10 said in Take "delete" & "add" RoundButton out of a selection zone:

        visible: root.selected

        Just negate the argument:

        visible: !root.selected
        
        Y Offline
        Y Offline
        Yazid10
        wrote on last edited by
        #3

        @sierdzio this will make them invisible when I create an instance of the component.

        I want something like this :

        zonne.PNG

        I tried adding a child rectangle while making the parent rectangle transparent but that didn't work because of the column and the repeater

        sierdzioS 1 Reply Last reply
        0
        • Y Yazid10

          @sierdzio this will make them invisible when I create an instance of the component.

          I want something like this :

          zonne.PNG

          I tried adding a child rectangle while making the parent rectangle transparent but that didn't work because of the column and the repeater

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

          Oh, I see. This makes it somewhat harder, indeed.

          One solution which comes to my mind (but is rather ugly): take these buttons out of Row so that their positioning is not automatic, and assign them negative x coordinate. This will push them to the left.

          Another solution would be to make the blue border Rectangle independent. So: root rect should have no border (it can even be an Item since it will be invisible), but it should have another Rectangle as a child (but not under Repeater!), with border.

          (Z(:^

          1 Reply Last reply
          1

          • Login

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