I have the following slider that currently goes from 1 to 2 in 12 steps on mouse wheel and keyboard arrows, what I want to make it do is to it takes 24 steps to go from 2 to 24?
QSlider *slider_speed = new QSlider;
slider_speed->setOrientation(Qt::Horizontal);
slider_speed->setTickPosition(QSlider::TicksAbove);
slider_speed->setRange(-12, 12);
slider_speed->setSingleStep(1);
slider_speed->setPageStep(4);
slider_speed->setTickInterval(12);
Ok. Before I do anything I should have checked the source code better :)
To change the steps I just had to change to range and tick interval to 24. And single step to 1. What confused me was a text label in the source code which would have shown a value better than 2.00 which messed me up since wasn't paying attention that that value was set my another function.
Related
when I use <LiquidCrystal.h library and lcd-write() it only show the first 16 char in the fist row and start in the 41st char in the second row.
I started with lcd.begin(16,2).
Here an example of the code.
The result of this code will be:
row 1: 0123456789112345
row 2: 4123456789
#include <LiquidCrystal.h>
LiquidCrystal lcd(2,3,4,5,6,7);
void setup() {
// put your setup code here, to run once:
lcd.begin(16, 2);
Serial.begin(9600);
lcd.print("0123456789");
lcd.print("1123456789");
lcd.print("2123456789");
lcd.print("3123456789");
lcd.print("4123456789");
}
void loop() {
}
Its that the expected functionality?
There are a way so I can get the 17th char be displayed in second row.
Yes, that is the expected behaviour. The library allows you to control HD44780-based LCD modules. This LCD controller can drive displays up to 40 character by 2 lines in size. When you use a smaller module, the lines are still stored in the same locations in the DDRAM: the first line starts at location 0, the second line starts at location 40. See the datasheet for more information:
https://www.sparkfun.com/datasheets/LCD/HD44780.pdf
You can use the entire memory and scroll left and right since the 16-character wide display is a window into the DDRAM. You can use the scrollDisplayLeft and scrollDisplayRight to shift the display left and right. These functions change which DDRAM address is used for the first character on the far left of the display. Both lines scroll in unison.
I'm not completely sure why your Arduino has this behaviour but you can pass a complete line in your case 16 characters every time you print and look how it works, also parsing in variables ant passing it to the .print method.
Another way is to set manually the data in the row that you want using the setCursor() method, this method helps you to move and print in the position that you want, it receives two parameters the column and the row, I'll let you the URL with more information.
https://www.arduino.cc/en/Tutorial/LiquidCrystalSetCursor
I have a int containing a value like this:
int CharY = 20;
And I want that value to increase with 1 until it is equal to lets say 50.
But I dont want it to do like this:
I would more likely make the value smoothly increase something like this:
How can I achive this like in picture number 2 without a ton of code and such?
If you are familiar with a little math, you should be able to understand the window function. So let's say 20 is the start point and 50 is the top(middle of window). Pick a function, decide the sample count, use a timer tick and sample a value from the function for every tick.
By the way, I find the welch window easiest.
Gokhan.
I have a Node named "Fruit" which contains 4 single frames for each fruit. It also contains a shadow, which should be the same for all fruits. I'm creating this node like this:
auto newFruit = CSLoader::createNode("Fruit.csb");
auto fruitAction = CSLoader::createTimeline("Fruit.csb");
newFruit->runAction(fruitAction);
Now when I'm creating this fruit I want to set a random frame:
fruitAction->gotoFrameAndPause(r + 1);
r is from 0 to 3.
However it doesn't work. It doesn't change frame at all. When I run debugging I can see correct frame number.
So I've tried different solution. I've made 4 1-frame animations named "a1", "a2", "a3" and "a4".
Then:
fruitAction->play("a" + to_str(r + 1), false);
Now I'm getting sometimes good sometimes not. Giving constant r continuously is giving me different results.
Only solution I've found is to make all animation 2-frames long (with 1 offset) so "a1": 0->1, "a2": 2->3, "a3":4->5, "a4":6->7, but this is too complicated to be worth using. Also it sometimes blinks first frame for a frame or few (so it looks very bad then).
Is it a bug or I'm doing something wrong?
After digging in cocos2d-x code it seems more troublesome than it looks.
There are 3 problems in current implementation:
1) when you won't play your animation it'll have playing property set to false so ActionTimeline::step won't even pass first if (checking if playing) and it'll never render another frame.
2) when you use gotoFrameAndPause _endFrame is never set (it's 0 by default) and because of that setCurrentFrame will always fail, because of this if:
if (frameIndex >= _startFrame && frameIndex <= _endFrame)
3) when you use "play" _startFrame and _endFrame are set between just this one particular animation and you won't be able to "jump" to frame outside it.
I've made a little workaround and put that in 3 macros:
#define CC_INIT_ACTION(__ACTION__) __ACTION__->gotoFrameAndPlay(0, __ACTION__->getDuration() + 1, 0, false); __ACTION__->pause()
#define CC_JUMP_ACTION_TO_FRAME(__ACTION__, __FRAME__) __ACTION__->setCurrentFrame(__FRAME__); __ACTION__->resume(); __ACTION__->step(0.0001f); __ACTION__->pause()
#define CC_JUMP_ACTION_TO_FRAME_BY_NAME(__ACTION__, __NAME__) int __FRAME__ = __ACTION__->getAnimationInfo(__NAME__).startIndex; CC_JUMP_ACTION_TO_FRAME(__ACTION__, __FRAME__)
CC_INIT_ACTION makes possible to jump to every frame.
CC_JUMP_ACTION_TO_FRAME jumps to particular frame number.
CC_JUMP_ACTION_TO_FRAME_BY_NAME jumps to first frame in particular animation.
Also step(0.0001f) in CC_JUMP_ACTION_TO_FRAME is necessary, because step sometimes calculates current frame wrong (maybe rounding problem, not sure).
Can this be done with SDL ?
What I mean is when you press F1 - "turn on the lights". When you press F1 for a second time - "turn off the lights", and so on.
A solution to this can be to keep a counter for the button and if it is pressed odd number of times - "turn on lights", if it is pressed even number of times - "turn off lights".
But if I have 12 buttons for different functions I don't think that's the optimal way to do it, because I will have to keep different counters for each of these 12 buttons.
Counter are not a bad idea, and I don't think that the optimal way too. If you use an int to do this, it only 4 byte per counter, so it's not that much.
But in my opinion, you can do this with a bool value, when the value is true, the button is active else, it's not. If will simplify your code too, because you will just need to implement a getter for your bool value, and you will be able to use it in your condition. On and off are binary option, because it's 0 or 1, so the bool represent that exactly.
And just for the conception of your software, you can make a class Button that contains that information and you just create an instance for each of your switches.
I use a QDial control for input time values in sec. How do I change the automatically added text that shows up in the middle of these dials?
EDIT: They come from the QtCurve style.
If there is no code in your program to explicitly display this integral value (in a signal/slot), then it may very well be your current Qt Style which does it. See the following examples of Qt styles to see that the display of this integer is usually NOT part of the QDial display:
http://qt-project.org/doc/qt-4.8/gallery-plastique.html
http://qt-project.org/doc/qt-4.8/gallery-cde.html
http://qt-project.org/doc/qt-4.8/gallery-gtk.html
http://qt-project.org/doc/qt-4.8/gallery-cleanlooks.html
http://qt-project.org/doc/qt-4.8/gallery-windowsvista.html
http://qt-project.org/doc/qt-4.8/gallery-macintosh.html
See: http://qt-project.org/doc/qt-4.8/qstyle.html for more info on styles.
You can also look in your program code for the following code:
QApplication::setStyle(...);
You could also check the following:
QT_STYLE_OVERRIDE environment variable
-style= argument passed to your program
If you still don't find how your style is set, then it may be the default style for your platform.
What does the following says ?
QStyle *currentStyle = QApplication::style();
qDebug() << currentStyle;
qDebug() << currentStyle->objectName();
qDebug() << currentStyle->metaObject()->className();
EDIT: I see you identified the style to be QtCurve.
Source is there: http://kde-look.org/content/download.php?content=40492&id=1&tan=23640920
And we can see that the style is responsible for displaying the value:
file: style/qtcurve.cpp, line: 7980
// Draw value...
#ifdef DIAL_DOT_ON_RING
drawItemTextWithRole(painter, outer.adjusted(sliderWidth, sliderWidth, -sliderWidth, -sliderWidth),
Qt::AlignCenter, palette, state&State_Enabled,
QString::number(slider->sliderValue), QPalette::ButtonText);
#else
int adjust=2*sliderWidth;
drawItemTextWithRole(painter, outer.adjusted(adjust, adjust, -adjust, -adjust),
Qt::AlignCenter, palette, state&State_Enabled,
QString::number(slider->sliderValue), QPalette::ButtonText);
#endif
From now on, you can either:
Recompile the style after disabling the faulty code (commenting or using a boolean option).
Ask the maintainer to provide an option to disable the display of the dial's value.
Assuming you mean sec as in seconds? You can work out the percentage of where the dial is relative to its full rotation and then apply that to the percentage of maximum seconds.
For example, if the dial goes from 0 to 360 and the current position is at 90, its percentage is
90 / 360 * 100 = 25%.
If your maximum value in seconds is 60, then 25 percent of 60.
25 / 100 * 60 = 15 seconds.
So the display would now show 15 seconds.