Bug 445033 - Button content is always centered when button is forced to be wider than its implicit width
Summary: Button content is always centered when button is forced to be wider than its ...
Status: RESOLVED INTENTIONAL
Alias: None
Product: frameworks-qqc2-desktop-style
Classification: Frameworks and Libraries
Component: general (show other bugs)
Version: unspecified
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: Marco Martin
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-11-05 17:22 UTC by Nate Graham
Modified: 2021-12-05 04:08 UTC (History)
3 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
Ugly centered content (211.58 KB, image/png)
2021-11-05 17:22 UTC, Nate Graham
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Nate Graham 2021-11-05 17:22:36 UTC
Created attachment 143252 [details]
Ugly centered content

Consider the following code:


import QtQuick 2.15
import QtQuick.Controls 2.5 as QQC2
import QtQuick.Layouts 1.1

import org.kde.kirigami 2.5 as Kirigami

Item {
    implicitWidth: 400
    implicitHeight: 100

    QQC2.ToolBar {
        anchors.centerIn: parent
        width: 300
        contentItem: RowLayout {
            QQC2.ToolButton {
                icon.name: "go-previous-symbolic"
                text: "back"
                Layout.fillWidth: true
            }
            QQC2.ToolButton {
                icon.name: "application-menu"
            }
        }
    }
}


The "Back" toolbutton is intentionally wider than normal, but this results in its content being centered within the button, rather than left-aligned, which would look better here. See attached screenshot.

We have a use case for this in System Settings, for the subcategory header's back button. Using a standard toolbutton is nicer than the fake button we currently use, but porting to it exposes this problem.
Comment 1 Noah Davis 2021-12-04 20:38:24 UTC
RESOLVED INTENTIONAL because this is how buttons are supposed to work by default. The same is true for Qt Widget buttons and other QQC2 styles, including the Qt QQC2 styles. If you want different behavior, you should replace the `contentItem`.
Comment 2 Nate Graham 2021-12-05 04:08:49 UTC
Yeah, that's what I ended up doing.