Combobox -
-
why is the combobox not have text in black?
https://prntscr.com/k1zegz -
@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?
-
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) } } }
-
@123456789 Did you try to select an item in the combo box?
-
@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 casetextRole: "text"
can solve your problem of visibility
https://doc.qt.io/qt-5.11/qml-qtquick-controls2-combobox.html#textRole-prop