Results 1 to 6 of 6

Thread: Check FOCUS-status on Multiple Windows(sub-forms)

  1. #1
    Join Date
    Jun 2013
    Posts
    46
    Thanks
    24
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Windows

    Question Check FOCUS-status on Multiple Windows(sub-forms)

    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.

    Qt Code:
    1. #include <QMainWindow>
    2. #include "miniFormClass.h"
    3.  
    4. namespace Ui {
    5. class MainWindow;
    6. }
    7.  
    8. class MainWindow : public QMainWindow
    9. {
    10. Q_OBJECT
    11.  
    12. public:
    13. explicit MainWindow(QWidget *parent = 0);
    14. ~MainWindow();
    15.  
    16. private:
    17. Ui::MainWindow *ui;
    18. miniFormClass* msWindow;
    19. ...
    To copy to clipboard, switch view to plain text mode 

    and
    Qt Code:
    1. //On Push Button clicked
    2. msWindow = new miniFormClass(this);
    3. msWindow->show();
    4. msWindow->callDialogUploadImage();
    To copy to clipboard, switch view to plain text mode 


    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

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Check FOCUS-status on Multiple Windows(sub-forms)

    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,
    _

  3. #3
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Check FOCUS-status on Multiple Windows(sub-forms)

    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.

  4. #4
    Join Date
    Jun 2013
    Posts
    46
    Thanks
    24
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Windows

    Default Re: Check FOCUS-status on Multiple Windows(sub-forms)

    Thanks

    Though, How do I create a List of 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);

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

    Kind Regards

  5. #5
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Check FOCUS-status on Multiple Windows(sub-forms)

    Quote Originally Posted by 2lights View Post
    Though, How do I create a List of Windows
    Qt Code:
    1. QList<miniFormClass*> windows;
    To copy to clipboard, switch view to plain text mode 

    Quote Originally Posted by 2lights View Post
    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,
    _

  6. The following user says thank you to anda_skoa for this useful post:

    2lights (16th January 2014)

  7. #6
    Join Date
    Jun 2013
    Posts
    46
    Thanks
    24
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Windows

    Exclamation Re: Check FOCUS-status on Multiple Windows(sub-forms)

    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
    Qt Code:
    1. //this is in the main Window .cpp
    2. //The signal is emited from a sub-window (the sub-window is only created when button is pressed)
    3. connect(this, SIGNAL(checked()), this, SLOT(doSomething));
    4. error
    To copy to clipboard, switch view to plain text mode 

    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
    Last edited by 2lights; 16th January 2014 at 08:26.

Similar Threads

  1. bool check status from subclass
    By ebsaith in forum Newbie
    Replies: 1
    Last Post: 18th June 2013, 12:54
  2. Can Qt check current audio status?
    By bizmopeen in forum Qt Programming
    Replies: 3
    Last Post: 5th November 2010, 02:58
  3. Multiple Forms and vertical layout in forms
    By eva2002 in forum Qt Programming
    Replies: 0
    Last Post: 13th January 2010, 05:05
  4. How to check COM port status?
    By rajesh in forum Qt Programming
    Replies: 1
    Last Post: 2nd December 2009, 17:07
  5. How to check the current status of a service
    By Ankitha Varsha in forum Qt Programming
    Replies: 1
    Last Post: 21st October 2008, 12:55

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.