qml Anchoring with something inside a Row - qt

Imagine I want something like that :
INPUT1 | INPUT2 | INPUT3
------------------------------------
FIELD1 | FIELD2 | FIELD3
FIELDBIS1 | FIELDBIS2 | FIELDBIS3
I will do something close of :
Column {
Row {
INPUT1{}
INPUT2{}
INPUT3{}
}
Separator{}
Row {
FIELD1{anchor.horizontalCenter : input1.horizontalCenter;}
FIELD2{anchor.horizontalCenter : input2.horizontalCenter;}
FIELD3{anchor.horizontalCenter : input3.horizontalCenter;}
}
Row {
FIELDBIS1{anchor.horizontalCenter : input1.horizontalCenter;}
FIELDBIS2{anchor.horizontalCenter : input2.horizontalCenter;}
FIELDBIS3{anchor.horizontalCenter : input3.horizontalCenter;}
}
}
But since field, fieldbis and input are not at the same size, how can I do?
Is there a better way than anchoring to solve this problem?

Use spacing for equally sized looking columns.
Column {
spacing: 10
Row {
spacing: 10
----
----
}
}

Related

QML GridView contentItem children lenght doesn't match count

I'm experiencing issues with a GridView dinamically populated in a QtQuick app I'm developing.
The GridView is populated by the user input of a number of identical objects, except for some text.
GridView {
id: grid_fc
width : parent.width
height: parent.height / 2
model: ListModel {}
delegate: Fancoil {
objectName: nome
text: indirizzo
}
}
onNewNode:
{
grid_fc.model.append({nome: "fc_" + address, indirizzo: address})
}
At a certain signal the app need to change a property of these objects, so I search for each object by objectName and do the job.
onStatusChanged:
{
for(var i = 0; i <= grid_fc.count; i++)
{
if (grid_fc.contentItem.children[i].objectName === "fc_" + address)
{
if (online)
grid_fc.contentItem.children[i].status(Fancoil.Status.ONLINE)
else
grid_fc.contentItem.children[i].status(Fancoil.Status.OFFLINE)
break
}
}
}
If the number of object is "low" the GridView.count is equal to the GridView.contentItem.children lenght, but increasing the number, I get that the GridView.count it's correct, instead of the children lenght that is wrong.
Ex. Populating the GridView with 100 elements:
GridView.count = 100
GridView.contentItem.children = 74 (?!)
What's wrong with my code?
If the model has 100k elements, it is inefficient for the view to create 100k items if it is only going to show 100. In other words, the view dynamically creates the necessary items, so it is not recommended to access those elements through the "childrens", since these can change. Instead you should use the models:
ListModel{
id: gridview_model
}
GridView {
id: grid_fc
width : parent.width
height: parent.height / 2
model: gridview_model
delegate: Fancoil {
text: indirizzo
}
}
onNewNode:
{
gridview_model.append({status: Fancoil.Status.OFFLINE, indirizzo: address})
}
onStatusChanged: {
for(var i = 0; i <= gridview_model.count; i++)
{
var new_status = online ? Fancoil.Status.ONLINE : Fancoil.Status.OFFLINE
gridview_model.get(i).status = new_status
}
}
I get the point, but I tried this way and the result is the same.
Now, the model count is correct and I can see the code looping through all the nodes.
It seems like a rendering issue. Images out of sight seem not to catch the status update.
Also this happens: scrolling the gridview up and down causes some nodes to lose the red glow (status update to offline).
See the result of first time render

jQuery UI Draggable: Scroll other lists when dragging over them

I have a strange issue with jQuery ui-sortable. In my example I have multiple columns and in each column I have multiple sortable items.
I want to drag and drop in any column, sorting within one column is no problem.
I have two problems:
When dragging from one column to another column I need the destination column to auto scroll to the bottom.
Horizontal scroll does not auto scroll for the column on the very right side.
See my example
https://jsfiddle.net/maidanhcongtu/9ws2unLa/11/
var configuration2 = {
cursor : 'move',
placeholder : 'highlight',
dropOnEmpty : true,
connectWith : ".connectedSortable",
containment : "body",
};
$(".connectedSortable").sortable(configuration2).disableSelection();
Okay, I have found a solution to disable scrolling when you're no longer sorting in the original parent, so that the sortable item does not scroll the parent when dragging over another sortable.
I also made the sortable list you're sorting over auto scroll to the bottom.
Sorry, I changed your code up a bit because it's easier for me to keep track of things this way.
Also, I added ID's to each sortable list.
see updated fiddle: https://jsfiddle.net/Souleste/ktxeu35p/46/
$('li').addClass('item');
var y;
var og;
var n, nB, half;
$(".connectedSortable").sortable({
cursor : 'move',
placeholder : 'highlight',
dropOnEmpty : true,
connectWith : ".connectedSortable",
containment : "body",
items: '.item',
start: function(event,ui) {
og = $(this).closest('.connectedSortable');
},
over: function(event,ui) {
n = $(this).closest('.connectedSortable');
nB = n.outerHeight(true) + n.position().top;
half = nB / 2;
},
sort: function(event,ui) {
console.log(half);
if ( n.attr('id') != og.attr('id') ) {
og.sortable( "option", "scroll", false );
if (event.pageY > half) {
n.scrollTop(n.scrollTop() + 5);
} else if (event.pageY < half) {
n.scrollTop(n.scrollTop() - 5);
}
} else {
og.sortable( "option", "scroll", true );
}
}
});

Why do I have to assign a new array so that every dynamic object (component) gets deleted?

I have a JS array that I use in QML. In this array I store many dynamic objects(components) that I create and show in my application window. I also have a clear all button that is supposed to delete all items by iterating through that array. I use delete and then shift() to remove the items, however for some reason not every object gets deleted or removed. Why is that?
This is the code that is not work:
Button
{
id: clearallButton
width: 60
height: 25
text: qsTr("Clear all")
onClicked:
{
for (var y = 0; y < canvas.componentvect.length; ++y)
{
canvas.componentvect[y].destroy();
canvas.componentvect.shift();
}
}
}
And this is the code that has been working for me:
Button
{
id: clearallButton
width: 60
height: 25
text: qsTr("Clear all")
onClicked:
{
for (var y = 0; y < canvas.componentvect.length; ++y)
{
canvas.componentvect[y].destroy();
}
var emptyvect=[];
canvas.componentvect=emptyvect;
}
}
When I try variant 1, it only removes some objects and some still remain? Why is that? I call delete on every object and shift() to remove it from the array. Shouldn't every object be removed then as it does in example 2?
Ok I feel very stupid now. By using shift() inside the loop the iteration doesn't work properly because if the iterating variable destroys object on position 0 and then I use shift() the object that was supposed to be at position 1 moves to position 0. Was a logic mistake my bad.
This is the updated code and it works:
onClicked:
{
while(canvas.componentvect.length !=0)
{
canvas.componentvect[0].destroy();
canvas.componentvect.shift();
}
}

How to access nested Repeaters in QML?

I want to fill the colours in the following rectangles created through Repeaters, dynamically.
I am not able to access the bottom Repeater at all.
How should I access "all" the rectangles here?
Row
{
spacing: 20
Repeater
{
id: repeater3
property Repeater repeater2: repeater2
model: head.rows
Column
{
id: columnInBetween
spacing: 20
Repeater
{
id: repeater2
model: head.columns
property Row row1: row1
Row
{
id: row1
property Repeater repeater1: repeater1
Repeater
{
id: repeater1
model: 2
Rectangle
{
width: 20; height: 20
color: "red"
}
}
}
}
}
}
}
Repeater will expand Item they contians.So you can use .children[index] to access those Item expanded.
In your case:
/*0< index < head.rows
you get first Column expanded by repeater3*/
repeater3.itemAt(index).children[0]
/*0< index < head.columns
you get first Row of first Column expanded by repeater3 and repeater2*/
repeater3.itemAt(index).children[0].children[0]
/*0< index < 2
you get first Rectangle of first Row of first Column expanded by repeater3 and repeater2 and repeater1*/
repeater3.itemAt(index).children[0].children[0].children[0]
By the way, I do not know your intention and just remaid that you are getting a head.columns rows and 2 * head.rows columns of tables.

