Im making a quiz. And it works like this, When you are answearing a question, you have to click some buttons with text on them to answear.
Example () = button
(G) (L) (O) (R) (I) (O) (U) (S)
And they have to spell glorious in that label correctly. And when they click the answear button, if the label says Glorious, they go to the next level. And if it says something else like Gloirous a message saying wrong answear will come up.
The problem :
The problem is that when i click a button, it adds text to the label.
But when i click another button the previous text dissapears and the new comes in.
I hope you guys understand what i want here! My english is not the best but if you want me to post some code i can do that !;)
You need to save previous text, and append new text to previous.
label.setText(label.text() + newText)
Try this:
[yourLabel setText:[yourLabel.text stringByAppendingString:#"%#", yourButton.text]];
Don't save the text to a label. Display the text in a label, but store it somewhere else.
Create an instance variable "answerString". Append each letter to the answer string, and then display the answer string to your label:
NSString *answerString;
Also, don't write a different IBAction method for each button. Put numeric tags on each button, attach them to the same method, and use the tag number to figure out which button was pressed. Something like this:
typedef NS_ENUM(NSInteger, buttonTags)
{
aButton = 100,
bButton = 101,
cButton = 102
//and so on for the entire alphabet, or for the letters you need
}
- (IBAction) buttonAction: (UIButton *) sender;
{
int button_id = sender.tag;
switch (button_id)
{
case aButton:
answerString = [answerString stringByAppendingString: #"a"];
break;
case bButton:
answerString = [answerString stringByAppendingString: #"b"];
break;
}
answerLabel.text = answerString
}
If you have buttons for all 26 letters it probably makes more sense to do some math on the tag numbers to get the unicode value of each character rather than having a switch statement with 26 cases, but you get the idea.
Related
Can someone help with my code searching for a partial match. I seem to be stuck here.
I would like type only the first few letters in a combo-box, hit enter, and store whatever I have typed as a variable. Then I want to check my variable against my list for the closest name that matches what I have typed. That becomes the new variable. How do I do this?
#singleInstance, Force
list =
(
Phone Numbers
Important People
Modification
Traffic Data
Tasks
Tracker
)
Gui, +alwaysontop
Gui +Delimiter`n
Gui, Add, ComboBox, vMyVar w200 h110 CHOOSE1 sort, % LIST
Gui, Add, Button, gGO Default x+5 w60 h20 , GO
Gui, show, y200, What do you want now?!
return
; Type first couple letters in box hit enter
GO:
Gui, Submit, nohide
Loop, parse, List, `n
{
; Search LIST for nearest match
;First partial match found
; MyVar := "A_loopfield"
MsgBox % InStr(A_loopfield, DoThis)
}
if MyVar = Phone Numbers
; Msgbox or Function ETC..
Try
#singleInstance, Force
list =
(
Phone Numbers
Important People
Modification
Traffic Data
Tasks
Tracker
)
Gui, +alwaysontop
Gui +Delimiter`n
Gui, Add, ComboBox, vMyVar w200 h110 CHOOSE1 sort, % LIST
Gui, Add, Button, gGO Default x+5 w60 h20 , GO
Gui, show, y200, What do you want now?!
return
; Type first couple letters in box hit enter
GO:
Gui, Submit, nohide
GuiControlGet, text_typed,, ComboBox1
StringLen, length, text_typed ; retrieves the count of how many characters are in the text typed
Loop, parse, List, `n
{
If (SubStr(A_LoopField, 1, length) = text_typed)
{
GuiControl, Choose, MyVar, %A_LoopField%
If (A_LoopField = "Phone Numbers")
MsgBox, Item 1
; ...
If (A_LoopField = "Traffic Data")
MsgBox, Item 6
break
}
}
return
I have an editable QComboBox that allows a user to type in a name for a new object and add it to the list. They can also edit names for existing items in the list. The problem is...say I have an item in the list called "AF" and I want to rename it to "ABCDEF". My first problem was if I placed the cursor in between 'A' and 'F' and started typing the cursor would jump to the end after typing 1 letter. So I would get "ABFCDE" unless I manually moved the cursor after each letter typed.
I fixed this by using
// slot connected to textEditChanged(QString) signal from QComboBox
void textChanged(const QString &text)
{
int pos = QComboBox->lineEdit()->custorPosition();
stuff...
QComboBox->setItemText(idx, text);
QComboBox->lineEdit()->setCursorPosition(pos);
}
and that works but unfortunately this caused a new problem.
setCursorPosition will subsequently select (highlight) all text beyond the new cursor location. So in the "AF" to "ABCDEF" example... I place the cursor between 'A' and 'F', type B and the cursor stays after "AB" and before 'F' but 'F' is highlighted. The next key press will replace the 'F' entirely. It will highlight more than 1 character, it highlights every character to the right of the cursor after it is moved.
I tried this to no avail.
QComboBox->lineEdit()->deselect();
I also tried this just as a test and it incorrectly exhibited the same behavior.
QComboBox->lineEdit()->moveCursorBackward(false,2);
The false parameter is supposed to not select the text the cursor moves past but it does anyway.
Anyone have any ideas on what's causing this?
I also encountered this problem. Here's what solved it for me for anyone interested:
First connect the signal but make sure it is queued!
connect(_comboBox, SIGNAL(editTextChanged(const QString&)), this, SLOT(slotTextChanged(const QString&)), Qt::QueuedConnection);
and for the slot:
void ViewListWidget::slotViewNameChanged(const QString& /*name*/) {
int index = _viewComboBox->currentIndex();
int cursorPosition = _viewComboBox->lineEdit()->cursorPosition();
// Since we are using a queued connection, get the current QLineEdit text
// instead of relying on the signal argument, which might be out of sync
QString name = _viewComboBox->lineEdit()->text();
_viewComboBox->blockSignals(true);
_viewComboBox->setItemText(index, name);
_viewComboBox->blockSignals(false);
_viewComboBox->lineEdit()->setCursorPosition(cursorPosition);
}
You should also probably disable auto-complete:
_comboBox->setCompleter(0);
I'm trying to use autohotkey to gather a chuck of data from a website and then click a certain spot on the website depending on what the text is. I'm able to get it to actually pick up the value but when it comes to the if statement it won't seem to process and yields no error message. Here is a quick sample of my code, there is about 20 if statement values so for brevity sake I've only included a few of the values.
GuessesLeft = 20
Errorcount = 0
;triple click and copy text making a variable out of the clipboard
;while (GuessesLeft!=0) part of future while loop
;{ part of future while loop
click 927,349
click 927,349
click 927,349
Send ^c
GetValue = %Clipboard%
if ( GetValue = "Frontal boss")
{
click 955,485
Guessesleft -= 1
}
else if ( GetValue = "Supraorbital Ridge")
{
click 955,571
Guessesleft -= 1
}
;....ETC
else
{
Errorcount += 1
}
;} part of future while loop
Any tips on what I might be doing wrong. Ideally I'd use a case statement but AHK doesn't seem to have them.
Wait a second -- you are triple clicking to highlight a full paragraph and copying that to the clipboard and checking to see if the entirety of the copied portion is the words in the if statement, right? And your words in the copied portion have quotes around them? Probably you will have to trim off any trailing spaces and/or returns:
GetValue = % Trim(Clipboard)
If that doesn't work, you may even have to shorten the length of the copied text by an arbitrary character or two:
GetValue = % SubStr(Clipboard, 1, (StrLen(Clipboard)-2))
Now, if I am wrong, and what you are really looking for is the words from the if statement wherever they may be in a longer paragraph -- and they are not surrounded by quotes, then you will want something like:
IfInString, Clipboard, Frontal boss
Or, if the quotes ARE there,
IfInString, Clipboard, "Frontal boss"
Hth,
on oneButtonClicked_(sender)
set faceNumber's setStringValue() to faceNumber's stringValue() & "1"
end oneButtonClicked_
I get this error: "Can’t make «class ocid» id «data optr000000000058B37BFF7F0000» into type list, record or text. (error -1700)"
faceNumber is a label and when the user clicks the button, I want to add string of "1" to it. So for example, if the user clicked the button 5 times
stringValue returns an NSString(wrong answer) CFString. You have to make a real AppleScript String to use it.
BTW your code set faceNumber's setStringValue() is not correct. The reasons are:
The Cocoa handlers are always using the underscore.
If you use the setter setStringValue() you don't need to use set x to
If you want to use setStringValue() you must give the parameter between the parentheses
Now put everything together:
on oneButtonClicked_(sender)
faceNumber's setStringValue_((faceNumber's stringValue) as string & "1")
end oneButtonClicked_
or (to have it clearer):
on oneButtonClicked_(sender)
tell faceNumber
set currentValue to (its stringValue) as string
setStringValue_(currentValue & "1")
end tell
end oneButtonClicked_
I hope you like the answer, after pressing the button twice you have an 11 at the end of the label.
Cheers, Michael / Hamburg
I have a GTK application that has a window with a treeview and a button. When the button is clicked I need to get the data from the first (and only) column of the selected row in the treeview.
This is the class for the columns:
class ModelColumns:
public Gtk::TreeModel::ColumnRecord{
public:
ModelColumns(){ add(m_port_name); }
Gtk::TreeModelColumn<Glib::ustring> m_port_name;
};
This is like in the example here but with only one column: http://www.lugod.org/presentations/gtkmm/treeview.html
This is the button click signal handler at the moment:
tvPorts is the treeview widget
tvPortsList is the listStore for the treeview
static
void on_btnPortSelectOK_clicked (){
Glib::RefPtr<Gtk::TreeSelection> selection = tvPorts->get_selection();
Gtk::TreeModel::iterator selectedRow = selection->get_selected();
//Now what?
//Need to get data from selected row to display it.
}
I have searched the documentation and many examples to try and find out what to do next but can't find any examples for gtkmm, I can only find examples for c or python implementations.
As far as I can tell, I need to get a TreeRow object from my iterator (selectedRow) how do I do this?
Thanks.
Update:
I am now using this code and it almost works.
The only problem is that it prints the previous selection.
The first time I select something and then press the button it prints only a new line. The second time it prints what was selected the first time, the third prints the second, etc.
Glib::RefPtr<Gtk::TreeSelection> selection = tvPorts->get_selection();
Gtk::TreeModel::iterator selectedRow = selection->get_selected();
Gtk::TreeModel::Row row = *selectedRow;
Glib::ustring port = row.get_value(m_Columns.m_port_name);
printf("\nselected port: %s", port.data());
This seems odd.
(m_Columns is an instance of the ModelColumns class)
Update 2:
Fixed the problem by adding fflush(stdout);
It all works now, thanks.
The docs say to simply dereference the iter to get the TreeRow:
Gtk::TreeModel::Row row = *iter; // 'iter' being your 'selectedRow'
std::cout<<row[0];