Qt QInputDialog parameter list - c++

I am starting a Qt course this semester. Having looked at the official documentation as well as some on line examples I am confused by the parameter lists of the QInputDialog and QMessagebox classes.
Is there anywhere where one could find some decent info as to what to pass when creating the class / form?
Right now I have this by trial error
tempC = QInputDialog::getDouble(0, "Temperature Converter",
"Enter the temperature in Celsius to convert to Fahrenheit:", 1);
Looking at the official docs doesn't help a lot either (at least not for me yet) as it says this:
double d = QInputDialog::getDouble(this, tr("QInputDialog::getDouble()"),
tr("Amount:"), 37.56, -10000, 10000, 2, &ok);
as an example.
Any links will be much appreciated.

double d = QInputDialog::getDouble(this, tr("QInputDialog::getDouble()"),
tr("Amount:"), 37.56, -10000, 10000, 2, &ok);
A dialog will popup with parent the widget in which you are using this function. (this)
The dialog's title will be QInputDialog::getDouble() (tr is used in order to translate this string if you want using QtLinguist)
Inside the dialog will be a double spibox and a label
The label's string will be Amount:
The default value of the spinbox (what you see when the dialog popups) will be 37.56
The minimum value will be -10000 (you will not be able to set a value less than this)
The maximum value will be 10000 (you will not be able to set a value greater than this)
Two decimal point will be displayed, eg 3.478 will be displayed as 3.48.
If the user presses the Ok button then the ok argument will be set to true, otherwise it will be set to false
Check the documentation which includes an example for more details.

Related

MIT AppInventor list Error : Attempt to get item number 0, of the list [5]

" Select list item: Attempt to get item number 0, of the list [5]. The minimum valid item number is 1.
Note: You will not see another error reported for 5 seconds. "
Hey Guys,
The message on top appear when the app open the app not crashing but I need to click somewhere on screen few times till it disappear..
The idea is to search a value of var 'UID' in firebase.database and when it found it I need to get the value of is brother key..
I want you please to help me to clear this message I tried a few ways to get the result but nothing yet..
Thanks a lot for helpers :)
When Screen Open.
This is how I tried to get the uid && employeeKey.
for your help me I set var 'UID' = to uid value of employee number 1
'UID' get the value from firebase.auth form on screen 1..
The index in list block returns 0, if the "thing" has not been found in the list and in this case you are trying to get the value from the 0th item from the empKey list, which does not make sense.
Therefore you will have to add an if statement... if the returned index is 0, then do not search for the empKey.
Btw. the better place to ask questions like this would be the MIT App Inventor community...

Checkbuttons using dictionary will not update values

Folks,
So I've been working on a little GUI using Tkinter for a capstone project, and given the circumstances, I've only been programming for about two weeks before I was thrown into this, so I'm still a newbie.
My issue today is that I cannot manage to get my checkbutton dictionary to update values; the output for my checkbutton is always 0 or False. The code is as follows:
...
datatype= {'Joint Angle' : 0,
'Joint Acceleration' : 0,
'Ground Reaction Force' : 0,
'Muscle Activation' : 0
}
for measure in datatype:
datatype[measure] = IntVar()
dt_cb = Checkbutton(root, text=measure,
variable=datatype[measure],command = enable_location_state)
dt_cb.grid(column=0, sticky='W', padx=20)
dt1 = datatype['Joint Angle'].get()
dt2 = datatype['Joint Acceleration'].get()
dt3 = datatype['Ground Reaction Force'].get()
dt4 = datatype['Muscle Activation'].get()
...
So I tried periodically printing values throughout the code and I continued to get 0 as soon as I booted the GUI, and after that, no matter what I clicked, the numbers did not update. I read that I should try BooleanVar() and StringVar() instead, but neither of those worked. The code is based off of another bit of code I found somewhere on stackoverflow, though I cannot remember exactly where.
I tried making it a list rather than a dictionary in order to overcome my problem because I was successful with lists previously, but the list created only a single checkbutton for all of those and I was unable to differentiate what is what.
The command enable_location_state configures other checkbuttons, and is as follows:
def enable_location_state():
if dt1 == 1 or dt2 == 1:
ja_cb.configure(state=ACTIVE)
if dt3 == 1:
grf_cb.configure(state=ACTIVE)
if dt4 == 1:
emg_cb.configure(state=ACTIVE)
Your problem is that you are getting the values of the IntVar only once: at the same moment you create your buttons. Move your .get() statements to the beginning of the enable_location_state() function. That way, every time your checkbutton is clicked, the function will check on (i.e., .get()) the value of the IntVar.