What's the best way to add progressbar to cxGrid column

I am adding progressbar to each row of my first grid's banded tableview column !
The way I do it => I put 4 progressbars on my form and on
btvArrProgGetProperties(TcxCustomGridTableItem *Sender, TcxCustomGridRecord *ARecord,
TcxCustomEditProperties *&AProperties) assigning properties to a specific row by changing putted progressbar properties.
here is my code
void __fastcall TfMain::btvArrProgGetProperties(TcxCustomGridTableItem *Sender, TcxCustomGridRecord *ARecord,
TcxCustomEditProperties *&AProperties)
{
if ( StrToInt(ARecord->Values[ARecord->RecordIndex,1])==4 ){
ARecord->Values[ARecord->RecordIndex,0]=100;
AProperties=pCancel->Properties;
}
else
if ( StrToInt(ARecord->Values[ARecord->RecordIndex,1])==2) {
ARecord->Values[ARecord->RecordIndex,0]=100;
AProperties=pDep->Properties;
}
else {
if (StrToInt(ARecord->Values[ARecord->RecordIndex,1])==1) {
if ((ARecord->Values[ARecord->RecordIndex,7])!=0 && (ARecord->Values[ARecord->RecordIndex,12])!=0) {
//now time
nwTm=Now().FormatString("hh:mm:ss");
//get dep time
dpTm=StrToDateTime(ARecord->Values[ARecord->RecordIndex,7]);
dpTm.DecodeTime(&dpH,&dpM,&dpS,&dpMS);
//get reg time
rgTm=StrToDateTime(ARecord->Values[ARecord->RecordIndex,12]);
//find difference between dep and reg
dif=(1.0 + Double(dpTm)-Double(rgTm));
//get difference hours and mins
dif.DecodeTime(&difH,&difM,&difS,&difMS);
//diff between dep and reg in seconds
pReg->Properties->Max=difH*3600+difM*60+difS;
nwTm=Now().FormatString("hh:mm:ss");
nwTm.DecodeTime(&nwH,&nwM,&nwS,&nwMS);
if ((dpH>nwH) || ((dpH>nwH) && (dpM>=nwM ||dpM<=nwM)) || (dpH==nwH && dpM>nwM) ) {
fltRem =(1.0 + Double(dpTm)-Double(nwTm));
fltRem.DecodeTime(&remH,&remM,&remS,&remMS);
_result=remH*3600+remM*60+remS;
pReg->Properties->Text=getTimeBySecs(_result);
ARecord->Values[ARecord->RecordIndex,0]=pReg->Properties->Max-_result;
pReg->Position=- _result;
}
else
{
pReg->Properties->Max=100;
ARecord->Values[ARecord->RecordIndex,0]=100;
pReg->Properties->Text="Готово";
/*
ARecord->Values[ARecord->RecordIndex,0]=pReg->Properties->Max;
pReg->Position=pReg->Properties->Max;
*/
}
AProperties=pReg->Properties;
}
}
}
}
I think that this not a good approach to solve my problem (adding progressbar to a column which it's position get's changed dynamically), because when I click to each's row progressbar's position gets changed due to a last value set to progressbar!!
I prefer to dynamically create progressbar set name and other properties to it during runtime and assign to specific row on GetProperties event.
What approach is the best one ?
Is there any demo on this issue? If yes could you share please!
Thanks in advance !

Resources