QML + CSS
-
Hey guy, I'm looking for a suitable approach to declare styles for my qml layout.
I don't know whether there is any way to use some kind of CSS within qml.
So what can I do to realize something like that.I would create a qml file with several properties which I can import in my other qml files.
But is this really necessary ? -
So far i guess that is the way out.
-
I think you already referred to "this":http://developer.qt.nokia.com/wiki/QmlStyling ,i got an idea from that guide itself.
-
Hi Madoodia,
I think Schneidi do that :
Create a Js script called "Style.js" for example :
@function styleText( myText) {
myText.font.family= "Serif"
myText.font.italic= true
myText.font.pointSize= 6
}@
And in the qml file you want to use it :
@import QtQuick 2.2
import QtQuick.Window 2.1
import "Style.js" as StyleWindow {
visible: true
width: 360
height: 360MouseArea { anchors.fill: parent onClicked: { Qt.quit(); } } Text { id: text text: qsTr("Hello World") anchors.centerIn: parent Component.onCompleted: {Style.styleText(text);} }
}@
-
[quote author="Tomme" date="1406381356"]I'm not sure I understand you very well.
In pure QML you can't use CSS (I don't think so). Maybe are you working with a webview or a textedit or a QtQuickControl ?[/quote]Hello,
Here the "CSS span" property is used in QML Text item.
I think we can use the css directly in QML files.@import QtQuick 2.0
Rectangle {
width: 400; height: 400
Text { Text: "Hello <span style="font-size:24px">world</span>"; textFormat: Text.RichText}}@Regards
Ansif -
[quote author="Tomme" date="1406381356"]I'm not sure I understand you very well.
In pure QML you can't use CSS (I don't think so). Maybe are you working with a webview or a textedit or a QtQuickControl ?[/quote]Sorry it was a mistake form my side. I agreed with Tomme as we cannot use CSS in pure QML.
But chick this new Styling technique available in Qt 5.3, "QML Styling":http://qt-project.org/doc/qt-5/qtquickcontrolsstyles-index.htmlQML provides most of the features of CSS and javascript. Also check this "link":https://qt-project.org/wiki/QmlStyling.
-
Will this help you, "QML Rectangle custom border":http://stackoverflow.com/questions/16534489/qml-control-border-width-and-color-on-any-one-side-of-rectangle-element
-
Welcome. Glad to hear from you.
-
Does QML support CSS?
forum.qt.io/post/584878
appears to indicate that it does, yet this thread, and the existence ofgithub.com/Ableton/aqt-stylesheets
, indicate otherwise.