Placing the submit button qml layout bb10 - c++

I want to place the submit button below the colored box. What should I do to fix the layout?
Whenever I adjust the topPadding the whole covered box adjusts not the submit button
import bb.cascades 1.0
Page {
Container {
background: Color.create("#f9f7f2");
layout: StackLayout {}
// Container for holding the title
Container {
horizontalAlignment: HorizontalAlignment.Center
layout: DockLayout {}
ImageView {
horizontalAlignment: HorizontalAlignment.Fill
verticalAlignment: VerticalAlignment.Fill
imageSource: "asset:///images/navigation_bar.png"
}
Container {
horizontalAlignment: HorizontalAlignment.Right
rightPadding: 30
topPadding: 40
layout: DockLayout {}
ImageButton {
id: btnsettings
verticalAlignment: VerticalAlignment.Center
defaultImageSource: "asset:///images/navbar_icon_settings.png"
onClicked: {
// show settings page when the button is clicked
cppObj.onSettingsClicked();
}
}
}
}
Container {
topPadding: 20
leftPadding: 20
rightPadding: 20
bottomPadding: 20
background: Color.create("#F4E9E1");
horizontalAlignment: HorizontalAlignment.Fill
layout: StackLayout {}
Label {
verticalAlignment: VerticalAlignment.Center
horizontalAlignment: HorizontalAlignment.Left
text: "Add Projects"
textStyle {
// fontFamily: FontStyle.Default.Myriad
// fontSize: 36
color: Color.create("#60323C")
}
}
}
ScrollView {
scrollViewProperties {
scrollMode: ScrollMode.Vertical
}
Container {
verticalAlignment: VerticalAlignment.Center
horizontalAlignment: HorizontalAlignment.Center
Divider {}
Container {
rightPadding: 30
leftPadding: rightPadding
bottomPadding: 40
topPadding: 20
verticalAlignment: VerticalAlignment.Bottom
layout: DockLayout {}
ImageView {
horizontalAlignment: HorizontalAlignment.Center
verticalAlignment: VerticalAlignment.Center
topMargin: 40
imageSource: "asset:///images/create_project_frame.png"
}
Container {
horizontalAlignment: HorizontalAlignment.Center
leftPadding: 70
rightPadding: 70
topPadding: 60
Label {
horizontalAlignment: HorizontalAlignment.Center
verticalAlignment: VerticalAlignment.Center
text: qsTr("Create a Project")
}
}
Container {
leftPadding: 70
rightPadding: 70
topPadding: 150
TextField {
id: tfMemberName
input.submitKey: SubmitKey.Next
topPadding: 50
hintText: qsTr("project name")
}
}
Container {
rightPadding: 30
leftPadding: rightPadding
bottomPadding: 20
verticalAlignment: VerticalAlignment.Bottom
layout: DockLayout {}
ImageView {
horizontalAlignment: HorizontalAlignment.Center
verticalAlignment: VerticalAlignment.Center
topMargin: 40
imageSource: "asset:///images/add_member_frame.png"
}
Container {
horizontalAlignment: HorizontalAlignment.Center
leftPadding: 70
rightPadding: 70
topPadding: 60
Label {
horizontalAlignment: HorizontalAlignment.Center
verticalAlignment: VerticalAlignment.Center
text: qsTr("Add a Member")
}
}
Container {
leftPadding: 70
rightPadding: 70
topPadding: 150
TextField {
id: tfEmail
input.submitKey: SubmitKey.Next
topPadding: 40
hintText: qsTr("email address")
}
}
Container {
horizontalAlignment: HorizontalAlignment.Left
verticalAlignment: VerticalAlignment.Center
topPadding: 250
leftPadding: 180
layout: DockLayout {}
ImageButton {
id: btnaddmore
defaultImageSource: "asset:///images/button_add.png"
onClicked: {
controller.showProjectsPage(); /*var projectsPage = page.createObject();
navPane.push(projectsPage);*/
}
}
}
Container {
horizontalAlignment: HorizontalAlignment.Right
rightPadding: 250
topPadding: 310
Label {
horizontalAlignment: HorizontalAlignment.Right
text: qsTr("add more")
}
}
}
}
}
ImageButton {
id: btnsubmit
horizontalAlignment: HorizontalAlignment.Center
defaultImageSource: "asset:///images/button_submit.png"
}
}
}
/*actions: [
ActionItem {
title: qsTr ("Add Project")
imageSource: "asset:///images/actionbar_icon_add.png"
ActionBar.placement: ActionBarPlacement.OnBar
/*onTriggered: {
_projects.addProjects()
navigationPane.push(addProjects.createObject())
}
}
]*/
}
I want to achieve this look

