QML StatusBar in the upper portion of ApplicationWindow - why? - qml

I have following QML's ApplicationWindow:
import QtQuick 2.4
import QtQuick.Controls 1.3
import QtQuick.Window 2.2
import QtQuick.Dialogs 1.2
import QtMultimedia 5.0
import QtQuick.Layouts 1.0
import QtTest 1.1
import "gui/windows"
import "gui/items"
ApplicationWindow
{
id: ueWindowMain
title: qsTr("testApp")
width: Screen.desktopAvailableWidth
height: Screen.desktopAvailableWidth
visible: true
opacity: 1.0
contentOrientation: Qt.LandscapeOrientation
color: "black"
UeKeypad
{
id: ueLoginKeypad
} // ueLoginKeypad
StatusBar
{
id: ueStatusBar
RowLayout
{
spacing: 8
UeStatusIndicator
{
id: ueStatusIndicatorDatabaseConnected
ueParamImageStatusOn: "qrc:///ueIcons/icons/ueDbConnectionOk.png"
ueParamImageStatusOff: "qrc:///ueIcons/icons/ueDbConnectionError.png"
} // ueStatusIndicatorDatabaseConnected
} // RowLayout
} // ueStatusBar
} // ueWindowMain
And here is screenshot:
As you can see, I've added QML StatusBar into QML ApplicationWindow, but StatusBar is not positioned in the lower part of ApplicationWindow, but in upper. Why?

This may give you a hint:
ApplicationWindow {
statusBar: StatusBar {
RowLayout {
anchors.fill: parent
Label { text: "Read Only" }
}
}
}

Related

Want to connect QML types across the QML files in PyQt6

This is a simple example of what I want to do.
// main.qml
import QtQuick
import QtQuick.Layouts
import QtQuick.Controls
import QtQuick.Controls.Material
ApplicationWindow {
visible: true
width: 640
height: 480
title: "Example App"
Material.theme: Material.Dark
MyLabel {
id: idMyLabel
anchors.centerIn: parent
}
MyButton {
anchors.top: idMyLabel.bottom
anchors.horizontalCenter: parent.horizontalCenter
}
}
// MyLabel.qml
import QtQuick
import QtQuick.Layouts
import QtQuick.Controls
import QtQuick.Controls.Material
RowLayout {
spacing: 40
Label {
id: idInnerLabel1
text: "Label 1"
}
Label {
id: idInnerLabel2
text: "Label 2"
}
Label {
id: idInnerLabel3
text: "Label 3"
}
}
// MyButton.qml
import QtQuick
import QtQuick.Layouts
import QtQuick.Controls
import QtQuick.Controls.Material
Page {
Button {
text: "Change"
onClicked: idInnerLabel2.text = "Changed"
}
}
But, I got an error when I run this example.
ReferenceError: idInnerLabel2 is not defined
I wanted to communicate between nested QML files. Putting them together in one file worked fine. So I was confused and I couldn't understand its inner working.
How can I resolve this issue?
Since both MyButton and MyLabel appear in main.qml the simplest solution would be to create a property in main.qml that both can access.
import QtQuick
import QtQuick.Controls
Page {
property string txt1: "Label 1"
property string txt2: "Label 2"
property string txt3: "Label 3"
MyLabel {
id: idMyLabel
anchors.centerIn: parent
}
MyButton {
anchors.top: idMyLabel.bottom
anchors.horizontalCenter: parent.horizontalCenter
}
}
// MyLabel.qml
import QtQuick
import QtQuick.Layouts
import QtQuick.Controls
import QtQuick.Controls.Material
RowLayout {
spacing: 40
Label {
text: txt1
}
Label {
text: txt2
}
Label {
text: txt3
}
}
// MyButton.qml
import QtQuick
import QtQuick.Layouts
import QtQuick.Controls
import QtQuick.Controls.Material
Page {
Button {
text: "Change"
onClicked: txt2 = "Changed"
}
}
You can Try it Online!

React-navigation: Increase height of the bottom tab navigation?

