سؤال

I am trying to write a small app that has dark background. To make life easier i make use of Qt quick controls.

For example the ToolButton. When not-pressed the ToolButton has a black font so it is NOT visible on my dark background.

Reading other posts it seems (although hard to believe) that you can NOT set the text color (or other colors for that matter) for ToolButton or many other of the Qt quick controls. The solution suggested is complete copy / paste recoding of those elements and / or the styles. This sounds very dim of Qt / Digia and its hard to believe as the FIRST thing you want to "customize" is the colors (fore- back- text- active- inactive and so on...).

So is there any other way of app-wide change of those colors ? In Qt widgets i would modify the QApplication::QPallette and things are done in a few lines.

Please help me out !

Nils

هل كانت مفيدة؟

المحلول

Did you actually try? Where did you read that it was not possible? I've not done much with palettes, but searching "palette qt 5.2" gave me SystemPalette as the second result, and it's been around since Qt 4.7. The properties are read-only, so the intention must be that you set the palette in C++.

A "complete copy/paste" of the controls/styles is not necessary, even without using SystemPalette:

import QtQuick 2.2
import QtQuick.Controls 1.1
import QtQuick.Controls.Styles 1.1

Rectangle {
    width: 400
    height: 400
    color: "#444"

    ToolButton {
        text: "Button"
        style: ButtonStyle {
            label: Text {
                color: "red"
                text: control.text
            }
        }
    }
}

If you want to reuse a style for several controls, just create a component out of it, either as a property or in its own QML file.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top