Opened 9 years ago
Closed 9 years ago
#398 closed defect (fixed)
Command-line loses focus when clicking toolbar button
Reported by: | Tom Goddard | Owned by: | Tom Goddard |
---|---|---|---|
Priority: | major | Milestone: | |
Component: | Window Toolkit | Version: | |
Keywords: | Cc: | pett@… | |
Blocked By: | Blocking: | ||
Notify when closed: | Platform: | all | |
Project: | ChimeraX |
Description
In Qt, clicking any toolbar button, e.g. background color gray, makes subsequent key press events not go to the command-line. Have to click back into the command-line or graphics window to type a command. Also clicking a file history panel thumbnail also steals the focus.
Change History (2)
comment:1 by , 9 years ago
comment:2 by , 9 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Fixed.
I made the top level ChimeraX window forward keystrokes to the command-line if the focus widget is None.
Note:
See TracTickets
for help on using tickets.
Partially fixed. The trouble was that the log stole the focus whenever any new text was written to the log, for instance, when a command was executed. This is QTBUG-52999. I put in a work-around that disables the log QWebEngineView, change the html, then reenables. This avoids the widget taking the focus. With this fix, if the command-line has the focus, then clicking toolbar icons does not change the focus.
After clicking the graphics window the QApplication.focusChanged signal indicates the focus becomes None. But keystrokes do get forwarded to the command-line (in ui/gui.py the graphics_window.keyPressEvent handler is set to achieve this). After clicking a toolbar icon the forwarding no longer happens although no focus change is reported. The graphics window is a QWindow (native OS window) rather than a QWidget, which is probably why Qt reports the focus widget as None. Maybe the keys get forwarded only because the native Mac window has focus, and clicking on the toolbar causes another native mac window to get the focus and Qt doesn't know to restore the focus to the graphics window because it thinks the focus is None.
Clicking the file history panel gives it the focus and then keys are not forwarded to the command-line. the setFocusPolicy(NoFocus) call on the QWebEngineView and ToolWindow ui_area and QDockWidget did not prevent it from taking focus. I tried making ui/gui.py MainWindow also redirect keys to the command-line. This had the bad effect that pressing Enter in the command-line or in the volume viewer level entry field passed the Enter key event to the MainWindow and handed it to the command-line. If the focus was in the command-line this caused the command to be run twice. If the focus was in the volume view level entry field, it executed the current command in the command-line. I could make the file history forward key strokes to the command-line by setting its keyPressEvent. Ick.
Clicking in the log panel also prevents key forwarding to the command-line, just like file history.