Showing negative values on progress bar in qt - qt5

I have 8 different progress bar. In the code below, im showing the positive values of my array. I want to display negative values also. How can i do it?
When i put else and write the other progress bar on gui, it didnt work true
if(dizi[1] > 0 || dizi[2] > 0 || dizi[3] > 0 || dizi[4] > 0)
{
ui->progressBarAx->setValue(dizi[1]);
ui->progressBarAy->setValue(dizi[2]);
ui->progressBarBx->setValue(dizi[3]);
ui->progressBarBy->setValue(dizi[4]);
}

You could use the method setFormat(const QString &format) to generate the text you need.
Example:
ui->progressBar->setValue(5);
ui->progressBar->setInvertedAppearance(true);
ui->progressBar->setFormat(QString("-") + QString("%p"));
ui->progressBar_2->setValue(51);
ui->progressBar_2->setInvertedAppearance(true);
ui->progressBar_3->setValue(5);
ui->progressBar_3->setFormat(QString("-") + QString("%p%")); //with %
ui->progressBar_3->setInvertedAppearance(false);
ui->progressBar_4->setValue(51);
ui->progressBar_4->setInvertedAppearance(false);
The method setInvertedAppearance is also interesting to show the progress inverted.

Related

macOS Sierra: Emulate Mouse Down and Up

after an update to Sierra I had to find that Karabiner is not working anymore, which could emulate pointer clicks really well.
Any chance to get that via Swift or Apple Script or Obj.C ?
Background: Using Karabiner(and seil) I could bind caps-lock + d down and up to mouse down and up and in between the trackpad movement was understood. My trackpad is not processing keypress anymore but works still fine for pointer moves.
Answering myself, hacked it in hammerspoon. Was quite tricky to get chrome select working, maybe it saves somebody an hour or two:
1 ~/.hammerspoon $ cat init.lua
--[[ Left Keyboard Mouse (alt-d)
The main problem was to get chrome based apps select text when we drag via
keyboard.
You MUST return true always in the handle_drag otherwise it fails to select.
FF works, terminal works, chrome apps (atom, ...) don't.
But true is preventing further processing of the drag coords,
hs.mouse.getAbsolutePosition remains constant while dragging (!)
=> i.e. we MUST calc them via DeltaX, DeltaY, see below.
--]]
hs.alert.show("Config loaded")
-- all mechanics stolen from here:
-- local vimouse = require('vimouse')
-- vimouse('cmd', 'm')
now = hs.timer.secondsSinceEpoch
evt = hs.eventtap
evte = evt.event
evtypes = evte.types
evp=evte.properties
drag_last = now(); drag_intv = 0.01 -- we only synth drags from time to time
mp = {['x']=0, ['y']=0} -- mouse point. coords and last posted event
l = hs.logger.new('keybmouse', 'debug')
dmp = hs.inspect
-- The event tap. Started with the keyboard click:
handled = {evtypes.mouseMoved, evtypes.keyUp }
handle_drag = evt.new(handled, function(e)
if e:getType() == evtypes.keyUp then
handle_drag:stop()
post_evt(2)
return nil -- otherwise the up seems not processed by the OS
end
mp['x'] = mp['x'] + e:getProperty(evp.mouseEventDeltaX)
mp['y'] = mp['y'] + e:getProperty(evp.mouseEventDeltaY)
-- giving the key up a chance:
if now() - drag_last > drag_intv then
-- l.d('pos', mp.x, 'dx', dx)
post_evt(6) -- that sometimes makes dx negative in the log above
drag_last = now()
end
return true -- important
end)
function post_evt(mode)
-- 1: down, 2: up, 6: drag
if mode == 1 or mode == 2 then
local p = hs.mouse.getAbsolutePosition()
mp['x'] = p.x
mp['y'] = p.y
end
local e = evte.newMouseEvent(mode, mp)
if mode == 6 then cs = 0 else cs=1 end
e:setProperty(evte.properties.mouseEventClickState, cs)
e:post()
end
hs.hotkey.bind({"alt"}, "d",
function(event)
post_evt(1)
handle_drag:start()
end
)
and alt I mapped to capslock via karabiner elements.

PHP do while with multiple while conditions