COM IContextMenu::InvokeCommand - matching LPCMINVOKECOMMANDINFO::lpVerb to item

I have created a shell extension for windows with COM, however I seem to fail to properly match the ids of items I add in the overload of IContextMenu::QueryContextMenu with what I receive in the overload of IContextMenu::InvokeCommand. In my code I use InsertMenu and InsertMenuItem (as far as I understood they do the same, but the latter has some more features?). However I'm not sure which arguments passed to InsertMenu/InsertMenuItem correspond to what I must be looking for in LPCMINVOKECOMMANDINFO::lpVerb. I need some way to easily know that when I add items x, y, z to a context menu, I can then know exactly which one of x, y or z has been clicked.
EDIT: It seems that the verb equals the number from top to bottom of the item in the current menu/submenu. However I have two sub-menus each with x amount of items, so they have the same IDs of 1,2,3. How do I set custom IDs or something?
Firstly you should define an enum that holds the command IDs for your menu items, e.g.
enum {
CMDID_FIRST = 0,
CMDID_DOSOMETHING = CMDID_FIRST,
CMDID_DOSOMETHINGELSE,
CMDID_LAST,
};
These ID values need to start from 0.
In your IContextMenu::QueryContextMenu implementation:
when you add your menu items you need to give each of them an ID by setting the MIIM_ID flag in the MENUITEMINFO.fMask field, and setting the MENUITEMINFO.wID value.
give each of your menu items an ID derived from its command ID as defined above, plus the value of idCmdFirst which is passed into QueryContextMenu. E.g. the "Do Something" menu item would have MENUITEMINFO.wID set to idCmdFirst + CMDID_DOSOMETHING, and "Do Something Else" would have MENUITEMINFO.wID set to idCmdFirst + CMDID_DOSOMETHINGELSE.
the return value from QueryContextMenu needs to be MAKE_HRESULT(SEVERITY_SUCCESS, FACILITY_NULL, x) where x is the ID of the highest-numbered item you added plus 1 (alternatively, if all items were sequentially numbered, the total number of items). Basically, you're telling the host which menu item ID values are now in use so that no other context menu extensions add items that clash with yours. In the above example, you'd return MAKE_HRESULT(SEVERITY_SUCCESS, FACILITY_NULL, CMDID_LAST).
In IContextMenu::InvokeCommand:
test if lpVerb (or lpVerbW) is an integer value using the IS_INTRESOURCE macro.
if so, the command ID can be found in the low word. E.g, if the user selected "Do Something Else", you would find that LOWORD(lpVerb) == CMDID_DOSOMETHINGELSE.

Line Edit setText function Qt

