I should set property of Material style at runtime, for example to change theme value (light/dark) when the user click on a defined button.
I have configured Material style with qtquickcontrols2.conf and its properties (theme, accent and primary). I can't import QtQuick.Controls.Materials 2.0 because I don't know, but I'm working on Ubuntu with QtCreator 4.0.2 and the QtQuick.Controls.Materials and QtQuick.Controls.Universal imports are not detected.
My goal is simply change theme of material style from light to dark and viceversa on runtime. How can I integrate this feature? Thanks in advice.
Best Regards
Daniele
I can't import QtQuick.Controls.Materials 2.0 because I don't know, but I'm working on Ubuntu with QtCreator 4.0.2 and the QtQuick.Controls.Materials and QtQuick.Controls.Universal imports are not detected.
You need at least Qt 5.7.0 in order to have the Qt Quick Controls 2.0 import available.
My goal is simply change theme of material style from light to dark and viceversa on runtime.
You switch the theme at runtime like this:
import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.Controls.Material 2.0
ApplicationWindow {
id: window
width: 200
height: 200
visible: true
Material.theme: themeSwitch.checked ? Material.Dark : Material.Light
Switch {
id: themeSwitch
text: "Dark"
anchors.centerIn: parent
}
}
Related
I wanna update namespaces of the old project all together.
Currently I use replace tool (Menu Edit => Replace).
For Example I replace
import QtQuick 2.0
with
import QtQuick 2.13
in project.
Is use replace tool the best way?
I'm pretty new to QtCreator, my issue is that I'm not able to see QML Custom Components.
For example if you import QtQuick.Controls 1.5 you see under QML types:
- Qt Quick - Controls.
So far I have created my personal set of components, here is the folder structure:
the components qmldir is done in that way:
# qmldir
module components
Header 1.0 Header.qml
Footer 1.0 Footer.qml
CentralPage 1.0 CentralPage.qml
GenericButton 1.0 GenericButton.qml
ProgressBarCustom 1.0 ProgressBarCustom.qml
than for example in the LandingPageFrom.ui.qml
import QtQuick 2.6
import QtQuick.Controls 1.5
import QtQuick.Layouts 1.3
import components 1.0 as Components
Components.CentralPage {
pageName: "landingPage"
id: landingPage
width: 800
height: 1056
property alias aButton: aButton
Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
}
And is compiling and showing fine but inside the Designer nothing is showing as aspected, I only see .qml that are in the same directory but not the ones in components directory:
this is what I have done in the .pro and in the main.cpp
QML_IMPORT_PATH += $$PWD/resources/common/ui
QML_DESIGNER_IMPORT_PATH += resources/common/ui
main.cpp
QQmlApplicationEngine engine;
engine.addImportPath("qrc:///ui");
engine.load(QUrl("qrc:///ui/main.qml"));
What is strange is that only the designer is not able to see the components, but the QML code is able, what I'm missing here?
Not sure if you already solved your issue, but try steps 4 and 5 here:
http://doc.qt.io/qtcreator/creator-qml-modules-with-plugins.html
That made it work for me, although I had some issues with the metainfo file. You can just use this guys metainfo file as an example(or look at the one the Qt docs referenced in the instructions above): https://forum.qt.io/topic/56207/how-to-load-custom-qml-controls-into-the-qml-designer/2
Just make sure you put the designer folder where your module qmldir is located and the metainfo file goes in there. Probably named components.metainfo judging by the module name, not sure if that matters.
I found the following JavaFx code on internet, but I dont know where to run it or what library I have to import. Please help me to understand..
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.shape.Rectangle;
import javafx.scene.paint.Color;
import javafx.animation.transition.PauseTransition;
import javafx.animation.transition.SequentialTransition;
import javafx.animation.Timeline;
var fillColor: Color.BLUE;
Stage {
title : "MyApp"
scene: Scene {
width: 400
height: 200
content: [
Rectangle {
x: 10, y: 10
width: 140, height: 90
fill: bind fillColor
}
]
}
}
There is no start method and extends Application class in the code.
Thanks in advance.
That is very old JavaFX script code. JavaFX Script and the system to run it are no longer supported by Oracle (and likely no longer distributed by them either).
Forget you ever saw the JavaFX Script code and the internet site which provided it. Do not try to understand the JavaFX Script code.
Instead, learn JavaFX using the Java language based on current resources for Java client technology (Java 8) at the Oracle Java site.
When I import qml from qrc (which place in different directory from ) it's compile and work fine.
But when Qt Creator don't recognize imported component and don't hightlight this.
This's code:
import QtQuick 2.0
import "qrc:/qml_libs/ApplicationContainer"
Item
{
id: root_object
width: 300
height: 200
ApplicationContainer {
width : parent.width
height: parent.height
}
}
#Aleus, your way of doing thing is little bit tricky. I can't find any information of such kind importing in official documentation (please, take a look at Importing statements in Qt 5.2, QML. Also, take a look at QML Best Practices: Coding Conventions
First of all, check weather your file ApplicationContainer really has no extension (I mean .qml)
To make QtCreator recognize imported component do next things:
Add your qml file to .pro file in section OTHER_FILES like this:
OTHER_FILES += qml_libs/ApplicationContainer
AND/OR place statement for importing whole directory to your qml file, like:
import "qml_libs" as MyLibs
...
MyLibs.ApplicationContainer { ... }
Hope it helps!
I'm using QtQuick2 of QT 5.1.1
When I try to include and use the QML Elem FileDialog like described here I just get Unkown component (M300)
If I hover over import QtQuick.Dialogs 1.0 it says "library at: OS-PATH/qml/QtQuick/Dialogs" but in this folder is only a DefaultFileDialog.qml some other stuff but no FileDialog.qml.
So is there any reason why my QT installation doesn't provide this QML type? How can I import it?
Thanks in advance.
have a look here, just ignore the error message. it works for me!
https://qt-project.org/doc/qt-5.1/qtquickdialogs/systemdialogs-filedialogs-qml.html
There is no "FileDialog.qml" at all in QtQuick since the FileDialog is implemented in C++ and exported to QML.
Make sure to
import QtQuick 2.0
import QtQuick.Dialogs 1.0
Last but not least, ignore the warning given by QT Creator. In my case, FileDialog works perfctly but QTCreator does not know about it.