How do I change the background color of a page on a button click?

How do I change the background color of a page on a button click?

Как изменить фоновый цвет страницы по нажатию кнопки?

To be more precise. Here is the project.
There are three text boxes for specifying HSV colors and a button. When you press the button, the background color should change to the one that is obtained by the HSV system.
I do not know how to program in QT and do not quite understand what code to write. As far as I understand, for example, such a script sets the string parameter of the QColor function. In this case, the color is hex. But how can I be allowed to specify HSV? Text into variables and then somehow pass the QColor function, but it’s not clear to me how to do this. Please tell me. :sweat:
ups

Если быть более точным. Вот проект.
Есть три текстовых поля для указания цвета по системе HSV и кнопка. При нажатии на кнопку, цвет фона должен меняться на тот который получается по системе HSV.
Я программировать не умею на QT и не совсем понимаю какой код писать. На сколько я понял например такой скрипт устанавливает строковый параметр функции QColor. В данном случае цвет hex. А как же мне допустим указать HSV? Текст в переменные и потом передать каким-то образом функции QColor но для меня непонятно как это сделать. Подскажите пожалуйста.

Can you provide an example of several HSV colors? Is it a string or an array? Because in your screenshot the color is in HEX format.

Then I can send you a working example.

This is the screenshot generated by Flipabit :slight_smile:
Это на скриншоте код сгенерированный Flipabit :slight_smile:

I will try to explain.
The first text box indicates the tone (from 0 to 359)
The second text box indicates the saturation (0 to 100)
The third text box indicates the brightness (from 0 to 100)
(True, in Flipabit, brightness and saturation change values from 0 to 255 instead of 0 to 100. But that doesn’t matter now.)
hsv

So. I have three meanings. How can I specify them in the code?
I tried to figure out how to set color values in Qt in RGB, HSV and others, but in the Flipabit code window, write so that the script would not work for me.
Я попробую объяснить.
Первое текстовое поле указывает тон ( от 0 до 359)
Второе текстовое поле указывает насыщенность ( от 0 до 100)
Третье текстовое поле указывает яркость( от 0 до 100)
(Правда в Flipabit яркость и насыщенность меняют значения от 0 до 255 вместо 0 до 100. Но это сейчас не важно.)

Итак. Я имею три значения. Как мне их указать в коде?
Я пытался понять как в Qt задавать значения цвета в системе RGB, HSV и других, но в окне кода Flipabit написать так, что бы работал скрипт у меня не вышло.

That’s all I could write myself. Assign a value to a variable and return its value =)
Это всё, что я смог написать сам. Присвоить значение переменной и вернуть её значение =)
function () {
myColor = “#ff5e70af
return myColor
}
It worked for me. I couldn’t go on :laughing:
Это у меня сработало. Дальше я не смог

Yes, and one more question. In the Qt code, it is possible to set the color in the HSV system in a function, but no matter how many code examples I look, nowhere is the possibility of fractional values indicated. Is it possible?
Here is a screenshot from the 3D editor (I work in it). Perhaps this will make you understand what I’m talking about …
hsv2
Да, и ещё один вопрос. В коде Qt возможно в функции устанавливать цвет в системе HSV, но сколько бы примеров кода я не смотрел, нигде не указывается возможность дробных значений. Возможно ли это?
Вот скриншот из 3д-редактора (я в нём работаю). Возможно так Вам станет понятно о чём я говорю…

Here is the example
hsv_color.pma (6.0 KB)

image

Javascript function used:

function () {
  var h = document.childByName("H").content.text;
  var s = document.childByName("S").content.text;
  var l = document.childByName("V").content.text;

  s /= 100;
  l /= 100;

  let c = (1 - Math.abs(2 * l - 1)) * s,
      x = c * (1 - Math.abs((h / 60) % 2 - 1)),
      m = l - c/2,
      r = 0,
      g = 0, 
      b = 0; 

  if (0 <= h && h < 60) {
    r = c; g = x; b = 0;
  } else if (60 <= h && h < 120) {
    r = x; g = c; b = 0;
  } else if (120 <= h && h < 180) {
    r = 0; g = c; b = x;
  } else if (180 <= h && h < 240) {
    r = 0; g = x; b = c;
  } else if (240 <= h && h < 300) {
    r = x; g = 0; b = c;
  } else if (300 <= h && h < 360) {
    r = c; g = 0; b = x;
  }
  // Having obtained RGB, convert channels to hex
  r = Math.round((r + m) * 255).toString(16);
  g = Math.round((g + m) * 255).toString(16);
  b = Math.round((b + m) * 255).toString(16);

  // Prepend 0s, if necessary
  if (r.length == 1)
    r = "0" + r;
  if (g.length == 1)
    g = "0" + g;
  if (b.length == 1)
    b = "0" + b;

  return "#" + r + g + b;
}

The script editor in Flipabit uses JavaScript, not Qt. I found JavaScript example of color conversion function here: Converting Color Spaces in JavaScript | CSS-Tricks

Yes. It works in the example.

Thank you for the reporting. We’ll fix it soon;

This is incredible! What an inconsiderate fool I am! Thank you very much! True, HSL has a smaller color range than HSV. They are similar in mechanics in appearance, but not in essence. However, it is my task to swim in the seas of color spaces and transformations :slight_smile: The main thing. what did you show me how to use scripts and in what dialect. Thank you so much again!:star_struck:

Это невероятно! Какой же я невнимательный глупец! Спасибо Вам огромное! Правда, HSL имеет меньший цветовой диапазон чем HSV. Они схожи по механике внешне, но не в сути. Однако плавать в морях цветовых пространств и преобразовнаий уже моя задача :slight_smile: Главное. что Вы мне показали как применять скрипты и на каком диалекте. Огромное Вам спасибо ещё раз!


Back to Flipabit >
Copyright © 2018. Flipabit Team. All rights reserved.