QDial change position indicator text - c++

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.

Related

QSlider change the number of increments/decrements when using the mouse wheel

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.

Fatal error: exception Graphics.Graphic_failure("Cannot open display ")

I was trying to run the code and it keeps showing the same error.
I start by compiling with ocamlc -o cardioide graphics.cma cardioide.ml and it appears to work, but then I do ./cardioide to execute it and the message Fatal error: exception Graphics.Graphic_failure("Cannot open display ") appears...
I've searched all across the internet and i can't find the solution, can someone please help me?
Thank you
open Graphics
let () = open_graph "300x20"
let () =
moveto 200 150;
for i = 0 to 200 do
let th = atan 1. *. float i /. 25. in
let r = 50. *. (1. -. sin th) in
lineto (150 + truncate (r *. cos th))
(150 + truncate (r *. sin th))
done;
ignore (read_key ())
Error message:
Fatal error: exception Graphics.Graphic_failure("Cannot open display ")
The string argument to the open_graph function is not the size or title, but actually implementation-dependent information that is passed to the underlying graphical subsystem (in X11 it is the screen number). In modern OCaml, optional arguments are passed using labels, but Graphics was written long before this feature was introduced to the language. Therefore, you have to pass an empty string there (if you don't want to pass any specific to implementation of the underlying graphical subsystem information), e.g.,
open_graph ""
will do the work for you in a system-independent way.
Besides, if you want to resize the window, then you can use the resize_window function. And to set the title, use set_window_title.
For the historic reference, the string parameter passed to the open_graph is having the following syntax (it is no longer documented, so there is no reason to believe that it will be respected):
Here are the graphics mode specifications supported by
Graphics.open_graph on the X11 implementation of this library: the
argument to Graphics.open_graph has the format "display-name
geometry", where display-name is the name of the X-windows display
to connect to, and geometry is a standard X-windows geometry
specification. The two components are separated by a space. Either
can be omitted, or both. Examples:
Graphics.open_graph "foo:0" connects to the display foo:0 and creates a
window with the default geometry
Graphics.open_graph "foo:0 300x100+50-0" connects to the display foo:0 and
creates a window 300 pixels wide by 100 pixels tall, at location (50,0)
Graphics.open_graph " 300x100+50-0" connects to the default display and
creates a window 300 pixels wide by 100 pixels tall, at location (50,0)
Graphics.open_graph "" connects to the default display and creates a
window with the default geometry.
Put a 'space' in the argument to get the window you want (should be 200 for your cardioide):
let () = open_graph " 300x200"
I met the same problem and it was because I used the Windows subsystem for linux(WSL) so it needs a XServer to run graphical application. And the Ubuntu Wiki For WSL helped solve the problem. I downloaded and installed MobaXterm (it has free community version!) and it automatically detects the WSL and runs it inside the app. Try the same code before and a graphical window will pop up!

How to change dateTimeFromText to only allow minutes%15 or disable manual text input?

I have extended QDateTimeEdit to do steps in intervals of 15 minutes by overwriting stepBy(int steps). So if a user scrolls up the minutes-section, the only choices they have are 0, 15, 30 and 45.
One problem appears if a user enters the dateTime manually, because then no validation takes place. I had a good look at: https://qt.gitorious.org/qt/qt/source/57756e72adf2081137b97f0e689dd16c770d10b1:src/gui/widgets/qdatetimeedit.cpp but to be honest, the dateTimeFromText method was a bit overwhelming.
I also found: http://qt-project.org/doc/qt-5/qt.html#InputMethodHint-enum but still not sure if that is of any help.
Is there any easy way to only allow dateTimes that have a minutes-section of 0, 15, 30 or 45? Or can I alternatively disable manual input?
You can use dateTimeChanged slot to manually control if input is divisible by 15. Also you can update the element with one of the closest permitted values.
if (dateTime.time().minute()%15 != 0) {
QTime t(dateTime.time().hour(),dateTime.time().minute()-dateTime.time().minute()%15,dateTime.time().second());
ui->dateTimeEdit->setTime(t);
}

Qt - how to detect line count increase after word wrapping?

I'm using a QPlainTextEdit control with word-wrapping active and I'm wondering how can I detect, in order to update a line counter, when a block of text gets wrapped (causing the number of lines to be incremented).
The underlying QTextDocument has a signal to detect when the block count changes, but not the corresponding one for line count changes.
Is it possible to detect word-wrapping and line count increase for a QTextDocument?
It's a little bit late but perhaps my answer can help somebody.
I had almost the same need in my company and I solved it like this:
// This example show how to get the visual number of lines
QPlainTextEdit *pte = new QPlainTextEdit();
pte->setAttribute(Qt::WA_DontShowOnScreen);
pte->show();
pte->setFixedWidth(50);
pte->setPlainText("Hello world!");
/* The next line return the number of necessary line
to display the text "Hello World!" with width of 50px */
int lineCount = pte->document()->documentLayout()->documentSize().height();
Best regards
I solved by using QAbstractTextDocument's signal documentSizeChanged:
void QAbstractTextDocumentLayout::documentSizeChanged ( const QSizeF &
newSize ) [signal]
This signal is emitted when the size of the
document layout changes to newSize. Subclasses of
QAbstractTextDocumentLayout should emit this signal when the
document's entire layout size changes. This signal is useful for
widgets that display text documents since it enables them to update
their scroll bars correctly.
I know the size of my font and getting the precise size of the new underlying document allowed me to count the lines (wrapped or not) of my text document.

Write information into empty window with c++

So I'm building this game engine thinggy, and found it to be VERY hard to create some kind of an overlay with debug information into the main game window with D3D11 or at all draw text, so I thought I'd create an other window to contain my debug data.
I got the window created fine and all, but I have no idea how to write my debug info into it. I do not want to use the windows form designer as that would have to convert my project into a CLR project which I do not want.
I have been googling now for 3 hours at least (honest) and tried various solutions but none of them really seemed practical to use/they were not working.
The debug info I'd like to write originates from global float values. An example would be CAM_POS_X which holds a floating point value which indicates at which X co ordinate the camera is currently at.
Something like this is desired:
|SiriusAlpha 0.1 Debug window_ |
|Current X position: CAM_POS_X|
|Current Y position: CAM_POS_Y|
|Current Z position: CAM_POS_Z|
|Current YAW: CAM_YAW______|
|Current PITCH: CAM_PITCH___|
|Current FPS: CUR_FPS_______|
All of these values are not nescessarily floating point variables. They could be strings, doubles, integers or even booleans.
If anyone would be willing to explain to me how to do this in D3D11 and I could skip the whole debug window schenennigans I'd be even happier.
Otherways, I'd be delighted if somebody could explain to me how this is done.
Have you tried TextOut()? Read the article on msdn. You should already have a device context, the rest is quick and easy.
The TextOut function writes a character string at the specified location, using the currently selected font, background color, and text color.
Printing to a string is trivial.
wchar buf[128];
swprintf(buf, "Current X Position: %f", CAM_X_POS);
TextOut(yourDC, screenXPos, screenYPos, &buf, sizeof(buf));
I haven't tested this, but from the MSDN documentation this should work fine.