If I got you right, this code
import bb.cascades 1.0
Page {
// [0]
Container {
background: Color.Gray
topPadding: 40
leftPadding: 20
rightPadding: leftPadding
bottomPadding: topPadding
layout: StackLayout {
}
// [1]
Container {
leftPadding: 40
rightPadding: leftPadding
background: Color.Red
maxHeight: 350
// [2]
Container {
layoutProperties: StackLayoutProperties {
spaceQuota: 1.5
}
Label {
horizontalAlignment: HorizontalAlignment.Center
text: "Add a Member"
}
TextField {
horizontalAlignment: HorizontalAlignment.Center
hintText: "email address"
}
} // [2]
Container {
layoutProperties: StackLayoutProperties {
spaceQuota: 1
}
horizontalAlignment: HorizontalAlignment.Center
Container {
layout: StackLayout {
orientation: LayoutOrientation.LeftToRight
}
Button {
text: "+"
}
Label {
verticalAlignment: VerticalAlignment.Center
text: "add more"
}
}
}
} //[1]
Button {
horizontalAlignment: HorizontalAlignment.Center
text: "Button submit"
}
} // [0]
}
will give you the following layout:
Simply replace Buttons with your custom ImageButtons

Related

How to display Popup of ComboBox above?

My custom ComboBox works is correctly, but I do not understand how to up popup with list of element above of combobox.
ComboBox {
id: pointsPositionComboBox
anchors.fill: parent
displayText: qsTr("Position point")
model: map.pointPositionModel
textRole: "name"
delegate: Row {
Rectangle {
id: delegateRect
width: pointsPositionRect.width - removePointRect.width
height: pointsPositionRect.height
color: {
if (!delegateRectMouseArea.containsMouse)
return "#25263C"
else if (delegateRectMouseArea.containsMouse
&& !delegateRectMouseArea.pressed) {
return "#5F8C6D"
} else if (delegateRectMouseArea.containsMouse
&& delegateRectMouseArea.pressed) {
return "#73AB84"
}
}
Text {
text: model.name
color: "white"
width: parent.width - removePointItem.width
font.pixelSize: pointsPositionComboBox.font.pixelSize
anchors.topMargin: pointsPositionRect.height / 3
anchors.left: parent.left
anchors.leftMargin: 5
}
MouseArea {
id: delegateRectMouseArea
anchors.fill: delegateRect
hoverEnabled: true
acceptedButtons: Qt.LeftButton
onClicked: {
if (hasUserMenuProperty.hasUserMenu()
&& !globalUserManager.hasAccessToPrivilege("controlMap"))
return
const latitude = model.position.latitude
const longitude = model.position.longitude
map.center.latitude = latitude
map.center.longitude = longitude
map.zoomLevel = model.zoomLevel
globalMapProperty.bearing = model.bearing
pointsPositionComboBox.popup.close()
}
}
}
Rectangle {
id: removePointRect
width: 30
height: 30
z: pointsPositionComboBox.z + 1
color: {
if (!removePointItemMouseArea.containsMouse)
return "#25263C"
else if (removePointItemMouseArea.containsMouse
&& !removePointItemMouseArea.pressed) {
return "#73A081"
} else if (removePointItemMouseArea.containsMouse
&& removePointItemMouseArea.pressed) {
return "#52785E"
}
}
Image {
id: removePointItem
anchors.centerIn: parent
source: removePointItemMouseArea.containsMouse ? "qrc:/icons/compass/remove_point_en.svg"
: "qrc:/icons/compass/remove_point_dis.svg"
}
MouseArea {
id: removePointItemMouseArea
anchors.fill: removePointRect
hoverEnabled: true
acceptedButtons: Qt.LeftButton
onClicked: {
if (hasUserMenuProperty.hasUserMenu()
&& !globalUserManager.hasAccessToPrivilege("controlMap"))
return
map.pointPositionModel.remove(map.pointPositionModel.index(index, 0))
}
}
}
}
}
Component.onCompleted: {
pointsPositionComboBox.popup.contentItem.implicitHeight = Qt.binding(function () {
// Делаем отображение только 10 элементов (остальные скроллом только)
return Math.min(pointsPositionRect.height * 10,
pointsPositionComboBox.popup.contentItem.contentHeight)
})
}
How to display a list of combo box elements from the top, and not from the bottom as in the photo?
P.s. I set implicitHeight for displaying element of combobox in Component.onCompleted
P.s.2 Now it looks like picture:
I've used the implicitHeight of the Popup to set its y property. Have a look at the source below. The default behavior of the Popup is when ever it fits below it will open up below, if there is not enough space below it will open above the ComboBox. The following code is a tweaked version of the Customizing ComboBox example from the Qt documentation.
import QtQuick 2.12
import QtQuick.Window 2.12
import QtQuick.Controls 2.12
Window {
width: 400
height: 300
Row {
anchors.centerIn: parent
ComboBox {
id: control
model: ["First", "Second", "Third"]
delegate: ItemDelegate {
width: control.width
contentItem: Text {
text: modelData
color: "#21be2b"
font: control.font
elide: Text.ElideRight
verticalAlignment: Text.AlignVCenter
}
highlighted: control.highlightedIndex === index
}
indicator: Canvas {
id: canvas
x: control.width - width - control.rightPadding
y: control.topPadding + (control.availableHeight - height) / 2
width: 12
height: 8
contextType: "2d"
Connections {
target: control
function onPressedChanged() { canvas.requestPaint(); }
}
onPaint: {
context.reset();
context.moveTo(0, 0);
context.lineTo(width, 0);
context.lineTo(width / 2, height);
context.closePath();
context.fillStyle = control.pressed ? "#17a81a" : "#21be2b";
context.fill();
}
}
contentItem: Text {
leftPadding: 10
rightPadding: control.indicator.width + control.spacing
text: control.displayText
font: control.font
color: control.pressed ? "#17a81a" : "#21be2b"
verticalAlignment: Text.AlignVCenter
elide: Text.ElideRight
}
background: Rectangle {
implicitWidth: 120
implicitHeight: 40
border.color: control.pressed ? "#17a81a" : "#21be2b"
border.width: control.visualFocus ? 2 : 1
radius: 2
}
popup: Popup {
y: myCheckBox.checked ? -implicitHeight + 1 : control.height - 1
width: control.width
implicitHeight: contentItem.implicitHeight
padding: 1
contentItem: ListView {
clip: true
implicitHeight: contentHeight
model: control.popup.visible ? control.delegateModel : null
currentIndex: control.highlightedIndex
ScrollIndicator.vertical: ScrollIndicator { }
}
background: Rectangle {
border.color: "#21be2b"
radius: 2
}
}
}
CheckBox {
id: myCheckBox
text: qsTr("above")
}
}
}

How to Correctly Clear Qml ListView Selection

If I have the following:
import QtQuick 2.4
import QtQuick.Controls 1.3
import QtQuick.Window 2.2
import QtQuick.Dialogs 1.2
ApplicationWindow {
title: qsTr("Hello World")
width: 800
height: 700
visible: true
property var myArray: [1, 2, 3, 4, 5, 6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]
menuBar: MenuBar {
Menu {
title: qsTr("&File")
MenuItem {
text: qsTr("&Open")
onTriggered: messageDialog.show(qsTr("Open action triggered"));
}
MenuItem {
text: qsTr("E&xit")
onTriggered: Qt.quit();
}
}
}
Rectangle {
id: myButton
anchors.top: parent.top
anchors.topMargin: 5
color: "yellow"
width: 100
height: 25
radius: 3
anchors.horizontalCenter: parent.horizontalCenter
Text {
text: "Clear Selection"
anchors.fill: parent
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
}
MouseArea {
anchors.fill: parent
onClicked: {
myListView.currentIndex = -1
}
}
}
ListView {
id: myListView
width: 300
anchors.horizontalCenter: parent.horizontalCenter
anchors.top: myButton.bottom
anchors.topMargin: 5
anchors.bottom: parent.bottom
currentIndex: -1
//highlightFollowsCurrentItem: false
highlight: Rectangle {
color: "pink"
radius: 3
width: parent.width - 10
height: 25
//y: myListView.currentItem.y
anchors.horizontalCenter: parent.horizontalCenter
}
clip: true
model: myArray
delegate: Rectangle {
width: parent.width - 10
height: 25
color: "transparent"
border.color: "cyan"
anchors.horizontalCenter: parent.horizontalCenter
Text {
text: myArray[index]
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
anchors.fill: parent
}
MouseArea {
anchors.fill: parent
onClicked: myListView.currentIndex = index
}
}
}
MessageDialog {
id: messageDialog
title: qsTr("May I have your attention, please?")
function show(caption) {
messageDialog.text = caption;
messageDialog.open();
}
}
}
When clicking the Clear Selection button I receive the following:
qrc:/main.qml:67: TypeError: Cannot read property of null
qrc:/main.qml:64: TypeError: Cannot read property of null
How can I clear the selection without getting the error? It doesn't appear to crash the application but I have a list view that changes based on another list view selection and the error occurs several times, cluttering up the debug output in Qt Creator. I have noticed this in Qt 5.4 and 5.5
The documentation for ListView says:
An instance of the highlight component is created for each list. The geometry of the resulting component instance is managed by the list so as to stay with the current item, unless the highlightFollowsCurrentItem property is false.
So you don't need to try to manage the position of the highlight item yourself. If you want to position the highlight, create an intermediate parent item instead:
highlight: Item {
Rectangle {
color: "pink"
radius: 3
width: parent.width - 10
height: 25
anchors.horizontalCenter: parent.horizontalCenter
}
}
As for why it happens, it's likely because the highlight item is reparented, leaving it in a state where its parent property is null. You can test this out with the following code:
anchors.horizontalCenter: { print(parent); parent.horizontalCenter }
The problem in general is that if you have a foo, which is supposed to have a bar, then you reference it as foo.bar, however, if foo was not properly initialized, then it cannot have a bar, since it does not exist (yet). In your case it seems that parent is not properly initialized, so it does not have a width and horizontalCenter (in the delegate, maybe), respectively. The solution is to initialize properly the object whose members are to be used, in our case, parent.
I had asked this question over on the Qt forum (https://forum.qt.io/topic/62328/clearing-a-qml-listview-selection) as well, but stack was quicker with a response. Checking the parent value works:
import QtQuick 2.4
import QtQuick.Controls 1.3
import QtQuick.Window 2.2
import QtQuick.Dialogs 1.2
ApplicationWindow {
title: qsTr("Hello World")
width: 800
height: 700
visible: true
property int myMargin: 5
menuBar: MenuBar {
Menu {
title: qsTr("&File")
MenuItem {
text: qsTr("&Open")
onTriggered: messageDialog.show(qsTr("Open action triggered"));
}
MenuItem {
text: qsTr("E&xit")
onTriggered: Qt.quit();
}
}
}
Rectangle {
id: myButton
anchors.top: parent.top
anchors.topMargin: myMargin
color: "yellow"
width: 100
height: 25
radius: 3
anchors.horizontalCenter: parent.horizontalCenter
Text {
text: "Clear Selection"
anchors.fill: parent
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
}
MouseArea {
anchors.fill: parent
onClicked: {
myListView.currentIndex = -1
}
}
}
Rectangle {
width: 300
anchors.top: myButton.bottom
anchors.topMargin: myMargin
anchors.bottom: parent.bottom
anchors.horizontalCenter: parent.horizontalCenter
ListView {
id: myListView
anchors.fill: parent
currentIndex: -1
spacing: 3
highlightMoveDuration: 25
highlight: Rectangle {
width: parent ? parent.width - 10 : 0
height: parent ? 25 : 0
color: "pink"
radius: 3
anchors.horizontalCenter: parent ? parent.horizontalCenter : undefined
}
clip: true
model: ListModel {
id: myArray
Component.onCompleted: {
for (var i = 1; i < 46; i++)
append({number: i})
}
}
delegate: Rectangle {
width: parent ? parent.width - 10 : 0
height: parent ? 25 : 0
color: "transparent"
border.color: "cyan"
anchors.horizontalCenter: parent ? parent.horizontalCenter : undefined
Text {
text: number
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
anchors.fill: parent
}
MouseArea {
anchors.fill: parent
onClicked: {
myListView.currentIndex = index
}
}
}
}
}
MessageDialog {
id: messageDialog
title: qsTr("May I have your attention, please?")
function show(caption) {
messageDialog.text = caption;
messageDialog.open();
}
}
}

QML ComboBox item DropDownMenu style

I want to use the ComboBox type in my project. Is it possible to change the appearance of the drop-down menu (color, shape, text style) or do I need to use a combination of rectangles, ListViews and other types?
The following code applies customizations but no modification is defined for the drop-down menu which remains gray:
ComboBox {
currentIndex: 2
activeFocusOnPress: true
style: ComboBoxStyle {
id: comboBox
background: Rectangle {
id: rectCategory
radius: 5
border.width: 2
color: "#fff"
Image {
source: "pics/corner.png"
anchors.bottom: parent.bottom
anchors.right: parent.right
anchors.bottomMargin: 5
anchors.rightMargin: 5
}
}
label: Text {
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter
font.pointSize: 15
font.family: "Courier"
font.capitalization: Font.SmallCaps
color: "black"
text: control.currentText
}
}
model: ListModel {
id: cbItems
ListElement { text: "Banana" }
ListElement { text: "Apple" }
ListElement { text: "Coconut" }
}
width: 200
}
The current public APIs does not allow customization of the drop-down menu as stated here. Qt 5.4, i.e. Styles 1.3, just introduced some properties to customize fonts and text (docs here) but still no public access to drop-down customization.
Also, the example provided in the link does not work with the newer versions of Qt. Here is a modified version I've tested with Qt 5.3, Qt 5.4 and Qt 5.5 (remember to add import QtQuick.Controls.Private 1.0 to the imports):
ComboBox {
id: box
currentIndex: 2
activeFocusOnPress: true
style: ComboBoxStyle {
id: comboBox
background: Rectangle {
id: rectCategory
radius: 5
border.width: 2
color: "#fff"
}
label: Text {
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter
font.pointSize: 15
font.family: "Courier"
font.capitalization: Font.SmallCaps
color: "black"
text: control.currentText
}
// drop-down customization here
property Component __dropDownStyle: MenuStyle {
__maxPopupHeight: 600
__menuItemType: "comboboxitem"
frame: Rectangle { // background
color: "#fff"
border.width: 2
radius: 5
}
itemDelegate.label: // an item text
Text {
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter
font.pointSize: 15
font.family: "Courier"
font.capitalization: Font.SmallCaps
color: styleData.selected ? "white" : "black"
text: styleData.text
}
itemDelegate.background: Rectangle { // selection of an item
radius: 2
color: styleData.selected ? "darkGray" : "transparent"
}
__scrollerStyle: ScrollViewStyle { }
}
property Component __popupStyle: Style {
property int __maxPopupHeight: 400
property int submenuOverlap: 0
property Component frame: Rectangle {
width: (parent ? parent.contentWidth : 0)
height: (parent ? parent.contentHeight : 0) + 2
border.color: "black"
property real maxHeight: 500
property int margin: 1
}
property Component menuItemPanel: Text {
text: "NOT IMPLEMENTED"
color: "red"
font {
pixelSize: 14
bold: true
}
}
property Component __scrollerStyle: null
}
}
model: ListModel {
id: cbItems
ListElement { text: "Banana" }
ListElement { text: "Apple" }
ListElement { text: "Coconut" }
}
width: 200
}
Here __dropDownStyle is assigned with a MenuStyle type. Some properties of such type are customized to obtain the desired style, in particular itemDelegate (which defines the appearance of an item inside the combobox) and frame (overall background). Refer to the linked MenuStyle APIs for more details. Overall result:
Note that this approach does perfectly work on Windows and Android whereas on OSX the code is completely ignored. One can check the qml style file inside the Qt installation (search for a subpath like qml/QtQuick/Controls/Styles/Desktop) to see what changes w.r.t. Windows and try to adapt the provided solution. This part is left up to the reader.
Thanks alot! I solved this by next code:
Item {
id: app
width: 200
height: 150
ListModel{
id: dataModel
ListElement{ name: "Day" }
ListElement{ name: "Week" }
ListElement{ name: "Month" }
ListElement{ name: "Year" }
}
Button {
id: comboButton
width: parent.width
height: parent.height / 5
checkable: true
style: ButtonStyle {
background: Rectangle {
color: control.pressed ? "#888" : "#fff"
smooth: true
radius: 5
border.width: 2
Image {
source: "pics/corner.png"
anchors.bottom: parent.bottom
anchors.right: parent.right
anchors.bottomMargin: 5
anchors.rightMargin: 5
}
}
label: Text {
renderType: Text.NativeRendering
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter
font.family: "Courier"
font.capitalization: Font.SmallCaps
font.pointSize: 15
color: "black"
text: "Day"
}
}
onVisibleChanged: {
if(!visible)
checked = false
}
}
TableView {
id: tableView
height: 120
width: parent.width
anchors.bottom: parent.bottom
highlightOnFocus: true
headerVisible: false
visible: comboButton.checked ? true : false
TableViewColumn {
role: "name"
}
model: dataModel
itemDelegate: Item {
Rectangle {
color: styleData.selected ? "#888" : "#fff"
height: comboButton.height - 0.5
border.width: 0.5
width: parent.width
Text {
renderType: Text.NativeRendering
anchors.verticalCenter: parent.verticalCenter
anchors.horizontalCenter: parent.horizontalCenter
font.family: "Courier"
font.capitalization: Font.SmallCaps
font.pointSize: 15
color: "black"
elide: styleData.elideMode
text: styleData.value
}
}
}
rowDelegate: Item {
height: comboButton.height - 0.5
}
onClicked: {
comboButton.checked = false
tableView.selection.clear()
}
}
}
With current Qt (as of 2020), ComboBox can be customized out-of-the box by specifying background, contentItem, indicator and delegate:
https://doc.qt.io/qt-5/qtquickcontrols2-customize.html#customizing-combobox
I've been using approaches like that, but they have a lot of limitations with focus management and z-index management.
I've end up with the implementation of ComboBox which consists of 2 parts: a header which you actually put somewhere and a dropdown component which you create dynamically. The latter consists of an Item covering everything (and intercepting mouse activity) and a dropdown which is carefully positioned below the header.
Code is pretty massive to included here so you can see details in my blogpost with all the code

QT5 QML-C++ binding and interaction: what am i doing wrong?

I am trying to get how to show C++ variables on a QML window, and also how to hande C++ properties or call C++ functions from there.
While i'm trying to follow various tutorials (most of them linked in other questions at this site) i can't get it work....
The "big plan" is that i would like to have a class UI_Updater which will expose to the QML all the data i want to show, and have the "real" app working underline (it will gather data using a socket or a serial).
Right now, all i want is to show 3 integers, changing them with a timer and/or by a couple of menu items.
This is all my code and the errors i get:
ui_updater.h
#ifndef UI_UPDATER_H
#define UI_UPDATER_H
#include <QObject>
#include <QtGui>
class UI_Updater : public QObject
{
Q_OBJECT
Q_PROPERTY(int countEjT
READ getcountEjT
WRITE setcountEjT
NOTIFY countEjTChanged
)
Q_PROPERTY(int countEjF
READ getcountEjF
WRITE setcountEjF
NOTIFY countEjFChanged
)
Q_PROPERTY(int countEjFNC
READ getcountEjFNC
WRITE setcountEjFNC
NOTIFY countEjFNCChanged
)
public:
explicit UI_Updater(QObject *parent = 0);
int getcountEjT();
int getcountEjF();
int getcountEjFNC();
void setcountEjT(int NewVal);
void setcountEjF(int NewVal);
void setcountEjFNC(int NewVal);
Q_INVOKABLE void increment(int i);
signals:
void countEjTChanged();
void countEjFChanged();
void countEjFNCChanged();
public slots:
void testSlot();
private:
int _countEjT;
int _countEjF;
int _countEjFNC;
QTimer *myTimer;
void OnTimeout();
};
#endif // UI_UPDATER_H
ui_updater.cpp
#include "ui_updater.h"
UI_Updater::UI_Updater(QObject *parent) :
QObject(parent)
{
myTimer = new QTimer(this);
myTimer->start(1000);
connect(myTimer, SIGNAL(timeout()), this, SLOT(testSlot()));
_countEjT = _countEjF = _countEjFNC = 0;
emit countEjTChanged();
emit countEjFChanged();
emit countEjFNCChanged();
}
void UI_Updater::setcountEjT(int NewVal)
{
_countEjT = NewVal;
emit countEjTChanged();
}
void UI_Updater::setcountEjF(int NewVal)
{
_countEjF = NewVal;
emit countEjFChanged();
}
void UI_Updater::setcountEjFNC(int NewVal)
{
_countEjFNC = NewVal;
emit countEjFNCChanged();
}
int UI_Updater::getcountEjT()
{
return _countEjT;
}
int UI_Updater::getcountEjF()
{
return _countEjF;
}
int UI_Updater::getcountEjFNC()
{
return _countEjFNC;
}
void UI_Updater::OnTimeout()
{
increment(0);
}
void UI_Updater::increment(int i)
{
if (i==0) {
++_countEjT;
}else{
_countEjT+=i;
}
emit countEjTChanged();
if (_countEjT%2 == 0) {
++_countEjF;
emit countEjFChanged();
}
if (_countEjF%4 == 0) {
++_countEjFNC;
emit countEjFNCChanged();
}
}
void UI_Updater::testSlot()
{
increment(2);
}
main.cpp
#include <QtGui/QGuiApplication>
#include <QQmlApplicationEngine>
#include <QtQml>
#include <QtQuick/QQuickView> // Necessario per QQuickWindow
#include "ui_updater.h"
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
qmlRegisterType<UI_Updater>("Phase.UI_Updater", 1, 0, "UI_Updater");
QQmlApplicationEngine engine(QUrl("qrc:/qml/MainForm.qml"));
QObject *topLevel = engine.rootObjects().value(0);
QQuickWindow *window = qobject_cast<QQuickWindow *>(topLevel);
if ( !window ) {
qWarning("Error: Your root item has to be a Window.");
return -1;
}
window->show(); // Evita di dover settare visible: true nel file qml
return app.exec();
}
The QML windows is meant to have multiple pages. I'll copy the code only of the relevant one:
MainForm.qml
import QtQuick 2.1
import QtQuick.Controls 1.0
import QtQuick.Window 2.1
import Phase.UI_Updater 1.0
ApplicationWindow {
id: screen
width: 480
height: 272
//toolBar: {
//}
property int partition: height / 3
title: qsTr("Main Screen")
menuBar: MenuBar {
Menu {
title: qsTr("File")
MenuItem {
text: qsTr("Exit")
onTriggered: Qt.quit();
}
}
Menu {
title: qsTr("Pages")
MenuItem {
text: qsTr("Working")
onTriggered: currentPage = "pagWorking";
}
MenuItem {
text: qsTr("Graphics")
onTriggered: currentPage = "pagGraphics";
}
MenuItem {
text: qsTr("Setup")
onTriggered: currentPage = "pagSetup";
}
// These items should increment the variables....
MenuItem {
text: qsTr("Add One")
onTriggered: UI_Updater.countEjT = UI_Updater.countEjT + 1;
}
MenuItem {
text: qsTr("Increment")
onTriggered: UI_Updater.increment(1);
}
}
}
// GESTIONE PAGINE ---------------------------------------------------------
property variant pagesList: [
"pagWorking",
"pagSetup",
"pagGraphics"
];
property string currentPage: "pagWorking";
Repeater {
model: pagesList;
delegate: Loader {
id: pageLoader
x: 0
y: 0
anchors.rightMargin: 0
anchors.bottomMargin: 0
anchors.leftMargin: 0
anchors.topMargin: 0
active: false;
asynchronous: true;
anchors.fill: parent;
visible: (currentPage === modelData);
source: "%1.qml".arg(modelData);
onVisibleChanged: { loadIfNotLoaded(); }
Component.onCompleted: { loadIfNotLoaded(); }
function loadIfNotLoaded() {
// Carica la pagina la prima volta che ce n'è bisogno
if (visible && !active) {
active = true;
}
}
} // Fine Loader
}
UI_Updater {
countEjT: 0;
countEjF: 0;
countEjFNC: 0;
}
// Fine GESTIONE PAGINE ------------------------------------------------
}
pagWorking.qml
import QtQuick 2.0
import QtQuick.Controls 1.0
import Phase.UI_Updater 1.0
Rectangle {
id: pagBackground
width: 400
height: 250
gradient: Gradient {
GradientStop {
position: 0
color: "#010036"
}
GradientStop {
position: 1
color: "#08006b"
}
}
Label {
id: lPagTitle
x: 0
width: parent.width
height: 20
color: "#0e909c"
text: "Working"
font.bold: true
font.pointSize: 12
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter
anchors.top: parent.top
anchors.topMargin: 0
}
GroupBox {
id: group_box1
x: 133
width: 120
height: 100
anchors.top: parent.top
anchors.topMargin: 20
anchors.horizontalCenter: parent.horizontalCenter
Text {
id: tTachimetro
x: 162
y: 50
width: 100
height: 30
color: "#d0d0ff"
text: qsTr("000.0°")
anchors.verticalCenterOffset: 5
anchors.verticalCenter: parent.verticalCenter
font.bold: true
style: Text.Normal
verticalAlignment: Text.AlignVCenter
font.pixelSize: 25
anchors.horizontalCenter: parent.horizontalCenter
horizontalAlignment: Text.AlignHCenter
}
Text {
id: labTach
x: 149
y: 30
width: 100
height: 20
color: "#a0a0ff"
text: qsTr("Position")
anchors.verticalCenterOffset: -20
anchors.verticalCenter: parent.verticalCenter
anchors.horizontalCenterOffset: 0
verticalAlignment: Text.AlignVCenter
font.pixelSize: 15
anchors.horizontalCenter: parent.horizontalCenter
horizontalAlignment: Text.AlignHCenter
}
}
GroupBox {
id: group_box2
x: 204
width: 200
height: 74
anchors.horizontalCenterOffset: 100
anchors.horizontalCenter: parent.horizontalCenter
anchors.top: parent.top
anchors.topMargin: 120
Text {
id: tET
x: 147
y: 0
width: 110
height: 20
color: "#ff8000"
text: UI_Updater.countEjT.toString();
anchors.right: parent.right
anchors.rightMargin: 0
anchors.top: parent.top
anchors.topMargin: 0
font.bold: true
style: Text.Normal
verticalAlignment: Text.AlignVCenter
font.pixelSize: 16
horizontalAlignment: Text.AlignRight
}
Text {
id: labET
x: 11
width: 70
height: 20
color: "#a0a0ff"
text: qsTr("Ej T")
anchors.top: parent.top
anchors.topMargin: 0
anchors.right: parent.right
anchors.rightMargin: 110
verticalAlignment: Text.AlignVCenter
font.pixelSize: 16
horizontalAlignment: Text.AlignRight
}
Text {
id: tEF
x: 130
y: 21
width: 110
height: 20
color: "#ff8000"
text: UI_Updater.countEjF.toString();
anchors.top: parent.top
font.bold: true
font.pixelSize: 16
verticalAlignment: Text.AlignVCenter
style: Text.Normal
anchors.rightMargin: 0
anchors.right: parent.right
anchors.topMargin: 21
horizontalAlignment: Text.AlignRight
}
Text {
id: labEF
x: 60
y: 21
width: 70
height: 20
color: "#a0a0ff"
text: qsTr("Ej F")
anchors.top: parent.top
font.pixelSize: 16
verticalAlignment: Text.AlignVCenter
anchors.rightMargin: 110
anchors.right: parent.right
anchors.topMargin: 21
horizontalAlignment: Text.AlignRight
}
Text {
id: tENCF
x: 130
y: 40
width: 110
height: 20
color: "#ff8000"
text: UI_Updater.countEjFNC.toString();
anchors.top: parent.top
font.bold: true
anchors.rightMargin: 0
style: Text.Outline
verticalAlignment: Text.AlignVCenter
font.pixelSize: 16
anchors.right: parent.right
anchors.topMargin: 42
horizontalAlignment: Text.AlignRight
}
Text {
id: labENCF
x: 60
y: 40
width: 70
height: 20
color: "#a0a0ff"
text: qsTr("Ej FNC")
anchors.top: parent.top
anchors.rightMargin: 110
verticalAlignment: Text.AlignVCenter
font.pixelSize: 16
anchors.right: parent.right
anchors.topMargin: 42
horizontalAlignment: Text.AlignRight
}
}
property bool shown: false;
state: "NASCOSTO";
onVisibleChanged: {
if (visible === false)
pagBackground.state = "NASCOSTO"
else if (visible === true)
pagBackground.state = "VISIBILE"
}
states: [
State {
name: "VISIBILE"
PropertyChanges { target: pagBackground; opacity: 1 }
}
,
State {
name: "NASCOSTO"
PropertyChanges { target: pagBackground; opacity: 0 }
}
]
//! [states]
//! [transitions]
transitions: [
Transition {
to: "NASCOSTO"
NumberAnimation { properties: "opacity"; duration: 1500; easing.type: Easing.OutExpo }
}
,
Transition {
to: "VISIBILE"
NumberAnimation { properties: "opacity"; duration: 1500; easing.type: Easing.OutExpo }
}
]
//! [transitions]
}
Now, it builds, but when i run i get:
TypeError: Cannot call method 'toString' to undefned
and clicking on the menu item "Increment i get
TypeError: object [object Object] has no method 'increment'
Now seems to me that my object UI_Updater was'nt really istanciated.... even if the editor sees it.
What should i do?
Thanks
The error message seem quite clear, you are not invoking increment on an UI_Updater instance but on UI_Updater type.
Try to put an id on your UI_Updater, then you can call methods declare by your UI_Updater C++ class. Here a little update in your MainForm.qml :
import QtQuick 2.1
import QtQuick.Controls 1.0
import QtQuick.Window 2.1
import Phase.UI_Updater 1.0
ApplicationWindow {
id: screen
width: 480
height: 272
//toolBar: {
//}
property int partition: height / 3
title: qsTr("Main Screen")
menuBar: MenuBar {
Menu {
title: qsTr("File")
MenuItem {
text: qsTr("Exit")
onTriggered: Qt.quit();
}
}
Menu {
title: qsTr("Pages")
MenuItem {
text: qsTr("Working")
onTriggered: currentPage = "pagWorking";
}
MenuItem {
text: qsTr("Graphics")
onTriggered: currentPage = "pagGraphics";
}
MenuItem {
text: qsTr("Setup")
onTriggered: currentPage = "pagSetup";
}
// These items should increment the variables....
MenuItem {
text: qsTr("Add One")
onTriggered: updater.countEjT = updater.countEjT + 1;
}
MenuItem {
text: qsTr("Increment")
onTriggered: updater.increment(1);
}
}
}
// GESTIONE PAGINE ---------------------------------------------------------
property variant pagesList: [
"pagWorking",
"pagSetup",
"pagGraphics"
];
property string currentPage: "pagWorking";
Repeater {
model: pagesList;
delegate: Loader {
id: pageLoader
x: 0
y: 0
anchors.rightMargin: 0
anchors.bottomMargin: 0
anchors.leftMargin: 0
anchors.topMargin: 0
active: false;
asynchronous: true;
anchors.fill: parent;
visible: (currentPage === modelData);
source: "%1.qml".arg(modelData);
onVisibleChanged: { loadIfNotLoaded(); }
Component.onCompleted: { loadIfNotLoaded(); }
function loadIfNotLoaded() {
// Carica la pagina la prima volta che ce n'è bisogno
if (visible && !active) {
active = true;
}
}
} // Fine Loader
}
UI_Updater {
id: updater
countEjT: 0;
countEjF: 0;
countEjFNC: 0;
}
// Fine GESTIONE PAGINE ------------------------------------------------
}

Action menu button selected bb10

How do you set the action menu button as selected when it's already on its view? I ave this one view with action menu tabs, then when you tapped one then it'll redirect the user to that view, and I want the button to be displayed as pressed. Where do I set the selected state of the button?
Here's my qml:
import bb.cascades 1.0
Page {
Container {
background: Color.create("#f9f7f2");
layout: StackLayout {}
// Container for holding the title
Container {
horizontalAlignment: HorizontalAlignment.Center
layout: DockLayout {}
ImageView {
horizontalAlignment: HorizontalAlignment.Fill
verticalAlignment: VerticalAlignment.Fill
imageSource: "asset:///images/navigation_bar.png"
}
Container {
horizontalAlignment: HorizontalAlignment.Right
rightPadding: 30
topPadding: 40
layout: DockLayout {}
ImageButton {
id: btnsettings
verticalAlignment: VerticalAlignment.Center
defaultImageSource: "asset:///images/navbar_icon_settings.png"
onClicked: {
// show settings page when the button is clicked
cppObj.onSettingsClicked();
}
}
}
}
Container {
topPadding: 20
leftPadding: 20
rightPadding: 20
bottomPadding: 20
background: Color.create("#F4E9E1");
horizontalAlignment: HorizontalAlignment.Fill
layout: StackLayout {}
Label {
verticalAlignment: VerticalAlignment.Center
horizontalAlignment: HorizontalAlignment.Left
text: cppObj.name
textStyle {
// fontFamily: FontStyle.Default.Myriad
// fontSize: 36
color: Color.create("#60323C")
}
}
}
Container {
verticalAlignment: VerticalAlignment.Center
horizontalAlignment: HorizontalAlignment.Center
layout: DockLayout {}
Divider {}
ScrollView {
scrollViewProperties {
scrollMode: ScrollMode.Vertical
}
/* ImageView {
id: listviewbackground
verticalAlignment: VerticalAlignment.Center
horizontalAlignment: HorizontalAlignment.Center
scalingMethod: ScalingMethod.Fill
imageSource: "asset:///images/list_view_cell.png"
}*/
ListView {
id: lvprojects
dataModel: cppObj.model()
listItemComponents: [
ListItemComponent {
type: "item"
Container {
horizontalAlignment: HorizontalAlignment.Center
layout: DockLayout {}
touchPropagationMode: TouchPropagationMode.Full;
StandardListItem {
title:ListItemData.desc
}
}
}
]
onTriggered: {
var selectedItem = dataModel.data(indexPath);
onClicked: {
// show issue's comment page when the button is clicked
cppObj.onIssueClicked(selectedItem.name);
}
}
}
}
}
}
actions: [
ActionItem {
title: qsTr ("Add Issue")
imageSource: "asset:///images/actionbar_icon_add.png"
ActionBar.placement: ActionBarPlacement.OnBar
onTriggered: {
cppObj.onAddIssuesClicked();
}
},
ActionItem {
title: qsTr ("Issues")
imageSource: "asset:///images/actionbar_icon_issues.png"
ActionBar.placement: ActionBarPlacement.OnBar
onTriggered: {
cppObj.onIssuesClicked();
}
},
ActionItem {
title: qsTr ("Members")
imageSource: "asset:///images/actionbar_icon_members.png"
ActionBar.placement: ActionBarPlacement.OnBar
onTriggered: {
cppObj.onMembersClicked();
}
}
]
}
I guess what you're trying to achieve is to mark a tab as active: void TabbedPane::setActiveTab (bb::cascades::Tab *activeTab)