[Interest] Can QML model specify a range including negative numbers? For example -180 to +180 ?
Edward Sutton
edward.sutton at subsite.com
Wed Nov 4 18:27:28 CET 2015
Thanks guys! This works!
File: main.qml
import QtQuick 2.2
import QtGraphicalEffects 1.0
import QtQuick.Controls 1.4
import QtQuick.Controls.Styles 1.4
import QtQuick.Dialogs 1.0
import QtQuick.Extras 1.4
import QtQuick.Layouts 1.0
import QtQuick.Window 2.1
Rectangle {
id: rectangle
color: "red"
width: 200
height: 200
Tumbler {
objectName: "lat"
// latitude degrees -180 to +180
TumblerColumn {
model: ListModel {
Component.onCompleted: {
for (var i = -180; i <= 180; ++i) {
append({value: i.toString()});
}
}
}
}
// latitude minutes 0 - 59
TumblerColumn {
model: 60
}
// latitude seconds 0 - 59
TumblerColumn {
model: 60
}
}
}
I am a total QML newbie. I am currently copying QML source without understanding it, modify, then run and view results.
I am using the Qt 5.5 Tumbler from http://doc.qt.io/qt-5/qml-qtquick-extras-tumbler.html
I can set and get column indexes from C++ when I press a widget button.
void MainWindow::on_pushButtonSet_clicked()
{
QObject *objectRectangle = m_view->rootObject();
QObject *objectLatitude = objectRectangle->findChild<QObject*>("lat");
if (0 != objectLatitude)
{
// void setCurrentIndexAt(int columnIndex, int itemIndex)
for(int col = 0; col < 3; ++col)
{
QVariant columnIndex(col);
QMetaObject::invokeMethod(objectLatitude, "setCurrentIndexAt",
Q_ARG(QVariant, columnIndex),
Q_ARG(QVariant, 0));
}
}
}
void MainWindow::on_pushButtonGet_clicked()
{
QObject *objectRectangle = m_view->rootObject();
QObject *objectLatitude = objectRectangle->findChild<QObject*>("lat");
if (0 != objectLatitude)
{
// int currentIndexAt(int columnIndex)
for(int col = 0; col < 3; ++col)
{
QVariant returnedValue;
QVariant columnIndex(col);
QMetaObject::invokeMethod(objectLatitude, "currentIndexAt",
Q_RETURN_ARG(QVariant, returnedValue),
Q_ARG(QVariant, columnIndex));
qDebug() << "returnedValue: " << returnedValue.toString();
}
}
}
It works well on OS X except no-repaint issues when resizing mainwindow.
It does not display so well on Android and iOS devices. I will look at some of the Qt examples and hope to learn more. At this point C++ to QML interop seems to do what I need.
Thanks! QML is starting to look less intimidating and more usable.
-Ed
OS X
[cid:F664C66A-76C1-467A-8EFD-F6F1E9C6CCBC at ditchwitch.cmw.internal]
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
connect(ui->pushButton, SIGNAL(clicked()), qApp, SLOT(quit()));
m_view = new QQuickView();
QWidget *container = QWidget::createWindowContainer(m_view, this);
container->setMinimumSize(200, 200);
container->setMaximumSize(400, 400);
container->setFocusPolicy(Qt::TabFocus);
m_view->setSource(QUrl("qrc:/res/files/main.qml"));
ui->frame->layout()->addWidget(container);
QObject *objectRectangle = m_view->rootObject();
QVariant color = objectRectangle->property("color");
qDebug() << "color: " << color.toString();
objectRectangle->setProperty("color", "blue");
}
On Nov 4, 2015, at 9:17 AM, Jason H <jhihn at gmx.com<mailto:jhihn at gmx.com>> wrote:
You can just programmaticaly make a model.
Here is real code to make a list of 1 to 31 days for a date picker:
ListModel {
id: dayModel
}
//--- in Component.onCompleted: {
for (var i=1; i<32; i++)
dayModel.append({value: i, name: ''+i});
//--- }
Sent: Wednesday, November 04, 2015 at 9:53 AM
From: "Edward Sutton" <edward.sutton at subsite.com<mailto:edward.sutton at subsite.com>>
To: "Qt Interest" <interest at qt-project.org<mailto:interest at qt-project.org>>
Subject: [Interest] Can QML model specify a range including negative numbers? For example -180 to +180 ?
Is there a way to declare a QML model range from -180 to +180?
A method that does not require typing 361 numbers model: [-180, -179, … 0, … 179, 180 ] ?
I added a Tumbler to Combining Qt Widgets and QML with QWidget::createWindowContainer()<http://www.ics.com/blog/combining-qt-widgets-and-qml-qwidgetcreatewindowcontainer> to experiment with making QML readable and writable from C++.
Tumbler {
// latitude degrees -180 to +180
TumblerColumn {
model: 181 // <- Is there a way to declare model range -180 to +180 ?
}
// latitude minutes 0 - 59
TumblerColumn {
model: 60
}
// latitude seconds 0 - 59
TumblerColumn {
model: 60
}
}
Thanks in advance,
-Ed
This email and any files transmitted with it from The Charles Machine Works, Inc. are confidential and intended solely for the use of the individual or entity to which they are addressed. If you have received this email in error please notify the sender. Our company accepts no liability for the contents of this email, or for the consequences of any actions taken on the basis of the information provided, unless that information is subsequently confirmed in writing. Please note that any views or opinions presented in this email are solely those of the author and do not necessarily represent those of the company. Finally, the recipient should check this email and any attachments for the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email. _______________________________________________ Interest mailing list Interest at qt-project.org<mailto:Interest at qt-project.org> http://lists.qt-project.org/mailman/listinfo/interest
This email and any files transmitted with it from The Charles Machine Works, Inc. are confidential and intended solely for the use of the individual or entity to which they are addressed. If you have received this email in error please notify the sender. Our company accepts no liability for the contents of this email, or for the consequences of any actions taken on the basis of the information provided, unless that information is subsequently confirmed in writing. Please note that any views or opinions presented in this email are solely those of the author and do not necessarily represent those of the company. Finally, the recipient should check this email and any attachments for the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20151104/33d85867/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: PastedGraphic-4.png
Type: image/png
Size: 34846 bytes
Desc: PastedGraphic-4.png
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20151104/33d85867/attachment.png>
More information about the Interest
mailing list