Fix Qt6 menus randomly not displaying#623
Open
Cordtus wants to merge 3 commits intobgrabitmap:masterfrom
Open
Conversation
When building with Qt6 widgetset, menus would randomly fail to appear in the main menu bar. The "Image" menu was particularly affected, but other menus could also be missing on any given launch (roughly 30-70% failure rate across multiple launches). Root causes and fixes: 1. ActionByName issues: TActionList.ActionByName appears to have race condition issues with Qt6 during early initialization. Replaced with FindActionByNameDirect helper that directly iterates ActionList.Actions. 2. Menu visibility: Qt6 sometimes fails to display TMenuItems even when they're correctly populated. Added explicit Visible:=true for used menus. 3. Menu bar refresh: Qt6 widget handle needed forced refresh after menu population. Added Menu detach/reattach with ProcessMessages calls to force Qt6 to rebuild the menu bar widget. Tested on Arch Linux with qt6pas 6.2.9, FPC 3.2.2, Lazarus 3.8.
Author
|
Upon further testing there are some issues this has created.
|
7dc14a0 to
adb1d52
Compare
- Only run the menu rebuild workaround on Qt5/Qt6 widgetsets - GTK and Win32 users no longer execute this code path - Reduce ProcessMessages calls from 2 to 1
uimageview.pas: - Keep IMAGEVIEW_DIRECTUPDATE disabled for Qt6 (bypasses Qt paint system) - Enable IMAGEVIEW_QUICKUPDATE for Qt6 (forces immediate repaint) - This fixes slow mouse wheel zoom and invisible paintbrush cursor lazpaintmainform.pas: - More aggressive Qt6 menu rebuild: toggle visibility on all menu items - Add HandleNeeded call to force menu bar widget creation - Multiple ProcessMessages calls to ensure Qt6 fully processes changes Tested on Arch Linux with qt6pas 6.2.9, FPC 3.2.2, Lazarus 3.8. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #624
Problem
When building LazPaint with Qt6 widgetset (
--ws=qt6), menus would randomly fail to appear in the main menu bar. The "Image" menu was particularly affected, but other menus could also be missing on any given launch (roughly 30-70% failure rate across multiple launches).This issue was tested and reproduced on Arch Linux with qt6pas 6.2.9, FPC 3.2.2, and Lazarus 3.8.
Root Causes and Fixes
1. TActionList.ActionByName race condition with Qt6
During early initialization,
TActionList.ActionByNameappears to have timing issues with Qt6 that cause it to fail to find actions that are actually present. Debug logging confirmed all 177 actions were loaded, but ActionByName would sometimes return nil.Fix: Added
FindActionByNameDirecthelper function that iterates directly overActionList.Actions[]instead of using the hash-based lookup.2. Menu visibility not explicitly set
Qt6 sometimes fails to display TMenuItems even when they're correctly populated with all their child items.
Fix: Added explicit
Visible := truefor all used menus in the Apply procedure.3. Main menu bar widget needs refresh
Even with correct menu data, Qt6's main menu bar widget wouldn't always render all items.
Fix: Added menu detach/reattach sequence with
ProcessMessagescalls after menu population to force Qt6 to rebuild the menu bar widget:Self.Menu := nil; Application.ProcessMessages; Self.Menu := MainMenu1; Application.ProcessMessages;Testing
Before this fix: 2/6 launches had the Image menu (~33% success rate)
After this fix: 6/6 launches had the Image menu (100% success rate)
The fix has been tested repeatedly with consistent results.
Changes
lazpaint/umenu.pas: AddedFindActionByNameDirecthelper, replacedActionByNamecalls, added explicit visibility settinglazpaint/lazpaintmainform.pas: Added menu bar refresh afterm.Apply