Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Give focus to dialog invoked from outside of the application
Forum Updated to NodeBB v4.3 + New Features

Give focus to dialog invoked from outside of the application

Scheduled Pinned Locked Moved Unsolved General and Desktop
10 Posts 3 Posters 2.9k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • IshMI Offline
    IshMI Offline
    IshM
    wrote on last edited by
    #1

    I have a hardware controller which can send events to my application. Now when I press the button, a dialog box shows up with some input fields. I want to give keyboard focus to the dialog so that the user can enter data without having to activate the dialog box by clicking it. I have tried several things including different Qt flags but it doesn't seem to work on Windows. The dialog box just flashes in the taskbar. I have tried native windows calls as well to no luck. Any help will be appreciated.

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      Quick check. Have tried windowsontophint or modality flags ?

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      IshMI 1 Reply Last reply
      3
      • dheerendraD dheerendra

        Quick check. Have tried windowsontophint or modality flags ?

        IshMI Offline
        IshMI Offline
        IshM
        wrote on last edited by
        #3

        @dheerendra I am using these flags Qt::WindowFlags flags = Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint;. I have tried modality too but doesn't seem to work.

        1 Reply Last reply
        0
        • R Offline
          R Offline
          Rondog
          wrote on last edited by
          #4

          If you are getting events from an external source I don't see why something like setFocus() wouldn't work. You might need to do a few things prior to this so that the setFocus() command isn't ignored (the dialog must be visible and not minimized for example).

          I think playing around with the window modal flags is probably not the best idea. I don't know about you but I hate it when a dialog pop's up ontop of everything else and all you can do is move it off to one side of the screen (or close it).

          1 Reply Last reply
          0
          • IshMI Offline
            IshMI Offline
            IshM
            wrote on last edited by
            #5

            @Rondog Could you provide me with some more information about what should I be doing to get setFocus to work properly. I am showing the dialog before hand and it's not minimized.

            I agree with you about the dialogs popping up, but this is related to physical controller which shows some feedback when pressed and gives you ability to enter info. So I think it might not be as obstructing since it's being shown when the user actually expects it.

            1 Reply Last reply
            0
            • R Offline
              R Offline
              Rondog
              wrote on last edited by
              #6

              I have a program I ran a test with. It uses a named pipe that a second program can send data through (the original idea was to synchronize programs). I modified it so that the program receiving the data automatically set focus on one of the QLineEdit's. Basically trying to recreate what you described (I hope) except I am not working in the QEvents.

              void TMyDialog::Make_This_In_Focus(void)
              {
              	if(this->isHidden())	// must be visible
              	{
              		this->show();
              	}
              	
              	if(this->isMinimized())	// cannot be minimized
              	{
              		this->showNormal();
              	}
              	
              	d_measurement_description_edit->setFocus();	// QLineEdit that I want to focus on
              	
              	this->raise();	// move this widget to the top of the Z order.  This sets the widget 'in focus' or active.
              }
              

              I didn't try any of this on Windows but I don't see why it wouldn't work.

              1 Reply Last reply
              1
              • IshMI Offline
                IshMI Offline
                IshM
                wrote on last edited by
                #7

                @Rondog Thanks for this. One last issue with this will be that when I call raise() it brings the other application windows on the top as well. Is there a way to not do that and just bring the dialog in focus while not making other app window active?

                1 Reply Last reply
                0
                • R Offline
                  R Offline
                  Rondog
                  wrote on last edited by
                  #8

                  I took a second look at the documentation. Maybe 'activateWindow()' is a better option than 'raise()' (?).

                  I am not clear on what you mean by your comment ("...other application windows on top as well..."). The idea is to move the window of interest to the top of the Z order so all other windows must fall behind it. I can't picture this bringing other application windows to the top along with the one you want to have active. I probably don't understand what you are describing.

                  If the other window that moves to the top is the one that that creates the signal for the target window (the one you want to have focus) then how are they connected together? When I tried my test I was using a named pipe so the programs were very separate and it worked well.

                  1 Reply Last reply
                  0
                  • IshMI Offline
                    IshMI Offline
                    IshM
                    wrote on last edited by
                    #9

                    @Rondog Sorry for the confusion. I have a main application window and then I have this dialog which I want to show/give focus to. After call to raise() is made, both the application window and the dialog come to the top, i.e., in front of other apps with the focus given to the dialog. I am looking for a way to just raise the dialog box and keep the application where it was in the z-order. Hope this explains it.

                    1 Reply Last reply
                    0
                    • R Offline
                      R Offline
                      Rondog
                      wrote on last edited by
                      #10

                      Hmmm. Got it.

                      I am not sure if this is possible. If the dialog was created as a child of the parent window the two might always be attached to each other. If you can get the dialog to be on top with other programs between the dialog and the main window (i.e. Z order = dialog, something_else, something_else, main_window) then it might be possible. If you can't do this by using some method like the mouse then you won't be able to do this using setFocus().

                      If the dialog was not a child of the other window this might help (but can create new problems).

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved