Results 1 to 8 of 8

Thread: Finding the 'current' dialog

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2009
    Posts
    34
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Finding the 'current' dialog

    I have a QMainWindow with a toolbar with a toolbutton that I use to open a custom assistant for providing context relevant help to the user.

    This is a scenario I want to achieve: The user has opened several tools and is currently inputing a value into a spinbox, but wonders what this tool/dialog really does. He presses the questionmark on the main window's toolbar and gets the helpfile for the dialog he is using.

    Can someone help me find an elegant way of finding which dialog that currently has focus?

    I see that a spinbox in the current tool still has focus and I can get that by:
    Qt Code:
    1. QApplication::focusWidget();
    To copy to clipboard, switch view to plain text mode 
    If I try this:
    Qt Code:
    1. QApplication::focusWidget();
    To copy to clipboard, switch view to plain text mode 
    , I get the main window.

    I planned to get the current dialog and then use the objectName() to identify which helpfile to open.

    I see it as risky business to implement code in all dialogs to try to traverse up to the top parent for that dialog as you are not forced to provide the parent in a constructor. But if nothing else works, I will do that and rather show a default help file if the top dialog for that particular focus widget is not known.

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Finding the 'current' dialog

    Quote Originally Posted by zarkzervo View Post
    I see that a spinbox in the current tool still has focus and I can get that by:
    Qt Code:
    1. QApplication::focusWidget();
    To copy to clipboard, switch view to plain text mode 
    If this is always true - I don't know - you can use parent() till you reach the "QDialog" class and get its object name.

  3. #3
    Join Date
    Mar 2008
    Posts
    141
    Thanks
    10
    Thanked 9 Times in 9 Posts

    Default Re: Finding the 'current' dialog

    Hi,

    just an idea:
    maybe installing an eventfilter and checking the focus events might help.

  4. #4
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Finding the 'current' dialog

    Maybe use "What's this?"? It requires 1 more click: User clicks on what's this button and then clicks on the widget he want to get some info about and it appears in some kind of tooltip.
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

  5. #5
    Join Date
    Jan 2009
    Posts
    34
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Finding the 'current' dialog

    Thanks all.

    I went for this solution:
    After I created a tool that I wanted to have some help available for, I registered it in a central help object with its "parentPath" and the name of the helpfile I wanted to associate it with.

    The parentPath, I found by connecting the objectName() of all the ancestors. This key would uniqely identify the help file to open for that object. This allows for more detailed help files further down the hierarchy.

    When I wanted to open a help file, I simply used the focusWidget() widget and built the parentPath from that. I opened the helpfile with the longest parentPath that still fit with the parentPath:

    ":BOCS__Main::qt_workspacechild:ConfigureDlg:cmbB_ mode" would open the helpfile associated with ":BOCS__Main::qt_workspacechild:ConfigureDlg" and when I focus on a widget with more detailed help: ":BOCS__Main::qt_workspacechild:ConfigureDlg:split ter:groupBox_2:cmbB_stratType" it would open the file associated with ":BOCS__Main::qt_workspacechild:ConfigureDlg:split ter:groupBox_2:cmbB_stratType"

    It may not be the most elegant solution, but it works and would always come up with a helpfile as it traverses back up the ancestry tree until it would probably find some smaller file or just open the default helpfile for the application.

    One problem though: When you create a dialog and put it in the workspace, you automatically give away the ownership and the parentPath will change, e.g., the qt_workspacechild-part in my example. I therefore don't register the dialogs in their constructor, but rather call a registerHelp() after the dialog is shown.

    This opens for detailed help associated with a single widget anywhere in my system, e.g. a more elaborate help for my "execute"-button as well as automatically opening the most detailed help for a widget.

    There probably are endless problems that can occur, but as long as I'm aware of how it works, I can probably prevent most strange problems from happening.

  6. #6
    Join Date
    Jan 2009
    Posts
    34
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Finding the 'current' dialog

    Quote Originally Posted by faldżip View Post
    Maybe use "What's this?"? It requires 1 more click: User clicks on what's this button and then clicks on the widget he want to get some info about and it appears in some kind of tooltip.
    I just wanted to say that I use whatsThis already.

    I use the Qt Assistant system for more elaborate help and that allows for standard html files.

    IMHO, more programmers should use whatsThis. I often need a little bit of help in an application and pressing help in many applications just opens the root help file and you have to search for what you're after.

  7. #7
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Finding the 'current' dialog

    You could override WhatsThis event and show your custom help... cant you ?
    It wud be much simpler I guess

  8. #8
    Join Date
    Jan 2009
    Posts
    34
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Finding the 'current' dialog

    Personally, I don't think that is too smart as it would remove the main use of whatsThis and the user would expect something else than an elaborate help application from it.

    And as I already use the whatsThis for its original purpose, I couldn't really reassign the use.

Similar Threads

  1. Issue with Modelless dialog on Mac
    By Satyanarayana Chebrolu in forum Qt Programming
    Replies: 0
    Last Post: 24th February 2009, 10:10
  2. Qt designer plugin errors on OSX Leopard
    By mpotocnik in forum Qt Tools
    Replies: 10
    Last Post: 21st January 2008, 09:45
  3. Resizing the dialog boxes
    By anju123 in forum Qt Programming
    Replies: 4
    Last Post: 14th September 2007, 10:41
  4. Distributing QT application for Mac OS
    By mb0 in forum Qt Programming
    Replies: 1
    Last Post: 31st May 2007, 18:59
  5. Replies: 15
    Last Post: 21st April 2007, 17:46

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.