I am trying to pass a QLabel as a parameter to another function that is supposed to change the style of the label:
main
{
...
setSeatColor(ui->lblPan2Seat5B, 2);
}
void setSeatColor(QLabel& lbl, int i)
{
if(i == 1)
{
lbl.setStyleSheet("QLabel { background-color : blue; color : white; }");
}
else if(i == 2)
{
lbl.setStyleSheet("QLabel { background-color : red; color : white; }");
}
else if(i == 3)
{
lbl.setStyleSheet("QLabel { background-color : green; color : white; }");
}
else
{
lbl.setStyleSheet("QLabel { background-color : rgb(240,240,240); color : back; }");
}
}
The error in the function:
"No matching function for call to setSeatColor(QLabel*&,int)"
Your help is much appreciated!
You pass a QLabel pointer to a function that takes a QLabel&, so replace this call:
setSeatColor(ui->lblPan2Seat5B, 2);
with this one (notice the dereference operator *)
setSeatColor(*ui->lblPan2Seat5B, 2);
//you can use extra parentheses for your colleagues, so that they can understand what are you doing there: setSeatColor( *(ui->lblPan2Seat5B), 2); - that way is a little clearer that you intend to dereference the lblPan2Seat5B not the ui that is dereferenced by the -> operator
Related
How can I change navigationBarBackButton color in SwiftUI? (by
default it's blue)
How can I change navigationBarBackButton text in SwiftUI?
This is my code (an example):
struct ExercisesList : View {
var exercises : [Exercise]
var body: some View {
NavigationView {
List(self.exercises.identified(by: \.number)) {exercise in
NavigationLink(destination: ExerciseDetailView(exercise: exercise)) {
ExerciseRow(exercisE: exercise)
}
}
.navigationBarTitle(Text("Exercises"))
}
}
}
By default, the navigationBarBackButton in "ExerciseDetailView" has a text of Exercise and color of blue.
My question is how can I manipulate these two?
Here is a solution. Hope it will help. In this way, you can use custom UIColor also.
struct ExercisesList : View {
var exercises : [Exercise]
var body: some View {
UINavigationBar.appearance().tintColor = UIColor.red
return NavigationView {
List(self.exercises.identified(by: \.number)) { exercise in
NavigationLink(destination: ExerciseDetailView(exercise: exercise)) {
ExerciseRow(exercisE: exercise)
}
}
}
.navigationBarTitle(Text("Exercises"))
}
}
Currently, No direct methods are available for that(XCode 11 beta 3).
However You can use UINavigationBar method for that,
see below code :
struct ExercisesList : View {
var exercises : [Exercise]
init() {
//navigationBarBackButton color will change//
UINavigationBar.appearance().tintColor = .purple
// you can also set backgroundColor//
UINavigationBar.appearance().backgroundColor = .white
}
var body: some View {
NavigationView {
List(self.exercises.identified(by: \.number)) {exercise in
NavigationLink(destination: ExerciseDetailView(exercise: exercise)) {
ExerciseRow(exercisE: exercise)
}
}
.navigationBarTitle(Text("Exercises"))
}
}
}
I'm writing some sass to generate a set of icons based on a series of parameters. I have a function that analyses a set of variables and then returns a 'scenario' variable which in turn is used to filter the information taken from the nested map where everything is stored.
The code which retreives the information from the nested map is as follows:
#each $key-lv0, $lv0 in $icon-config {
#if($key-lv0 == $scenario) {
.icon{
#each $key-lv1, $lv1 in $lv0 {
#if type-of($lv1) != "map" {
#{$key-lv1}: $lv1;
}
#each $key-lv2, $lv2 in $lv1 {
#if type-of($lv2) != "map" {
.#{$key-lv1} {
#{$key-lv2}: $lv2;
}
}
#each $key-lv3, $lv3 in $lv2 {
#if($key-lv2 == "hover") {
.#{$key-lv1}:#{$key-lv2} {
#{$key-lv3}: $lv3;
}
} #else {
.#{$key-lv1} #{$key-lv2} {
#{$key-lv3}: $lv3;
}
}
}
}
}
}
}
}
... and this produces something along these lines:
.icon .icon-header {
background-color: #00a9f0;
}
.icon .icon-header:hover {
border-color: #040100;
}
... etc ...
... which is fine - repeated statements aside whicvh I'll deal with later.
The problem is the cap between ".icon" and ".icon-header". These classes will all be used in a single element and for the css to be interpretted correctly it needs to generate something like this:
.icon.icon-header {
background-color: #00a9f0;
}
.icon.icon-header:hover {
border-color: #040100;
}
I've tried bringing ".icon" down like so:
#if type-of($lv1) != "map" {
.icon#{$key-lv1}: $lv1;
}
and removing it from the top but sass rejects this with the following error:
Error: Properties are only allowed within rules, directives, mixin includes, or other properties.
It seems such a minor thing but it's nagging me and I can't seem to find an answer.
I want to check if the value provides to a function is a map or not.
#function func($props...) {
#if(is-map($props)) {
#return 'something';
}
#else {}
}
h1 {
color: func((color: red));
}
I'm getting the error:
(color: red) isn't a valid CSS value.
What am I doing wrong?
I personally never heard about any native Sass function called is-map. If you want to check the type of something, use the type-of function, so for example, checking for type-of($props) == map would solve your problem in this case.
#function func($props...) {
#if(type-of($props) == map) {
#return 'something';
}
#else {}
}
Because function returns map. Not a color as expected. Use map-get to get the access to properties values.
#return map-get($props, color);
And you have the variable argument. To get the first of arguments use nth($props, 1).
Sassmeister demo.
Update
If parameters in map are dynamic you can use this mixin instead of function.
#mixin print($declarations) {
#if $declarations {
#each $property, $value in $declarations {
#{$property}: $value
}
} #else {
#error "mixin print: $declarations is not specified";
}
}
Mixin sassmeister demo.
Completely new to QT and QML. I'm trying to set the color of a rectangle based on the relationship between the two propery doubles callValue and handRaiseXBB, but I get the error
unexpected token if"
and
expected a qualified name id
Could anyone tell me what I am doing wrong?
import QtQuick 2.0
Item{
id: hand
property double callValue: 0.0
property double handRaiseXBB: 100
property string handCallColor: "green"
property string handFoldColor: "grey"
Rectangle {
anchors.fill: hand
if (hand.callValue >= hand.handRaiseXBB) {
color: hand.handFoldColor
}
else {
color: hand.handCallColor
}
}
}
You can do it like this:
color: (hand.callValue >= hand.handRaiseXBB) ? hand.handFoldColor : hand.handCallColor
You could also make a function to calculate it and then assign the color property with the return value of the function:
function getHandColor()
{
var handColor = hand.handCallColor
if(hand.callValue >= hand.handRaiseXBB)
{
handColor = hand.handFoldColor
}
return handColor
}
color: getHandColor()
Another form to solve this is the following:
Rectangle {
...
color: {
color = hand.handCallColor
if(hand.callValue >= hand.handRaiseXBB)
color = hand.handFoldColor
}
...
}
But the form with ternary operator is a better form!
QML is "based" in javascript, then i belive that all itens are javascript objects, how to:
var Rectangle: {
color: "red",
id: "id",
//then we can do this
setColor: function(_color) {this.color = _color}
}
How do I get this $_GET['ago'] variable to increment by 1
public function __construct($future=false) {
$GLOBALS['twd_helper']=&$this;
}
public function query_string($add, $remove=null) {
$qs_data = array();
parse_str($_SERVER['QUERY_STRING'], $qs_data);
$qs_data = array_merge($qs_data, $add);
if ($remove) {
foreach($remove as $key) {
if (isset($qs_data[$key])) {
unset($qs_data[$key]);
}
}
}
return http_build_query($qs_data);
}
public function filter_overnight () {
if (isset($_GET['tod']) && $_GET['tod'] == 'overnight') {
$overnight = $_GET['overnight'];
}
if (($_GET['ago'])) {
$_GET['ago'] ? $_GET['ago']++ : $_GET['ago'] = 0;
}
}
I want to change my URL to increase by 1 each time its clicked
guide?ago=1
guide?ago=2
guide?ago=3
etc
In the html, just do this:
Link Text
Your filter_overnight function is a bit odd too - I think it could be made more readable:
if ($_GET['ago'])
{
$_GET['ago'] = (int)$_GET['ago'] + 1;
}
else
{
$_GET['ago'] = 0;
}
Or with the ternary:
$_GET['ago'] = ($_GET['ago']) ? (int)$_GET['ago'] + 1 : 0
Without seeing the whole code, I'm not sure why filter_overnight is incrementing $_GET['ago'], but at a glance it appears to put an undocumented side effect into the function by changing a global value (which would also render the increment in the <a> pointless). The superglobals in PHP can be dangerous things - I find it best to treat them as immutable and copy values out of them vs working on them directly.