I created a simple tab navigation for a React Native app using react-navigation. It works fine, but I can't seem to adjust the height of it. It'll only go to a max of about 80, I need it to be about 150% of the current height, maybe double.
Does anyone know how to increase the height of the tab nav (preferably without creating about 6 more js files? ) I only have a limited period to fix it as I'd like.
Below is the nav code as-is
import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import { createBottomTabNavigator, createAppContainer } from "react-navigation";
import HomeScreen from './screens/HomeScreen';
import AboutScreen from './screens/AboutScreen';
import SettingsScreen from './screens/SettingsScreen';
export default class App extends React.Component {
render() {
return <AppContainer />;
}
}
const AppNavigator = createBottomTabNavigator({
Home: {
screen: HomeScreen
},
About: {
screen: AboutScreen
},
Settings: {
screen: SettingsScreen
}
}, {
initialRouteName: "Home"
});
const AppContainer = createAppContainer(AppNavigator);
Thanks
As said in the docs, you just need to add screenOptions={tabBarStyle:{height:100}}
For example:
bottomNavigatorConfigs = {
initialRouteName: "HomeScreen",
screenOptions: {
tabBarStyle: { height: 300 },
},
};
This is an example of the bottomNavigatorConfigs (tested) and working.
Where bottomNavigatorConfigs is used like this:
createBottomTabNavigator(bottomRoutesConfig, bottomNavigatorConfigs);
Source: https://reactnavigation.org/docs/bottom-tab-navigator/#options
Be careful with an iPhone's home indicator as you need to take account of the extra space at the bottom of the iPhone when setting absolute height.
import { useSafeAreaInsets } from 'react-native-safe-area-context';
...
export const Navigation = () => {
const insets = useSafeAreaInsets();
return (
<NavigationContainer>
<Tab.Navigator
tabBarOptions={{
style: {
height: 60 + insets.bottom,
...
},
tabStyle: {
height: 60,
...
},
...
}}>
...
tabBarOptions: {
style: {
height: '50%',
}
}
try that may be working.
With react navigation 6 you can just use:
tabBarStyle : {
height: 150,
...
}
screenOptions={
{
headerShown:false,
tabBarActiveTintColor:Colors.primary,
tabBarInactiveTintColor:Colors.primary2,
tabBarStyle: { height: 60 }
}
}

Attribute selectors in emotion

The following code customizes the google maps DrawingManager crosshair cursor. It works but I would like to be able to pass an svg cursor as a prop. I was trying to get it working using emotion but couldn't find anything similar in the emotion docs and my attempts failed. Can it be done in emotion?
Code: There are really only two relevant lines here (indicated) - the rest is given for context.
import React, { useEffect, useContext } from 'react'
import { GoogleMapContext, MapBox } from '#googlemap-react/core'
import ThemeSwitcher from './theme-switcher'
import styles from './styles/styles'
import './map.css' <--------------------------------------------------
export default function Map(props) {
const { state: { map } } = useContext(GoogleMapContext);
useEffect(() => map && map.setOptions({ draggableCursor: props.cursor }));
return <>
<MapBox
className='crosshair-cursor' <---------------------
apiKey={process.env.REACT_APP_GMAPS}
opts={{
center: { lat: -37.815018, lng: 144.946014 },
zoom: 11,
styles: styles[localStorage.getItem('mapTheme')],
}}
useDrawing
useGeometry
useGoogleApi
onClick={props.onClick}
onRightClick={props.onRightClick}
LoadingComponent={null}
/>
<ThemeSwitcher bindingPosition='TOP_LEFT' map={map} />
{props.children}
</>
}
map.css:
.crosshair-cursor [style*='crosshair'] {
cursor: url("https://i.stack.imgur.com/mA4e2.jpg?s=48&g=1")24 24, crosshair !important;
}
My attempt:
import React, { useEffect, useContext } from 'react'
import { GoogleMapContext, MapBox } from '#googlemap-react/core'
import ThemeSwitcher from './theme-switcher'
import styles from './styles/styles'
import './map.css'
import {css} from '#emotion/core'
const cursor = css`[style*='crosshair'] {
cursor: url("https://i.stack.imgur.com/mA4e2.jpg?s=48&g=1")24 24, crosshair !important;
}`
export default function Map(props) {
const { state: { map } } = useContext(GoogleMapContext);
useEffect(() => map && map.setOptions({ draggableCursor: props.cursor }));
return <>
<MapBox
// className='crosshair-cursor'
css={cursor}
apiKey={process.env.REACT_APP_GMAPS}
opts={{
center: { lat: -37.815018, lng: 144.946014 },
zoom: 11,
styles: styles[localStorage.getItem('mapTheme')],
}}
useDrawing
useGeometry
useGoogleApi
onClick={props.onClick}
onRightClick={props.onRightClick}
LoadingComponent={null}
/>
<ThemeSwitcher bindingPosition='TOP_LEFT' map={map} />
{props.children}
</>
}

Angular2 Component listen when parent's resize change

I have a requirement in which I want to change properties of a child component depending on the size of its parent component though a method call. The issue I am running into is that the only resize event I can listen to is that of the window, which doesn't help as the window size is not changing, only the parent component is due to a side panel div opening and closing.
The only possibility I can see at the moment is to have some sort of polling in which we within the child component itself that checks if its width has changed every x amount of time.
Thanks for your help!
You are correct that you can't get the resize event on a div (without installing some js extension). But something like this works.
The Parent Component:
import {Component, AfterContentInit, ElementRef} from '#angular/core';
import { ChildComponent } from "./ChildComponent";
export interface IParentProps {
width: number;
height: number;
}
#Component({
selector: 'theParent',
template: `text text text text text text
text text text text text text
<the-child [parentProps]="parentProps"></the-child>`,
directives: [ChildComponent]
})
export class ParentComponent implements AfterContentInit {
sizeCheckInterval = null;
parentProps: IParentProps = {
width: 0,
height: 0
}
constructor(private el: ElementRef) {
}
ngAfterContentInit() {
this.sizeCheckInterval = setInterval(() => {
let h = this.el.nativeElement.offsetHeight;
let w = this.el.nativeElement.offsetWidth;
if ((h !== this.parentProps.height) || (w !== this.parentProps.width)) {
this.parentProps = {
width: w,
height: h
}
}
}, 100);
}
ngOnDestroy() {
if (this.sizeCheckInterval !== null) {
clearInterval(this.sizeCheckInterval);
}
}
}
The Child Component:
import {Component, Input, SimpleChange} from "#angular/core";
import { IParentProps } from "./ParentComponent";
#Component({
directives: [],
selector: "the-child",
template: `child`
})
export class ChildComponent {
#Input() parentProps: IParentProps;
constructor() {
this.parentProps = {
width: 0,
height: 0
}
}
ngOnChanges(changes: { [propName: string]: SimpleChange }) {
this.parentProps = changes["parentProps"].currentValue;
console.log("parent dims changed");
}
}

Get anchors to fill remaining area in the parent

I have a QML component called MyComponent and I have the following instantiations:
MyComponent {
id: rightComponent
SettingsScreenHeader {
id: settingsHeader
}
SettingsScreen {
id: settingsScreen
}
StackView {
id: settingsStack
anchors.fill: parent
initialItem: settingsScreen
}
}
SettingsScreenHeader and SettingsScreen are two other components. At the moment when I do anchors.fill: parent in the StackView object, it takes all the space and the header object gets obscured. Is there a way to tell it to fill all the remaining space in the parent?
Try using ColumnLayout:
MyComponent {
id: rightComponent
ColumnLayout {
anchors.fill: parent
SettingsScreenHeader {
id: settingsHeader
Layout.fillWidth: true
}
SettingsScreen {
id: settingsScreen
Layout.fillWidth: true
}
StackView {
id: settingsStack
Layout.fillHeight: true
Layout.fillWidth: true
initialItem: settingsScreen
}
}
}
See the documentation for further details.