Passing variables from one form to another in Qt - qt

I've got two forms, the mainform which opens up a dialog box that has a text box in it. How can I pass the text from the textbox back to the mainform? I've tried alot of different methods but I think I'm missing something simple. Thanks for any help.

The dialog box still exists after it closes. So you can, from the main form, do something like this:
QString text = subform->textEdit->text();
This assumes your dialog box is subform and the name you gave to the text edit box is textEdit. Make sure you make textEdit public in the designer.
If you don't want to make textEdit public, then you can add a getter to subform.

If you use the MVC pattern, you create the model object (container for your data) and pass to the text box to fill in the text value itself. When the dialog is closed, just read the value from the model and put it wherever you need it.

Related

Using links inside QTextEdit

ALL,
If I have a QTextEdit with the bunch of text and will want to insert a hyperlink in this text somewhere, will I get a handling of this hyperlink for free or I will have to write some additional code to handle the hyperlink hovering/clicking?
TIA!
[EDIT]
What I mean to ask was - whether it is possible QTextEdit to recognize the hyperlink after typing www.google.com and pressing either Space Bar or Enter key, so that it becomes rendered appropriately.
I don't want my user to type < a href=.....
Thank you and sorry for the confusion.
[/EDIT]

JavaFX how to show read-only text?

I want to show some text in my program and I tried with TextArea. However, the text shown is changeable. How can I make the text read only?
I did it like this:
#FXML
private TextArea myText;
and then added the following code to initialise():
myText.setEditable(false);
I needed read-only text fields, but setting the disabled property used styling which was not correct in context (in my scenario, the text field was an input to a search function where a value could be fixed in some cases - disabling the text field implied that it was not part of the search, rather than the value was fixed).
In the end I landed up using:
txtInput.setEditable(false);
txtInput.setMouseTransparent(true);
txtInput.setFocusTraversable(false);
This results in a normal looking text field that is non-reactive to the user.
Maybe just a text would serve the purpose.
Or if you want to show the text in a text field, then:
tf.setDisable(true)
In FXML, add editable="false" to your TextField tag.
Or uncheck the "Editable" checkbox in Scene Builder.
I would say just use a Label.
<TextField fx:id="input" disable="true"/>
You can use following statement in order to make text-area object non-editable with auto scrollbar:
textAreaObjectName.setEditable(false);
Hint: After setting the text to that respective textarea object using textAreaObjectName.setText() method.

Adding a text to the QTabWidget

I have class which inherits QTabWidget. Inside the generated tab I want to display some text.The text should not be editable by the user.But during the application execution there can be a case/s which will cause the text change. Which class should I use for text? Thought about QTextEdit - but it doesn`t look like best idea - since the user should not change the text.Also thought about QLabel - but it also is not good - since the application displays text not label.
QTextEdit can be set to read-only with its property readOnly. I use QTextEdit to display a long read-only text, because it can scroll. I also have read-write text, and by choosing the same widget for all long text, my user interface looks even.
http://qt-project.org/doc/qt-4.8/qtextedit.html#readOnly-prop
An other alternative is QWebView if you plan to have complexly formatted text.
http://qt-project.org/doc/qt-4.8/qwebview.html

Custom TextInput component loses focus but still contains cursor?

I have a custom TextInput that listens for the FocusEvent.FOCUS_IN and FocusEvent.FOCUS_OUT events:
textDisplay.addEventListener(FocusEvent.FOCUS_IN, onFocusInHandler);
textDisplay.addEventListener(FocusEvent.FOCUS_OUT, onFocusOutHandler);
My onFocusInHandler function basically removes a "promptview" that tells the user to type in a value, with the onFocusOutHandler doing the opposite.
For example, if the TextInput text was backspaced to a blank value and the user clicks out of the TextInput box, it would show a "Please enter a value" light-gray prompt in the TextInput.
This works fine until the user clicks our custom "Clear" button. The clear button sets the text to "", and I can tell the FocusEvent.FOCUS_OUT is received because the prompt text is set to visible (its not being set anywhere else). The problem is, the cursor remains in the box as if it still has focus, so if the user immediately starts typing, both the prompt text "Please enter a value" and the user-entered text appears over the gray text, which looks pretty ugly and unreadable.
Why does the TextInput receive the FocusEvent.FOCUS_OUT event if it's not actually losing focus? Is there any way I can get around this?
Option 1. Use the Spak TextInput in Flex 4.1 or 4.5. This already provides a promptDisplay by default (as mentioned in the comments)
Option 2. Take a look at the focus-skin. This skin class is usually placed on top of the normal skin. There could exist some focus ambiguity between these two. Try using a custom focus-skin without a textDisplay and clear button.
Option 3. Not only use a focus event to show or hide the prompt, but also look at the content of the TextInput. You don't want to display a prompt when the text is set by binding as wel.

How to get not truncated text from IUITextField

I have created a custom column header renderer for my AdvancedDataGrid which has a text and a little button inside. Everything works just fine, until a moment when I have to return a headerText by the button click.
Since my custom renderer is an extention of AdvancedDataGridHeaderRenderer it has inherited property label which is IUITextField. So, when I call label.text from inside the custom renderer I get only truncated text, but I need the original one.
Any idea how to get not truncated text from IUITextField? Or maybe the original text is stored somewhere else and I am looking in a wrong place?
You can read the header text from the headerText property of the corresponding AdvancedDataGridColumn

Resources