Bug 445033

Summary: Button content is always centered when button is forced to be wider than its implicit width
Product: [Frameworks and Libraries] frameworks-qqc2-desktop-style Reporter: Nate Graham <nate>
Component: generalAssignee: Marco Martin <notmart>
Status: RESOLVED INTENTIONAL    
Severity: normal CC: ahiemstra, kde, noahadvs
Priority: NOR    
Version: unspecified   
Target Milestone: ---   
Platform: Other   
OS: Linux   
Latest Commit: Version Fixed In:
Attachments: Ugly centered content

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.