Zoom with control + plus and control - minus? [duplicate] - qt

The problem with my code below is that on US/UK keyboard layouts + is generated with shift + =, but when the user uses both the control and shift modifiers simultaneously, + is not generated. This has been tested on Mac.
Keys.onPressed: {
if (event.modifiers & Qt.ControlModifier) {
if (event.key === Qt.Key_Minus) {
zoom(false)
event.accepted = true
} else if (event.key === Qt.Key_Plus) {
zoom(true)
event.accepted = true
}
}
}
Since control + + and control + - are standard shortcuts for zooming in applications I am certain that others have solved this. But how?

Instead of Key.onPressed use Shortcut and its sequence property :
Shortcut {
sequence: StandardKey.ZoomIn
onActivated: zoom(true)
}
Your issue is mentionned in this section of the QKeySequence documentation.

You have to use Qt.ShiftModifier for reacting on shift key:
Item {
focus: true
Keys.onPressed: {
if ((event.key == Qt.Key_Plus) && (event.modifiers & Qt.ShiftModifier))
console.log("PRessed");
}
}

Related

How can I let users use control + + for zoom in and control + - for zoom out?

The problem with my code below is that on US/UK keyboard layouts + is generated with shift + =, but when the user uses both the control and shift modifiers simultaneously, + is not generated. This has been tested on Mac.
Keys.onPressed: {
if (event.modifiers & Qt.ControlModifier) {
if (event.key === Qt.Key_Minus) {
zoom(false)
event.accepted = true
} else if (event.key === Qt.Key_Plus) {
zoom(true)
event.accepted = true
}
}
}
Since control + + and control + - are standard shortcuts for zooming in applications I am certain that others have solved this. But how?
Instead of Key.onPressed use Shortcut and its sequence property :
Shortcut {
sequence: StandardKey.ZoomIn
onActivated: zoom(true)
}
Your issue is mentionned in this section of the QKeySequence documentation.
You have to use Qt.ShiftModifier for reacting on shift key:
Item {
focus: true
Keys.onPressed: {
if ((event.key == Qt.Key_Plus) && (event.modifiers & Qt.ShiftModifier))
console.log("PRessed");
}
}

Wrong mouse coordinates when using css zoom property

When I use the css zoom property, the mouse coordinates are correct on all but two elements : http://seiyria.com/bootstrap-slider/ & https://fullcalendar.io
How do we fix this problem ?
Thank you in advance for your help.
For fullcalendar.io, I found a solution on Github, it is necessary to edit two functions of the file fullcalendar.js :
function getEvX(ev) {
if (ev.pageX !== undefined) {
return ev.pageX / Number($('body').css('zoom'));
}
var touches = ev.originalEvent.touches;
if (touches) {
return touches[0].pageX / Number($('body').css('zoom'));
}
}
function getEvY(ev) {
if (ev.pageY !== undefined) {
return ev.pageY / Number($('body').css('zoom'));
}
var touches = ev.originalEvent.touches;
if (touches) {
return touches[0].pageY / Number($('body').css('zoom'));
}
}
For bootstrap slider, here's the solution :
var valeurZoom = window.getComputedStyle(document.body, null).getPropertyValue('zoom');
if (valeurZoom !== "" && valeurZoom !== 1) {
eventPosition = eventPosition / valeurZoom;
}
Hopefully it helps other people !

Hide key from Qt Virtual keyboard

Is there a way to hide the language selection key from the virtual keyboard without use a custom layout?
I was able to hide the language key with a workaround:
property var keyboardLayout: inputPanel.keyboard.layout
function findChildByProperty(parent, propertyName, propertyValue, compareCb) {
var obj = null
if (parent === null)
return null
var children = parent.children
for (var i = 0; i < children.length; i++) {
obj = children[i]
if (obj.hasOwnProperty(propertyName)) {
if (compareCb !== null) {
if (compareCb(obj[propertyName], propertyValue))
break
} else if (obj[propertyName] === propertyValue) {
break
}
}
obj = findChildByProperty(obj, propertyName, propertyValue, compareCb)
if (obj)
break
}
return obj
}
onKeyboardLayoutChanged: {
if(keyboardLayout!=""){
var ChangeLanguageKey= findChildByProperty(inputPanel.keyboard, "objectName", "changeLanguageKey", null)
if(ChangeLanguageKey){
ChangeLanguageKey.visible=false
}
}
}
InputPanel {
id: inputPanel
z: 99
y: parent.height
anchors.left: parent.left
anchors.right: parent.right
states: State {
name: "visible"
when: inputPanel.active
PropertyChanges {
target: inputPanel
y: parent.height - inputPanel.height
}
}
transitions: Transition {
from: ""
to: "visible"
reversible: true
ParallelAnimation {
NumberAnimation {
properties: "y"
duration: 400
easing.type: Easing.InOutBack
}
}
}
CustomComponents.AutoScroller {
id:autoscroller
panelY: inputPanel.y
}
}
This only works in version 5.9 where the objectname property is defined with "changeLanguageKey", for previous versions set the property in the source code and recompile.
No, not without using a custom layout.
You can always modify the layouts that come with the keyboard though.
I was able to hide the hideKeyboard key with this trick. I basically tried to get the reference of the emoji key and thereby was able to disable the next key which is hideKeyboard key.
function disableKey(parent, objectText)
{
var obj = null
if (parent === null)
return null
var children = parent.children
for (var i = 0; i < children.length; i++) {
obj = children[i]
if (obj.text === objectText && obj.toString().substring(0, 7) === "BaseKey") {
console.log("Disabling symbols. " + obj.text)
obj.enabled = false
}
else if(obj.displayText === "HWR"){
console.log("Disabling Handwriting mode button." + obj.displayText + " " + objectText)
obj.visible = false
}
else if(obj.text === ":-)" && obj.toString().substring(0, 7) === "BaseKey"){
console.log("Disabling hidekeyboard key." + obj.text)
children[i+1].visible = false
}
obj = disableKey(obj, objectText)
if (obj)
break
}
return obj
}