I have a LineEdit which I want it to present a float value. I want the float value to have 2 digits precision so I used number function like this:
float tax = value * 0.23;
Qstring strTax = QString::number(tax, 'f', 2);
qDebug() << strTax;
ui->leTax->setText(strTax);
The thing is that while in console the value is printed with 2 digits precision, the widget prints all the decimal digits which might be 3 or more (depends on the value). Is there a way to fix it? I am using Qt 5.0.
So this is the accepted answer. I finally solved my problem. The onTextUpdate had to update two more LineEdits one containing the Tax and one containing The total amount. But the one containing the totalAmount also emitted the onTextChanged to update the net value and the Tax LineEdits, without rounding the values(I Was careless!!). So I corrected the totalAmount's onTextChanged. I also updated it to check if it has focus so to know if it is its turn to update the other LineEdits or not :). The point was that someone could edit the netValue line edit and that would update the tax and total amount or someone would enter the totalAmount and that automatically would update the net Amount and tax field. Everything working now. Thank you all for answering!!
I do not have a float-version for QString::number(), so maybe try cast-to-double
ui->leTax->setText(QString::number((double)tax, 'f', 2));
But since qDebug() is already showing the correct value, you probably change your strTax somewhere else in the code.
setValidator might be your solution. Click here and here
void QLineEdit::setValidator ( const QValidator * v )
Sets this line edit to only accept input that the validator, v, will accept. This allows you to place any arbitrary constraints on the text which may be entered.
Also, Set the number of decimal places with setDecimals().
So, it should looks like this :
// bottom (-999.0), top (999.0), decimals (2)
lineEdit->setValidator(new QDoubleValidator(-999.0, 999.0, 2, lineEdit));

QDoubleValidator is not working?

I'm trying to apply validator in a line edit box in Qt 4.2 and it is not working:
QDoubleValidator *haha= new QDoubleValidator(this);
haha->setBottom(0.00);
haha->setDecimals(2);
haha->setTop(100.00);
get_line_edit()->setValidator(haha);
or
QDoubleValidator *haha= new QDoubleValidator(0.00,100.00,2,this);
Neither way, I can still enter what ever value I want.
But if I switch to QIntValidator, it works!
So I went onto Google and did a bit search, and many people used to having the same issue. Is it a bug? or there should be some other set up I should do?
Just tripped over this one. Try setting the QDoubleValidator notation to:
doubleValidator->setNotation(QDoubleValidator::StandardNotation);
The validator documentation says that it returns "Intermediate" from "validate" when the input is an arbitrary double but out of range.
You need to distinguish intermediate input and the final input the user wants to submit by use of a line edit control (e.g. by emitting the "returnPressed" signal). If the user typed "10000" that is still a valid intermediate input for a number between 0 and 100 because the user can prefix this input with "0.".
You have to set notation to your validator
QLineEdit *firstX;
QDoubleValidator* validFirstX = new QDoubleValidator(-1000, 1000, 3, ui.firstX);
validFirstX->setNotation(QDoubleValidator::StandardNotation);
then it works but not fully correct. Interesting part is that it controls the digit numbers not number itself. For example, In this example, you can enter to QLineEdit 1000 either 9999.
&& ( input.toDouble() > top() || input.toDouble() < bottom())
This example works fine in 4.8. It doesn't look like its changed since 4.2 so I suspect the problem lies in how you are creating your QLineEdit. This is the relevent code from that example.
QLineEdit* validatorLineEdit;
validatorLineEdit = new QLineEdit;
validatorLineEdit->setValidator( new QDoubleValidator(-999.0, 999.0, 2, validatorLineEdit));
How have you created your line edit?
To clarify, use QDoubleValidator::setNotation(QDoubleValidator::StandardNotation)
Example:
QDoubleValidator* doubleValidator = new QDoubleValidator(-999.0, 999.0, 2, validatorLineEdit);
doubleValidator->setNotation(QDoubleValidator::StandardNotation);
validatorLineEdit->setValidator(doubleValidator);
If you set a validator to a QLineEdit then you can use the function hasAcceptableInput() to check whether inputed value is valid or invalid. For example:
if (!ui->lineEdit_planned_count_vrt->hasAcceptableInput())
{
slot_show_notification_message("EDIT_PLAN_COUNT_VRT", notification_types::ERROR, INVALID_INPUTED_VALUE);
return;
}
bool isOk = false;
double value = ui->lineEdit_planned_count_vrt->text().toDouble(&isOk);
//do something with the value here....