How to make links clickable in a QTextEdit? - qt

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.

Related

Qt: Tab Icon when QDockWidget becomes docked

Qt's QMainWindow has a ability to dock windows derived from QDockWidget. It also would put one on top on the other if few of them are stacked, producing a tab bar. Whenever a QDockWidget's state changes a signal topLevelChanged() is emmitted. At this point I would like to get access to underlying QTabWidget to set an icon for a a newly added tab. How can I do it? My patience is over trying to dig the answer out from Qt's documentation and source code. Thank you in advance.
So icon I want to be on Contents/Index tabs.
Once at least one dockwidget has been tabified, the main-window will create a QTabBar to provide the dock-tabs. Each dock-area can have its own tab-bar. These tab-bars will become children of the main-window, so you can use findChildren() or children() to get references to them.
The main difficulty will be in finding which dock-widget belongs to which tab and in which tab-bar. If the dock-widget window-titles are all unique, you can just search using the tabText(). Otherwise, you might be able to use the tabData(), which Qt sets internally to a quintptr from the dock-widget.
Once you have the correct tab, you can of course use setTabIcon() to add your icon. But note that every time a dock-widget is untabified or moved to another tab-bar, the icon will be lost.

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.

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

How to Remove Toolbar from QToolBox control in Qt?

How to Remove Toolbar from QToolBox in Qt?
Normal Toolbox looks like this:
I want to remove this button written with Page 1. Something like this :
I'm not sure if this makes much sense, since those buttons are needed for the functionality of the QToolBox. If you want a stack of widgets for which you can manually control if they are shown or not, then QStackedWidget provides similar functionality without displaying any elements of its own.
edit: No, as the QToolBox it doesn't come with a scrollbar. But since you 'fill' it with widgets of your own, which then are displayed with setCurrentWidget, you can use for example QScrollArea and placing your own widgets inside it.

Is it possible to style individual tab bars?

I would like to style individual tabs of the tab bar of a QTabWidget (not hover or current but an individual one) WHY? because I need to get the user's attention so that he knows urgent information appeared in that tab. There can be multiple tabs that need attention.
You would have to assemble your own tab widget but i think if you subclass QTabBar and use setTabButton(int index, ...) you can set a custom widget for the item in the tab, this would let you control the behaviour and you could change it through code or style it via the property selector e.g.
QTabBar MyButtonWidget[showalert=true]
{
background-color: red;
}
This seems a little strange. Why don't you start with that tab selected?
I don't think you can do that with stylesheets. You can easily customize first and last but not any tab (AFAIK)
http://doc.qt.io/archives/4.6/stylesheet-reference.html
On the other hand you can set custom icon to draw attention or use void QTabBar::setTabTextColor ( int index, const QColor & color )
You might want to try simply using stylesheets to directly style a tab instead of subclassing just for that purpose. In the stylesheet, you can use the :tab subcontrol to access a single tab, and you can then modify a dynamic propoerty to set its state as either needing attention or not, and applying the style based on the dynamic property.
See : :tab sub control , Customizing using dynamic properties

Resources