I currently have a combobox which displays a list of numbers which are retrieved elsewhere and stored into the variable "test". Every time another number is set for "test", that number will be added into the combobox list.
Is there a way where I can use a CEdit text box instead of a CComboBox to display my numbers?
This is how I have coded the combobox.
CComboBox *pCombobox = (CComboBox *) (GetDlgItem(IDC_ComboBox));
strNumber.Format(_T("%d"),test);
pCombobox->AddString(strNumber);
Any help would be appreciated. Thank you.
Presuming you have an appropriate edit control placed on your dialog with ID IDC_Edit for example, then get the existing string, append the new value to it, replace with new string.
CString text;
GetDlgItemText(IDC_Text, text);
if (text.IsEmpty())
text.Format(_T("%d"), test);
else
text.AppendFormat(_T(",%d"), test);
SetDlgItemText(IDC_Text, text);
Related
I am making an image annotation system Using qrect and Simple text items.
I am trying to store the string values from the QGraphicssimpletext items into a JSON file to save and load the annotation boxes. The rectangles work fine but I cannot understand how to get a string value. This is the foreach I am trying to loop through for each item, and as the text items are children of the rectangles the position does not matter.
foreach(QGraphicsItem* item, items())
{
arrayPosX.push_back(item->x());
arrayHeight.push_back(item->boundingRect().height());
arrayWidth.push_back(item->boundingRect().width());
arrayPosY.push_back(item->y());
arrayAnnotation.push_back(item->?);
}
Both the simple text and rect items are added to the scene using
itemToDraw = new QGraphicsRectItem;
this->addItem(itemToDraw);
simpleTextToDraw = new QGraphicsSimpleTextItem;
this->addItem(simpleTextToDraw);
I would simply like to know how I could get the string values from the simple text item as to allow saving and loading of both strings and boxes, not just boxes which the current system can do.
You have to cast and verify that the pointer is not null:
// ...
arrayPosY.push_back(item->y());
if(QGraphicsSimpleTextItem* text_item = qgraphicsitem_cast<QGraphicsSimpleTextItem *>(item)){
arrayAnnotation.push_back(text_item->text());
}
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);
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.
I am using CCEditBox in the latest cocos2d-x 3.2 as textBox for user input.
now , i want to align text which i am typing in Textbox area , but it's always stays left align. i want to set it in the Center of my textBox.
I tried one Function named : setLabelAnchorPoint but it's not giving any effect to my label alignment. please help.
cocos2d::extension::Scale9Sprite *Playername_bgtemp = cocos2d::extension::Scale9Sprite::create("Name_bg.png");
auto _editName = EditBox::create(Size(1000,164), Playername_bgtemp);
Point absolutePosition = Point(ReferenceFrameSprite->getContentSize().width/2,4*ReferenceFrameSprite->getContentSize().height*0.20);
_editName->setPosition(absolutePosition);
_editName->setFontName("fonts/HelveticaLTStd-Cond_0.ttf");
_editName->setFontColor(Color3B::WHITE);
_editName->setLabelAnchorPoint(Vec2(0.0f,0.0f));
_editName->setPlaceHolder(" Name ");
_editName->setPlaceholderFontColor(Color3B::WHITE);
_editName->setPlaceholderFontName("fonts/HelveticaLTStd-Cond_0.ttf");
_editName->setMaxLength(10);
_editName->setReturnType(EditBox::KeyboardReturnType::DONE);
_editName->setFontSize(BgContentFontSize);
_editName->setDelegate(this);
bgFrameSprite->addChild(_editName,PopUpTag);
I did the trick with a text Label in the same position than the Editbox. I keep the Editbox with an empty string.
When start editing the edit box:
Hide the label.
Set the Editbox text with the label content.
When end editing the Editbox:
Set label text to Editbox content.
Show the label.
Set Editbox text to an empty string.
I'm trying to insert tag next to specific text.
I was get a knowhow to insert tag next to text..
It is to use Setsel() and ReplaceSel().
example,
char str = "< name >";
m_richedit.Setsel( position of start dragging of text, end position )
m_richedit.ReplaceSel( str, TRUE )
but, I don't know how to get position of start dragging of text in richEdit.
Is there anybody who has an idea?
Thank you.
You need to add the appropriate accelerator key like they explain here: Adding accelerators(shortcuts) in MFC - HOW? . Then in the handler of the accelerator key, use GetSelText, add your tags to the string you get and call ReplaceSel.