I'm hoping somone might be able to help me here. I've had a look and found someone who has had he same issue:
Do-While Loop with Multiple Conditions
However I've checked and cannot see where i'm going wrong
Here's my code:
$x=0;
$y=0;
do {
$x = rand(0,5);
$y++;
} while ($x!=5 || $y<=5);
and so I was expecting the following: Either the code to stop when X was not == 5 OR y was more than 5. However the result i got was x=5 and y=>5
To put the theory to the test i changed my code to:
$x=0;
$y=0;
echo'<br />--x-y';
do {
$x = rand(0,5);
$y++;
echo'<br />--'.$x.'-'.$y;
if($y>5)
echo"-I should finish here";
} while ($x!==5 || $y<=5);
echo "<br />x=".$x;
echo "<br />y=".$y;
and in one instance i ended up with :
--x-y
--5-1
--3-2
--4-3
--4-4
--2-5
--4-6-I should finish here
--1-7-I should finish here
--3-8-I should finish here
--3-9-I should finish here
--3-10-I should finish here
--3-11-I should finish here
--5-12-I should finish here
x=5
y=12
Any suggestions as to where i'm going wrong?
You want to stop when (X = 5 or Y > 5). The condition inside while is for continuing, so you have to inverse the condition to: (X != 5 AND Y <= 5)
De Morgan Laws

Get marked range from NSTextInputContext

I was trying to clean up deprecation warnings of a certain project and the snippet of code looked like:
NSInputManager* im = [NSInputManager currentInputManager];
if (im && [im markedRange].length > 0) return NO;
I got this far:
NSTextInputContext* im = [NSTextInputContext currentInputContext];
if (im && [im /* What goes here? */].length > 0) return NO;
I am trying to get the marked range of the NSTextInputContext. How would I go about doing that?
This should work:
NSTextInputContext* context = [NSTextInputContext currentInputContext];
id<NSTextInputClient> client = context.client;
if (client && client.markedRange.length > 0) return NO;
The client is usually the text view with the focus, so the first responder of the key window. So, you can maybe bypass looking it up this way and just go straight to the text view.

Shopping cart doesn't update (unless I refresh page)

When I click 'Add to Cart' for a product, the cart doesn't update (unless you refresh the page). I've set the freeshippingtranslation to zero (see code below) but still not updating.
Can anyone help with this issue please? I use Prestashop 1.5.5 and my site is www.ayereadytshirts.com
if (parseFloat(jsonData.shippingCostFloat) > 0 || jsonData.nbTotalProducts < 1) $('.ajax_cart_shipping_cost').text(jsonData.shippingCost);
else if (typeof(freeShippingTranslation) != '0')
$('.ajax_cart_shipping_cost').html(freeShippingTranslation);
freeShippingTranslation is not defined
In comparsion you should use instead of
else if (typeof(freeShippingTranslation) != '0')
such a way
else if (typeof freeShippingTranslation === undefined)

3Ds MAx Script for Reading Pixels from an image

We are trying to read the pixels from an uploaded Bitmap image, yet the line
aBrightness = (0.2126*aPixel[1].red) + (0.7152*aPixel[1].green) + (0.0722*aPixel[1].blue) always gives an error saying "Unknown property: "red" in undefined".
Our current script is:
aBitmap = selectBitMap caption:"Select a Bitmap"
Print(aBitmap.height)
Print(aBitmap.width)
aLength = aBitmap.height
aWidth = aBitmap.width
for i = 0 to (aLength - 10) by 10 do
(
for j = 0 to (aWidth - 10) by 10 do
(
Print(i)
Print(j)
aPixel = getPixels aBitmap [i,j] 1
aBrightness = (0.2126*aPixel[1].red) + (0.7152*aPixel[1].green) + (0.0722*aPixel[1].blue)
aBox = box pos:[i,j,0] width:0.1 length:0.1 height:aBrightness
)
)
We would really appreciate any help regarding this script.
You have your coordinates wrong. The X value goes first.
It should be
APixels = Getpixels aBitmap [j, i] 1
You can check to see if aPixel is undefined before using it.
aPixel = getPixels aBitmap [i,j] 1
if (aPixel == undefined) do ( format "ERROR!!! [%,%]\n" i, j to:listener; continue )
aBrightness = (0.2126*aPixel[1].red) + (0.7152*aPixel[1].green) + (0.0722*aPixel[1].blue)
This might help you figure where the bug is. Often a function will return 'undefined' to a variable so you need to check if it is undefined. In this case, once you fix the bug, you can remove this type of code since you will have eliminated undefined behavior. Notice I used "format" instead of "print", this is much nicer to use for just a tiny extra code.
I see two suspicious things to check.
1) Most indexing in maxscript starts with 1 not 0. Check the documentation.
2) As Rotem pointed out, [x,y], not [y,x]