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. Combobox -

Combobox -

Scheduled Pinned Locked Moved Solved QML and Qt Quick
6 Posts 3 Posters 951 Views
  • 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.
  • 1 Offline
    1 Offline
    123456789
    wrote on last edited by
    #1

    why is the combobox not have text in black?
    https://prntscr.com/k1zegz

    jsulmJ 1 Reply Last reply
    0
    • 1 123456789

      why is the combobox not have text in black?
      https://prntscr.com/k1zegz

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @123456789 Maybe because of the moon phase? How is anybody going to know why? Can you please provide more information? Which combobox? Did you change the font color? Can you show your code?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      5
      • 1 Offline
        1 Offline
        123456789
        wrote on last edited by VRonin
        #3

        sorry @jsulm

        import QtQuick 2.7
        import QtQuick.Controls 2.2
        import QtQuick.Layouts 1.3
        import io.qt.awi_work_machine.backend 1.0
        import QtQuick.Controls.Material 2.0
        
        import QtQuick.Controls.Private 1.0
            Page {
                id: loginPage
                //property color mainAppColor: "#6fda9c"
               // property color mainTextCOlor: "#f0f0f0"
        
                background: Rectangle {
                    color: backGroundColor
                }
        
                Rectangle {
                    id: iconRect
        
                    y: 200
                    width: parent.width
                    // height: parent.height / 3
                    color: backGroundColor
        
                    Text {
                        id: icontext
                        text: qsTr("\uf0c0")
                        anchors.centerIn: parent
                        font.pointSize: 112
                        font.family: "fontawesome"
                        //color: mainAppColor
                    }
                }
        
                ComboBox {
                    id: combobox
                    y: 0
                    width: parent.width
                  // model: [ "Banana", "Apple", "Coconut" ]
                    height: 60
                  //  background: "#00000"
                    anchors.bottom: parent.bottom
                    anchors.bottomMargin: 250
                    Text{
                        //text: "\uf023"
                        font.pointSize: 14
                        text: model.currentText
        
                        font.family: "fontawesome"
        
                        anchors.left: parent.left
                        anchors.verticalCenter: parent.verticalCenter
                        leftPadding: 10
                    }
                    model:
                       ListModel {
                        id: model
                        ListElement { text: "Nível 1"; value: "1" }
                        ListElement { text: "Nível 2"; value: "2" }
                        ListElement { text: "Nível 3"; value: "3" }
                        ListElement { text: "Nível 4"; value: "4" }
                    }
                    onAccepted: {
                        if (find(currentText) === -1) {
                            model.append({text: editText})
                            currentIndex = find(editText)
                        }
                    }
                    onCurrentIndexChanged: {
                           console.log(model.get(currentIndex).text)
                    }
        
                }
        
                TextField {
                    id: idPasswordTextField
                    y: 550
                    placeholderText: qsTr("Password")
                    width: parent.width
                    Layout.preferredWidth: parent.width - 20
                    Layout.alignment: Qt.AlignHCenter
                  //  color: mainTextCOlor
                    font.pointSize: 14
                    font.family: "fontawesome"
                    leftPadding: 30
                    echoMode: TextField.PasswordEchoOnEdit
                    background: Rectangle {
                        implicitWidth: 200
                        implicitHeight: 50
                        radius: implicitHeight / 2
                        color: "transparent"
                        Text {
                            text: "\uf023"
                            font.pointSize: 14
                            font.family: "fontawesome"
                           // color: mainAppColor
                            anchors.left: parent.left
                            anchors.verticalCenter: parent.verticalCenter
                            leftPadding: 10
                        }
                    }
                }
                CButton{
                    y: 700
                    x: 250
                    width: 635
                    height: 62
                    text: qsTr("Log In")
                    leftPadding: 22.7
                    anchors.bottom: parent.bottom
                    anchors.bottomMargin: 100
                    anchors.left: parent.horizontalCenter
                    anchors.leftMargin: -320
                    onClicked: {
                        console.log("ProcessButton: id = ", combobox.model.get(combobox.currentIndex).value)
                        console.log("ProcessButton: Password = ", idPasswordTextField.text)
                    console.log(combobox.currentIndex)
        
                        if(idPasswordTextField.text == "m" && combobox.currentIndex === 0){
                            console.log("abriu")
                            uiContext.setLevel(combobox.currentIndex)
                            stackView.push("qrc:/Home.qml")
        
                        }else{
                            if(idPasswordTextField.text == "e" && combobox.currentIndex === 1){
                                console.log("abriu")
                                 uiContext.setLevel(combobox.currentIndex)
                                stackView.push("qrc:/Home.qml")
                            }else{
                                if(idPasswordTextField.text == "r" && combobox.currentIndex === 2){
                                    uiContext.setLevel(combobox.currentIndex)
                                    console.log("abriu")
                                    stackView.push("qrc:/Home.qml")
                                }else{
                                    if(idPasswordTextField.text == "d" && combobox.currentIndex === 3){
                                        uiContext.setLevel(combobox.currentIndex)
                                        console.log("abriu")
                                        stackView.push("qrc:/Home.qml")
                                    }else{
                                        console.log("error")
                                    }
                                }
                            }
                        }
                         uiContext.setLevel(combobox.model.get(combobox.currentIndex).color)
                    }
            }
        
        }
        
        
        jsulmJ 1 Reply Last reply
        0
        • 1 123456789

          sorry @jsulm

          import QtQuick 2.7
          import QtQuick.Controls 2.2
          import QtQuick.Layouts 1.3
          import io.qt.awi_work_machine.backend 1.0
          import QtQuick.Controls.Material 2.0
          
          import QtQuick.Controls.Private 1.0
              Page {
                  id: loginPage
                  //property color mainAppColor: "#6fda9c"
                 // property color mainTextCOlor: "#f0f0f0"
          
                  background: Rectangle {
                      color: backGroundColor
                  }
          
                  Rectangle {
                      id: iconRect
          
                      y: 200
                      width: parent.width
                      // height: parent.height / 3
                      color: backGroundColor
          
                      Text {
                          id: icontext
                          text: qsTr("\uf0c0")
                          anchors.centerIn: parent
                          font.pointSize: 112
                          font.family: "fontawesome"
                          //color: mainAppColor
                      }
                  }
          
                  ComboBox {
                      id: combobox
                      y: 0
                      width: parent.width
                    // model: [ "Banana", "Apple", "Coconut" ]
                      height: 60
                    //  background: "#00000"
                      anchors.bottom: parent.bottom
                      anchors.bottomMargin: 250
                      Text{
                          //text: "\uf023"
                          font.pointSize: 14
                          text: model.currentText
          
                          font.family: "fontawesome"
          
                          anchors.left: parent.left
                          anchors.verticalCenter: parent.verticalCenter
                          leftPadding: 10
                      }
                      model:
                         ListModel {
                          id: model
                          ListElement { text: "Nível 1"; value: "1" }
                          ListElement { text: "Nível 2"; value: "2" }
                          ListElement { text: "Nível 3"; value: "3" }
                          ListElement { text: "Nível 4"; value: "4" }
                      }
                      onAccepted: {
                          if (find(currentText) === -1) {
                              model.append({text: editText})
                              currentIndex = find(editText)
                          }
                      }
                      onCurrentIndexChanged: {
                             console.log(model.get(currentIndex).text)
                      }
          
                  }
          
                  TextField {
                      id: idPasswordTextField
                      y: 550
                      placeholderText: qsTr("Password")
                      width: parent.width
                      Layout.preferredWidth: parent.width - 20
                      Layout.alignment: Qt.AlignHCenter
                    //  color: mainTextCOlor
                      font.pointSize: 14
                      font.family: "fontawesome"
                      leftPadding: 30
                      echoMode: TextField.PasswordEchoOnEdit
                      background: Rectangle {
                          implicitWidth: 200
                          implicitHeight: 50
                          radius: implicitHeight / 2
                          color: "transparent"
                          Text {
                              text: "\uf023"
                              font.pointSize: 14
                              font.family: "fontawesome"
                             // color: mainAppColor
                              anchors.left: parent.left
                              anchors.verticalCenter: parent.verticalCenter
                              leftPadding: 10
                          }
                      }
                  }
                  CButton{
                      y: 700
                      x: 250
                      width: 635
                      height: 62
                      text: qsTr("Log In")
                      leftPadding: 22.7
                      anchors.bottom: parent.bottom
                      anchors.bottomMargin: 100
                      anchors.left: parent.horizontalCenter
                      anchors.leftMargin: -320
                      onClicked: {
                          console.log("ProcessButton: id = ", combobox.model.get(combobox.currentIndex).value)
                          console.log("ProcessButton: Password = ", idPasswordTextField.text)
                      console.log(combobox.currentIndex)
          
                          if(idPasswordTextField.text == "m" && combobox.currentIndex === 0){
                              console.log("abriu")
                              uiContext.setLevel(combobox.currentIndex)
                              stackView.push("qrc:/Home.qml")
          
                          }else{
                              if(idPasswordTextField.text == "e" && combobox.currentIndex === 1){
                                  console.log("abriu")
                                   uiContext.setLevel(combobox.currentIndex)
                                  stackView.push("qrc:/Home.qml")
                              }else{
                                  if(idPasswordTextField.text == "r" && combobox.currentIndex === 2){
                                      uiContext.setLevel(combobox.currentIndex)
                                      console.log("abriu")
                                      stackView.push("qrc:/Home.qml")
                                  }else{
                                      if(idPasswordTextField.text == "d" && combobox.currentIndex === 3){
                                          uiContext.setLevel(combobox.currentIndex)
                                          console.log("abriu")
                                          stackView.push("qrc:/Home.qml")
                                      }else{
                                          console.log("error")
                                      }
                                  }
                              }
                          }
                           uiContext.setLevel(combobox.model.get(combobox.currentIndex).color)
                      }
              }
          
          }
          
          
          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @123456789 Did you try to select an item in the combo box?

          https://forum.qt.io/topic/113070/qt-code-of-conduct

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

            yes
            item exist but not visual
            text is not black
            @jsulm

            1 Reply Last reply
            0
            • KillerSmathK Offline
              KillerSmathK Offline
              KillerSmath
              wrote on last edited by KillerSmath
              #6

              @123456789
              1) Why are you using if the ComboBox is not editable ?

               onAccepted: {
                   if (find(currentText) === -1) {
                       model.append({text: editText})
                       currentIndex = find(editText)
                   }
              }
              

              2) Why are you using a Text element inside of ComboBox and why are you getting currentText role of model if the model has'nt a element of this role ?

              Text{
                //text: "\uf023"
                font.pointSize: 14
                text: model.currentText
              
                font.family: "fontawesome"
              
                anchors.left: parent.left
                anchors.verticalCenter: parent.verticalCenter
                leftPadding: 10
              }
              

              ComboBox uses Model View Delegate paradigm, so if you want to set a custom Delegate, you must to set delegate property.

              3) When the model has more then one role,you must to set textRole property to specific what role should be showed
              In your case textRole: "text" can solve your problem of visibility
              https://doc.qt.io/qt-5.11/qml-qtquick-controls2-combobox.html#textRole-prop

              @Computer Science Student - Brazil
              Web Developer and Researcher
              “Sometimes it’s the people no one imagines anything of who do the things that no one can imagine.” - Alan Turing

              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