Defining Qt Quick Controls Styles as a seperate stylesheet
-
Hi all,
Is there any way we can define the "Qt Quick Controls Styles (http://qt-project.org/doc/qt-5.1/qtquickcontrolsstyles/qtquickcontrolsstyles-index.html), as a new stylesheet (for example, style.qml) and
use this stylesheet(style.qml) in other QML files.Best Regards,
Ansif -
Hi,
the answer is YES; you can define custom styles as Components and use them like other custom components.
-
[quote author="mcosta" date="1385569765"]Hi,
the answer is YES; you can define custom styles as Components and use them like other custom components.[/quote]
Thank you for your reply. Can you show me a small example.
-
Hi,
simply you have to:
create a QML file for each style (MyButtonStyle, MySliderStyle, ....)
for each control you set the style Property
example
@
// File: MyButtonStyle.qmlimport QtQuick 2.1
import QtQuick.Controls.Styles 1.0ButtonStyle {
....
}
@@
// File: main.qmlimport QtQuick 2.1
import QtQuick.Controls 1.0Rectangle {
Column {
Button { id: button1 ... style: MyButtonStyle {} } Button { id: button2 ... style: MyButtonStyle {} }
}
@ -
[quote author="mcosta" date="1385650066"]Hi,
simply you have to:
create a QML file for each style (MyButtonStyle, MySliderStyle, ....)
for each control you set the style Property
example
@
// File: MyButtonStyle.qmlimport QtQuick 2.1
import QtQuick.Controls.Styles 1.0ButtonStyle {
....
}
@@
// File: main.qmlimport QtQuick 2.1
import QtQuick.Controls 1.0Rectangle {
Column {
Button { id: button1 ... style: MyButtonStyle {} } Button { id: button2 ... style: MyButtonStyle {} }
}
@[/quote]Hi,
Great.. Thanks for your help. Actually i was looking for a common file (example: style.qml ) which can include the whole styles like Buttonstyle, Editbox style, RadioButton style and so on. By importing the style.qml, we
can use the individual styles for each controls. -
Hi,
you can't use a single file for all styles; you need a file for Component (Style).
Also you can read "here":http://qt-project.org/doc/qt-5.1/qtqml/qtqml-modules-topic.html to learn how to create a QML Module
-
[quote author="mcosta" date="1385715893"]Hi,
you can't use a single file for all styles; you need a file for Component (Style).
Also you can read "here":http://qt-project.org/doc/qt-5.1/qtqml/qtqml-modules-topic.html to learn how to create a QML Module[/quote]
Hi,
I have checked the QML module technique. Its a good idea to use the qmldir to include all styles in a single module.
Thank you for your help..
Best Regards
Ansif