component loaded but is not shown in window
-
So I created my custom component and loaded it as a plugin. It is also constructed, since I get a qInfo() from the constructor. However, it does not show on the window.
As stated in the documentation, you should override the paint() function, which I did. However, it seems this is never called. When should this be called, and what could a reason be that it never is called?
My code looks as following:
mycustombuttonnew.qml(The plugin):import QtQuick 6.6 import QtQuick.Controls import QtQuick.Controls.Material Item { id: button Material.background: Material.Red width: button.getWidth() height: button.getHeight() objectName: "MyCustomButton" Text { id: name text: button.name // Bind to the parent's text property color: "black" anchors.centerIn: button // Center text within the button objectName: "MyCustomButtonText" } MouseArea { id: mouseArea anchors.fill: button onClicked: { button.buttonClicked() } objectName: "MyCustomButtonMouseArea" } }Then I include this custom component/plugin inside the mainwindow.qml:
import QtQuick 6.6 import plugins.MyCustomButtonNew import QtQuick.Controls.Material Window { visible: true Item { width: 1920; height: 1080 objectName: "root item" MyCustomButtonNew { id: button Material.background: Material.Red name: "test" objectName: "MyCustomButton" } } }My main is as following:
int main(int argc, char *argv[]) { QApplication a(argc, argv); QQmlApplicationEngine engine; QWindow window; const QUrl url = QUrl::fromLocalFile("mainwindow.qml"); QObject::connect( &engine, &QQmlApplicationEngine::objectCreated, &a, [url](QObject *obj, const QUrl &objUrl) { if (!obj && url == objUrl) QCoreApplication::exit(-1); }, Qt::QueuedConnection); engine.load(url); QQuickView view = QQuickView(&engine, &window); view.setResizeMode(QQuickView::SizeRootObjectToView); view.show(); return a.exec();Any help to make me understand this better would be appriciated :).
-
So I created my custom component and loaded it as a plugin. It is also constructed, since I get a qInfo() from the constructor. However, it does not show on the window.
As stated in the documentation, you should override the paint() function, which I did. However, it seems this is never called. When should this be called, and what could a reason be that it never is called?
My code looks as following:
mycustombuttonnew.qml(The plugin):import QtQuick 6.6 import QtQuick.Controls import QtQuick.Controls.Material Item { id: button Material.background: Material.Red width: button.getWidth() height: button.getHeight() objectName: "MyCustomButton" Text { id: name text: button.name // Bind to the parent's text property color: "black" anchors.centerIn: button // Center text within the button objectName: "MyCustomButtonText" } MouseArea { id: mouseArea anchors.fill: button onClicked: { button.buttonClicked() } objectName: "MyCustomButtonMouseArea" } }Then I include this custom component/plugin inside the mainwindow.qml:
import QtQuick 6.6 import plugins.MyCustomButtonNew import QtQuick.Controls.Material Window { visible: true Item { width: 1920; height: 1080 objectName: "root item" MyCustomButtonNew { id: button Material.background: Material.Red name: "test" objectName: "MyCustomButton" } } }My main is as following:
int main(int argc, char *argv[]) { QApplication a(argc, argv); QQmlApplicationEngine engine; QWindow window; const QUrl url = QUrl::fromLocalFile("mainwindow.qml"); QObject::connect( &engine, &QQmlApplicationEngine::objectCreated, &a, [url](QObject *obj, const QUrl &objUrl) { if (!obj && url == objUrl) QCoreApplication::exit(-1); }, Qt::QueuedConnection); engine.load(url); QQuickView view = QQuickView(&engine, &window); view.setResizeMode(QQuickView::SizeRootObjectToView); view.show(); return a.exec();Any help to make me understand this better would be appriciated :).
@Mighty_Pig What if you set a width and height on the Window?