Adding a text to the QTabWidget - qt

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

Related

How to set cursor when it is in some area?

I have some rectangle link area on my widget. What is the best way to make cursor Qt::PointingHandCursor when it is in this area?
The QWidget class has a cursor property that you can set with the cursor you wish displayed when the mouse is above it.
EDIT:
Without more detail on what you are trying to achieve, I can only assume you're making your life much more difficult than it needs to be. You can create a QLabel widget to handle the link and then place the label on the menubar automatically.
QLabel *link = new QLabel("<a href='http://doc.qt.io'>Qt Documentation</a>");
menuBar()->setCornerWidget(link);
All the text formatting, cursor display and user interactions are handled by existing code in the Qt classes. The only thing you need to do yourself is to handle what happens when the user clicks on the link, that you can do by connecting a slot to the QLabel::linkActivated(const QString &) signal.

Is it possible show a tree view in a tooltip in Qt?

Is it possible show a tree view in a tooltip in Qt? Or represent a tree view with a QString and then show it in a tooltip?
doc states:
The tip is a short piece of text reminding the user of the widget's function. It is drawn immediately below the given position in a distinctive black-on-yellow color combination. The tip can be any rich text formatted string.
Rich text displayed in a tool tip is implicitly word-wrapped unless specified differently with <p style='white-space:pre'>.
Then I would suggest the simplest way could be to use a nested HTML list, something like <ul><li>...<ul><li>...</ul>...</ul> that could be easy to get from your structure
I think you need create treeview dynamically and show it when user stop moving mouse.
Create widget containing QTreeView and name like ToolTipTree
Make TooltipTree to follow mouse
When user stop moving mouse, set ToolTipTree shown. I user move mouse again, hide ToolTipTree

How to keep focus on Spark TextInput after setting StageWebView source

I have a mobile application that has a Text Input used for searching. Below the search TextInput is a StageWebView. When I set the source of the StageWebView using loadURL() the key input is shifted to the StageWebView.
How can I prevent this?
I think I figured out the problem. When you set the stage property (which is basically setting the visibility to true) that's when it steals the focus. I was showing and hiding the web view depending on if the text input had any text (I was updating the webview source on text change). The fix was to set the web view to visible before putting the cursor in the Text Input. As long as the visibility doesn't change the focus stays in the text input.
I dont know if there is a better way but my solution is to try to set the focus back to the textInput by using myText.setFocus() after your load routine.

How to make links clickable in a QTextEdit?

Is there a way to make links clickable in a QTextEdit?
I know I can use a QTextBrowser and connect to anchorClicked but I'd rather keep the editing and viewing all in one widget, and have clickable links when I set the widget to read-only mode.
Is this possible or am I stuck with having two separate widgets in a stack and switching between them?
Since QTextBrowser inherits from QTextEdit, you should use it and set the readOnly property to false. Then you can change the style of the QTextBrowser as you want.

Passing variables from one form to another in 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.

Resources