[Interest] Change Menu background

Doris Verria doris.verria at qt.io
Thu Oct 3 17:10:41 CEST 2024


Hi Alexander,

The background will automatically follow the controls size. However, the control uses the implicit size of the background or the content size (whichever is bigger) to calculate its implicit size.
So if the menu has no contentWidth/Height set and you don’t provide an implicit size for the background, the menu itself will have a 0x0 size. To avoid that, you should try either setting the contentWidth or give an implicit size to the background.

Note that most styles set the contentItem of the Menu to be a ListView. According to the documentation, a vertical ListView only estimates the contentHeight, and a horizontal ListView only estimates the contentWidth, while the other dimension is set to -1, so it is up to the application to explicitly set these.

Regards,
Doris Verria

From: Interest <interest-bounces at qt-project.org> on behalf of Alexander Dyagilev <alervdvcw at gmail.com>
Date: Thursday, 3 October 2024 at 2:47 PM
To: Qt Project <interest at qt-project.org>
Subject: [Interest] Change Menu background
Hello,

I'm using Qt 6.6.3.

I'm trying to customize menu.

I've created the following component:

Menu
{
    background: Rectangle {
        color: "green"
    }
}

Now my menu just does not show up. I believe it's because its size is (0,0) now.

Where am I wrong? In Qt docs it's stated, that background follows its parent's size.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20241003/d09358d6/attachment.htm>


More information about the Interest mailing list