[Interest] Change Menu background

James DeLisle james.delisle at qt.io
Thu Oct 3 21:52:03 CEST 2024


Hey Alexander,

Nope, not a design flaw. Perfectly in keeping with QML design principles. Please see the following on how to customize Quick controls:
https://doc.qt.io/qt-6/qtquickcontrols-customize.html

Best,
James

From: Interest <interest-bounces at qt-project.org> on behalf of Alexander Dyagilev <alervdvcw at gmail.com>
Date: Thursday, October 3, 2024 at 11:22
To: Doris Verria <doris.verria at qt.io>
Cc: Qt Project <interest at qt-project.org>
Subject: Re: [Interest] Change Menu background
OK, Thank you for the response. I think it's a design flaw. Background is just a background. It should not determine anything.

I did not change any properties of the menu control except the background. So I was expecting it to just become green. :)

On Thu, Oct 3, 2024 at 10:10 PM Doris Verria <doris.verria at qt.io<mailto:doris.verria at qt.io>> wrote:
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<mailto:interest-bounces at qt-project.org>> on behalf of Alexander Dyagilev <alervdvcw at gmail.com<mailto:alervdvcw at gmail.com>>
Date: Thursday, 3 October 2024 at 2:47 PM
To: Qt Project <interest at qt-project.org<mailto: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/d11e04e4/attachment.htm>


More information about the Interest mailing list