problem setFocus() in ui object
-
Hi , I'm trying to focus on an object in a " ui" from another " ui" but I'm not making. Use qt 4.8.
pressed a button to focus on another button in the same ui with this code and works
Touchpad::Touchpad(QWidget *parent) : QWidget(parent) { ui.setupUi(this); connect(ui.Enfocar, SIGNAL(clicked()), ui.Cerrar, SLOT(setFocus())); }
try to focus to a widget from another ui with this code but not work
Touchpad::Touchpad(QWidget *parent) : QWidget(parent) { ui.setupUi(this); connect(ui.Enfocar, SIGNAL(clicked()), MainWindow::ui.nameCombo, SLOT(setFocus())); }
the object you want to focus is a QComboBox , objetname " NameCombo ". this in a "ui " file.
that belongs to "MainWindow"Creation Time Description Resource Path Location Type 1451276551538 'MainWindow' has not been declared touchpad.cpp /stylesheet line 17 C/C++ Problem
-
Hi,
You can't access a private members of another class that way. If you really want to call setFocus in MainWindow's GUI, add a signal to Touchpad that will tell that you clicked ui.Enfocar and in MainWindow, add a slot that will call setFocus on NameCombo.
-
Press the button and nothing happens. if not misunderstood
in touchpad.h add:
signals: void hacer_foco(); //and private slots: void Enfocando();
in touchpad.cpp add:
//within Touchpad::Touchpad(QWidget *parent) connect(ui.Enfocar, SIGNAL(clicked()), this, SLOT(Enfocando())); //out of Touchpad::Touchpad(QWidget *parent) void Touchpad::Enfocando() { emit hacer_foco(); }
in mainwindows.h add
public slots: void hacer_foco();
and finally in mainwindow.cpp add
void Pantalla::hacer_foco() { ui.nameCombo->setFocus(); }
I try to do:
http://fotos.subefotos.com/21174ccca02c09ccbeb2a04877425f45o.jpg -
Are you trying to implement a virtual keyboard ?
-
Yes, but that's for later. I have a bluetooth keyboard. so I leave it to the end.
-
Meaning that you are putting that feature on hold ?