vis.js network physicsConfiguration

I am creating a network using vis.js and customizing my network with physics configuration
physics:{
stabilization: false,
},
configure: {
filter:function (option, path) {
if (path.indexOf('physics') !== -1) {
return true;
}
if (path.indexOf('smooth') !== -1 || option === 'smooth') {
return true;
}
return false;
},
showButton: false,
container: document.getElementById('config')
},
screenshot of the result
My problem is I do not want all the options, I just want some of the options and radio button only. How do I select only specific options or slider?
Thanks in advance
PS
As I asked same question on github I have got the response as:
Sorry but the only way would be to build your own config panel
you have to create your own config pannel for the network
so if any one have any other idea of customizing configuration of network plz share highly appreciable.
To adjust what options to show, you have just to adjust the filter function and actually filter options using the option and path params. Here I excluded the forceDirection option of smooth and left only barnesHut subset of options among physics:
configure: {
filter:function (option, path) {
if ((path.indexOf('physics') !== -1) && path.indexOf('barnesHut') !== -1) {
//alert(path);
return true;
}
if ((path.indexOf('smooth') !== -1 || option === 'smooth') && option != 'forceDirection') {
//alert(option);
return true;
}
return false;
},
You may also uncomment alerts to explore values of path and option further (or use console.log for more convenience).

Hiding an item outside viewport of a ListView

I've been learning QtQuick for about a week and I'm facing a weird behaviour on what I'm trying to achieve. I would like to make a vertical ListView with a Keyboard navigation so that when I press UP or DOWN, the items move up or down and if an item goes in or out of the "viewport", its opacity property will change smoothly to 0 or 1.
Here is my current QML code:
import QtQuick 2.4
Rectangle {
width:200
height:400
ListView {
property int activePosition:1
property int itemDisplayed:3
width:parent.width-50
height:parent.height-50
anchors.centerIn:parent
model:10
snapMode:ListView.SnapToItem
focus:true
cacheBuffer:2000
Component.onCompleted: {
console.log(count+' != '+contentItem.children.length+' ???')
}
Keys.onPressed: {
var i = 0
console.log('pos='+activePosition)
console.log(count+' != '+contentItem.children.length+' ???')
if (event.key === Qt.Key_Up) {
if (activePosition == 1 && currentIndex > 0) {
i = currentIndex+itemDisplayed-1
if (i < contentItem.children.length - 2/* why -2 instead of -1 ??? */) {
console.log('out='+i)
contentItem.children[i].state = 'out'
}
}
activePosition = activePosition > 1 ? activePosition - 1 : activePosition
}
if (event.key === Qt.Key_Down) {
if (activePosition == itemDisplayed && currentIndex < contentItem.children.length - 2) {
i = currentIndex-itemDisplayed+1
if (i >= 0) {
console.log('out='+i)
contentItem.children[i].state = 'out'
}
}
activePosition = activePosition < itemDisplayed ? activePosition + 1 : activePosition
}
}
delegate: Rectangle {
id:rect
state:index < ListView.view.itemDisplayed ? 'in' : 'out'
opacity:1.0
width:ListView.view.width
height:ListView.view.height/ListView.view.itemDisplayed
border.color:'white'
border.width:1
color:activeFocus ? 'red': 'gray'
onActiveFocusChanged: {
if (activeFocus) {
state = 'in'
console.log('in='+index)
}
}
states: [
State { name:'in'; PropertyChanges { target:rect; opacity:1.0 } },
State { name:'out'; PropertyChanges { target:rect; opacity:0.0 } }
]
transitions: [
Transition {
to:'in'
NumberAnimation { property:'opacity'; duration:250 }
},
Transition {
to:'out'
NumberAnimation { property:'opacity'; duration:250 }
}
]
Text {
text:index
anchors.centerIn:parent
}
}
}
}
First question : model=10, why model.count is not equal to contentItem.children.length? onCompleted gives 5 vs 11 and during navigation 10 vs 11
Second question: If I press UP or DOWN, it works fine until I reach index=4, why?
As I'm a beginner on QtQuick so maybe it's not the right approach. I tried to use the visible property but every item has visible = true even if they are outside. I tried also indexAt() with no success.
Any help would be great :-)
Now I know better about the ListView behavior. My previous code can be fixed by removing the Keys.onPressed event which is no longer useful, and by using the itemAt() method directly into the onActiveFocusChanged handler.

Resources