Buenas tardes.
Muchas gracias por su ayuda, tengo el sgte código QML el Login2, para ingresar al aplicativo:
ComboBox {
id: serverInput
width: 299
editable: true
model: theLogin.servers();
property var aString: theLogin.server();
property int servidorUltimo: find(aString);
onCurrentIndexChanged: console.debug(cbItems.get(currentIndex).text + ", " + cbItems.get(currentIndex).color)
Keys.onReturnPressed: conectarBoton.clicked(Qt.LeftButton);
Component.onCompleted: currentIndex = servidorUltimo;
}
Necesito que el combo donde ingreso servidor, cuando lo modifique tome los datos editados, y si la conexión es exitosa lo ingrese a la configuración del sistema, no sé cómo hacer por un lado el append en la lista del combo cuando sea nuevo el servidor, y como haría para ingresarlo a la configuración del equipo??
estisoft
([N4] estisoft)
16 Abril, 2023 12:27
2
Espero que te sirva.
import QtQuick 2.6
import QtQuick.Controls 2.15
import “auxiliares.js” as Aux
Rectangle
{
id: general
border.width: 1
border.color: “black”
width: 600
height: 500
//color: “blue”
//Imagen del logo de Velneo
Image {
id: logo
width: 480
height: 150
fillMode: Image.PreserveAspectFit
anchors.horizontalCenter: parent.horizontalCenter
source: "logo.png"
smooth: true;
asynchronous: true;
}//Imagen del logo de Velneo
//Servidores
Rectangle{
id: servidores
width: parent.width - 20
height: 50
anchors.top: logo.bottom
anchors.topMargin: 5
anchors.horizontalCenter: parent.horizontalCenter
// Modelo de coincidencias encontradas
ListModel
{
id: modeloServidores
}
//Cuando se ve un solo servidor (el seleccionado)
Rectangle{
id: cuadroUnServidor
width: parent.width
visible: true
Text{
id: textoServidor
text: theLogin.server();
color: "#A4A4A4"
font.pointSize: 13
anchors.horizontalCenter: parent.horizontalCenter
}
}//Cuando se ve un solo servidor (El seleccionado)
//Imagen del boton
Image {
id: botonImagen
width: 40
height: 40
fillMode: Image.PreserveAspectFit
anchors.right: parent.right
anchors.rightMargin: 100
source: "boton.png"
smooth: true;
asynchronous: true;
signal clicked;
MouseArea {
id: botonImagenRegion
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
anchors.fill: botonImagen
onClicked:
{
botonImagen.clicked();
}
}
onClicked:{
if( cuadroListaServidores.visible == false ){
servidores.height = 115;
cuadroListaServidores.visible = true;
cuadroUnServidor.visible = false;
botonImagenPlus.visible = true;
botonImagen.visible = false;
}else{
servidores.height = 50;
cuadroListaServidores.visible = false;
cuadroUnServidor.visible= true;
}
}
}//Imagen del boton
//Imagen del boton plus
Image {
id: botonImagenPlus
width: 40
height: 40
fillMode: Image.PreserveAspectFit
anchors.right: parent.right
anchors.rightMargin: 100
source: "plus.png"
smooth: true;
asynchronous: true;
visible: false
signal clicked;
MouseArea {
id: botonImagenPlusRegion
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
anchors.fill: botonImagenPlus
onClicked:
{
botonImagenPlus.clicked();
}
}
onClicked:{
cuadroServidor.visible = true;
cuadroListaServidores.visible = false;
}
}//Imagen del boton plus
//Cuando se ve la lista
Rectangle{
id: cuadroListaServidores
visible: false
width: 300
height: parent.height
anchors.horizontalCenter: servidores.horizontalCenter
border.color : "#6E6E6E"
border.width : 2
ListView
{
id: listaServidores
width: 290
y: parent.y + 2
height: parent.height - 5
anchors.horizontalCenter: cuadroListaServidores.horizontalCenter
clip: true
focus: true
//keyNavigationEnabled: true
model: modeloServidores;
highlight: highlightBar
highlightFollowsCurrentItem: true
headerPositioning: ListView.OverlayHeader
Component
{
id: highlightBar
Rectangle
{
z: 999
width: 200
height: 50
radius: 5
anchors.left: parent.left
anchors.right: parent.right
color: "#66CCFF"
opacity: 0.25
}
}
// Delegado de la lista
delegate: Rectangle
{
id: fila
width: 200
height:23
//height: model.visible ? 25 : 0
MouseArea
{
anchors.fill: parent
acceptedButtons: Qt.LeftButton | Qt.RightButton
onClicked:
{
theLogin.setServer(model.servidor)
textoServidor.text = model.servidor
botonImagenPlus.visible = false;
botonImagen.visible = true;
botonImagen.clicked()
//console.log("Selecciona server")
}
}
Text
{
anchors.fill: parent
maximumLineCount: 1
text: model.servidor
font.pointSize: 12
color: model.seleccionado? "#66CCFF": "#FFFFF"
opacity: seleccionado? 0.3 : 1
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
anchors.leftMargin: 30
}
}
Component.onCompleted:
{
Aux.getServidores(modeloServidores, theLogin.servers() )
}
}
}//Cuando se ve la lista
}//Servidores
//Servidor
Rectangle {
id: cuadroServidor
width: 300
height: 50
color: "white"
anchors.bottom: cuadroUsuario.top
anchors.bottomMargin: 5
anchors.horizontalCenter: parent.horizontalCenter
border.color : "#6E6E6E"
border.width : 2
visible: false
TextField {
id: servidor
width: parent.width - 10
font.pointSize: 13
anchors.fill: parent
anchors.margins: parent.border.width
placeholderText: "SERVIDOR"
selectByMouse: true
text: theLogin.server()
KeyNavigation.tab: usuario
Keys.onReturnPressed: botonAceptar.clicked(Qt.LeftButton)
}
}//Servidor
//Usuario
Rectangle {
id: cuadroUsuario
width: 300
height: 50
color: "white"
anchors.top: servidores.bottom
anchors.topMargin: 5
anchors.horizontalCenter: parent.horizontalCenter
border.color : "#6E6E6E"
border.width : 2
TextField {
id: usuario
width: parent.width - 10
font.pointSize: 13
anchors.fill: parent
anchors.margins: parent.border.width
placeholderText: "USUARIO"
selectByMouse: true
text: theLogin.user()
KeyNavigation.tab: clave
Keys.onReturnPressed: botonAceptar.clicked(Qt.LeftButton)
}
}//Usuario
//Clave
Rectangle {
id: cuadroClave
width: 300
height: 50
color: "white"
anchors.top: cuadroUsuario.bottom
anchors.topMargin: 2
anchors.horizontalCenter: parent.horizontalCenter
border.color : "#6E6E6E"
border.width : cuadroUsuario.border.width
TextField {
id: clave
width: parent.width - 10
font.pointSize: 13
anchors.fill: parent
anchors.margins: parent.border.width
placeholderText: "CONTRASEÑA"
selectByMouse: true
echoMode: TextInput.Password
KeyNavigation.tab: botonAceptar
Keys.onReturnPressed: botonAceptar.clicked(Qt.LeftButton)
}
}//Clave
//Botones
Rectangle {
id: cuadroBotones
width: 300
height: 50
color: "white"
anchors.top: cuadroClave.bottom
anchors.topMargin: 15
anchors.horizontalCenter: parent.horizontalCenter
//Boton aceptar
Rectangle{
id: botonAceptar
width: 145
height: 50
color: "#B7B7B7"
anchors.top: parent.top
anchors.bottom: parent.bottom
anchors.left: parent.left
border.color : "#6E6E6E"
border.width : cuadroUsuario.border.width
signal clicked;
Keys.onReturnPressed: botonAceptar.clicked(Qt.LeftButton)
MouseArea {
id: conectarRegion
anchors.fill: botonAceptar
onClicked:
{
botonAceptar.clicked();
}
}
Text {
id: conectarLabel
text: "Conectar"
anchors.verticalCenter: parent.verticalCenter
anchors.horizontalCenter: parent.horizontalCenter
font.pointSize: 13
color: "#0B0B0B"
anchors.centerIn: botonAceptar
}
onClicked:{
theLogin.setServer( theLogin.server() );
theLogin.setUser( usuario.text );
theLogin.setPassword( clave.text );
theLogin.accept();
mensajeError.text = theLogin.errorText()
cuadroErrores.visible = true;
if ( theLogin.errorText() )
{
if (theLogin.sslErrors().length>0)
{
theLogin.showDialogSslException();
}
}
}
}//Boton aceptar
//Boton cancelar
Rectangle{
id: botonCancelar
width: 145
height: 50
color: "#B7B7B7"
anchors.top: parent.top
anchors.bottom: parent.bottom
anchors.right: parent.right
border.color : "#6E6E6E"
border.width : cuadroUsuario.border.width
signal clicked;
MouseArea {
id: cancelarRegion
anchors.fill: botonCancelar
onClicked:
{
botonCancelar.clicked();
}
}
Text {
id: cancelarLabel
text: "Cancelar"
anchors.verticalCenter: parent.verticalCenter
anchors.horizontalCenter: parent.horizontalCenter
font.pointSize: 13
color: "#0B0B0B"
anchors.centerIn: botonCancelar
}
onClicked:{
theLogin.reject();
}
}//Boton cancelar
}//Botones
//Seccion de errores
Rectangle{
id: cuadroErrores
width: parent.width
height: 20
color: "white"
anchors.top: cuadroBotones.bottom
anchors.topMargin: 5
anchors.horizontalCenter: parent.horizontalCenter
visible: false
Text{
id: mensajeError
color: "red"
font.pointSize: 11
anchors.horizontalCenter: parent.horizontalCenter
text: ""
}
}//Seccion de errores
}