PDA

View Full Version : Check FOCUS-status on Multiple Windows(sub-forms)



2lights
15th January 2014, 12:44
Good Day,

I have created a mainWindow with a button to create a new sub-form.
This sub-form can be created multiple times depending on how many times the push button was clicked.
and each sub-form loads a user specified image.



#include <QMainWindow>
#include "miniFormClass.h"

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
Q_OBJECT

public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();

private:
Ui::MainWindow *ui;
miniFormClass* msWindow;
...


and


//On Push Button clicked
msWindow = new miniFormClass(this);
msWindow->show();
msWindow->callDialogUploadImage();



My Problem:
I need a way of keeping track which sub-form has focus, and I need to access certain member variables from that sub-form only, ignoring the other sub-forms until the user changes focus to another sub-form

Whats the way forward...
Thanks in advance

anda_skoa
15th January 2014, 13:01
You could keep the windows in a list or map so you can always access any of them.

The focus tracking could either be done by the sub windows and signalled to the main window or through an event filter.

Cheers,
_

stampede
15th January 2014, 13:14
You can use QApplication::focusWidget() method to get, well, current focus widget:) qobject_cast returned QWidget pointer to miniFormClass for conversion.
Another way could be to connect to QApplication::focusChanged signal, or install event filter on created objects and watch for FocusIn events.

I need to access certain member variables from that sub-form only, ignoring the other sub-forms until the user changes focus to another sub-form
Different design could include notifying the mainwindow about sub-window actions via signals, so maybe you don't really need access to current focus widget.

2lights
15th January 2014, 13:14
Thanks

Though, How do I create a List of Windows :confused:
Also in the sub window, where do I check to see its status (How do I create a slot on a "window" to see if focus == true);

If possible provide me with an example or link to a similar example

Kind Regards

anda_skoa
15th January 2014, 16:01
Though, How do I create a List of Windows :confused:




QList<miniFormClass*> windows;




Also in the sub window, where do I check to see its status (How do I create a slot on a "window" to see if focus == true);

Windows don't have focus, individual input widgets do.
See stampede's suggestion of connecting to the application's focusChanged() signal.

Cheers,
_

2lights
16th January 2014, 08:21
Apologies for the late reply....

this is what i need...

From the sub-window created when a button is pressed(Creating several sub-windows based on number of times Button is pressed)
I Added a check-box on the subwindow
That when checked it should emit a signal to the main window(Signifying focus status).
Creating the signal is no problem

I have a problem defining the SLOT


//this is in the main Window .cpp
//The signal is emited from a sub-window (the sub-window is only created when button is pressed)
connect(this, SIGNAL(checked()), this, SLOT(doSomething));
error


How do i create the slot in mainWindow to pick up the signal from sub-window
//will pass certain variables from sub-window to main-window via the signal and slot mechanism

Many thanks