I have a QWidget that has a tooltip set. The issue is, it's displayed on one huge line(the tooltip is quite large). I would like to put a constraint on the width of the tooltip, so it would be displayed on multiple smaller lines instead of a huge one. Is there a way to set this programmatically, in the C++ code?
Qt tool tip is HTML aware. You can design the tool tip using HTML tags
Here is a simple example
ui->pushButton->setToolTip(QString("<div style = 'background-color:yellow;float:left'> <p><b>test tool tip</p></div>"
"<div> <img src=':/someImage.png'></div>"
"<div style = 'background-color:red;float:left'> <p><b>test tool tip</p></div>"));
Related
Is it possible to completely remove the title from a QGroupBox? If you just give it an empty title, the label where the title would be still takes up space. It looks like this:
But I want it to look like this instead:
I tried the following things without success:
Setting the title font size to zero
Giving the title a size of zero in the stylesheet via setStyleSheet("QGroupBox:title{ max-width: 0; max-height: 0; }");
Moving the title inside the box via setStyleSheet("QGroupBox:title{ subcontrol-position: center center;}")
Note: You might say that a group box without title is a use case for QFrame. The problem with this is that I want to mix groups/frames with and without title, but the frame has a different visual style than the group box. So if you could tell me how to make QFrame look like QGroupBox that would solve my problems too.
You could use:
setStyleSheet("QGroupBox{padding-top:15px; margin-top:-15px}")
What you see is a bug of the particular style you're using. This pretty much "works" without you having to do anything special on other common styles (e.g. Mac, Windows). If you insist on using the particular style in question, you'll have to patch it yourself and either copy the style into your project, or build entire Qt to have a fixed version.
Is there any other control like ListView in win32 or if there is any way to remove the title area of the ListView control which is available in win32. And can this be used for text formatting like tabs and bold, italics.
Thanks in advance :)
If you want text-like features then use rich edit control.
If you want to show list view control in report view without header then include LVS_NOCOLUMNHEADER style when creating the control.
yes, the column header doesn't have to be visible at all. It can format each item individually too like bold, but tabs are best implemented as columns (without the header visible of course).
Without knowing more what you want, its difficult to advise.
I have a problem with displaying a text to area with different attributes.
My project has a multi-threading build. I reach to GUI text area by using signal-slot mechanism. I put my texts to the text area like this;
addrMW->ui->printerArea->appendPlainText(command.Data);
I want to append my text to this area with different font, size, etc..
I'm using Qt Creator 2.7.2 / Qt 5.1. Could someone explain this to me with an example?
What you want is a rich text edit. Luckily QTextEdit is able to handle that. Check the acceptRichText property (which should be true by default).
Then the methods you're looking for are:
setCurrentCharFormat
setCurrentFont
setFontFamily
setFontPointSize
etc...
Then, instead of appendPlainText() you should use append() to add text to the QTextEdit. Also see this Q/A. As proposed in the accepted answer, you can also use html formatted text instead.
What I would like to do is to make a WYSIWYG editor, not a big one, just the common utilities, so bold, italic, underline, size, font, in Qt.
My approach for now is to make it in a QTextEdit, when the user click the button i get the signal and using the cursor index i put html tag, but I don't know if it's a good idea.
Any Advice?
You can always use the webkit module and relay on the contentEditable feature.
Any Advice?
Study "Order form" and "Syntax Highlighter" examples. Also, read QTextCursor and QTextDocument documentation.
I think you refer to the internal format of a document. You just need a solution to keep the formating information, so the editor/viewer can interpret it. Of cause you can choose HTML or HTML-like tags for this. I'd recommend to check out BBCodes, which are widely used for that.
By the nature of WYSIWYG the internal format should be invisible to a user. I don't know about the capabilities of QTextEdit to achieve that. Perhaps there is a HTML/BBCode extension?
This is a question about Qt library, not about Web design.
For QLabel and other controls I can set HTML text, for example "<h3>Some Text</h3>". The question is: where is the default HTML style is defined? How can I find out what a font would be used for <h3> tag?
The next question: can I change the default HTML style?
Edit: I want to specify in one place in my code how my controls would be displayed. To specify css style in all the labels doesn't seem to be an elegant solution to me.
Edit2: It seems people don't get the question. I'll try again. Suppose I do the following:
QLabel* label = ...
label->setText("This <b>is</b> a <h3>Header</h3>");
The question: what fonts will be used for label text rendering? How can I control them? Is there a way to specify, say, default font size for <h3> headers?
Edit3: Thomi have suggested to use QTextDocument::setDefaultStyleSheet. But this is just a workaround. I have to manually apply css style to all the QTextEdits (and not QLabels) in the interface. And the question was: how to find out the default style sheet? QTextDocument::setDefaultStyleSheet just overrides it for a single QTextDocument object. Maybe QTextDocument::defaultStyleSheet returns it? I don't have a computer with Qt insatlled right now so I can't check it.
What you want cannot be done with a QLabel. The QLabel is designed to hold primative text labels - it's HTML support is rather... ropey.
However, You can achieve this using a QTextEdit & QTextDocument.
Try something like this (I'm writing this from memory, so it may not compile or be 100% correct):
QTextDocument *doc = new QTextDocument(this);
doc->setDefaultStyleSheet("h3 { font-color: red; }");
QTextEdit *edit = new QTextEdit(this);
edit->setDocument(doc);
edit->setHTML("this is a red <h3>heading</h3>");
The important thing is to use a QTextDocument, which allows you to change the HTML stylesheet. From the QT documentation:
The default style sheet is applied to all newly HTML formatted text that is inserted into the document, for example using setHtml() or QTextCursor::insertHtml().
The style sheet needs to be compliant to CSS 2.1 syntax.
Note: Changing the default style sheet does not have any effect to the existing content of the document.
see here for more info
Edit:
To get the default stylesheet, you can call QTextDocument::DefaultStyleSheet() - however, this only applies to QTextDocuments, and may or may not apply to all Qt controls (including QLabel).
As mentioned in other answers you can do it for widget styles but not for HTML tags. The only way to do it is to set CSS styles inside your widgets text property individually.
Qt uses its rich text engine to render HTML tags which are defined according to rules in HTML 4 specification. See Supported HTML Subset
If you need just one style for all your labels why not to set it using setStyleSheet() like this:
MainWindow w;
w.setStyleSheet("QLabel{font-size:20px; color:purple;};");
Unless you want to use more than one style inside your labels (for example: "More than one style") that's the right way to do it.
Have a look at Qt Documentation about Style Sheets
You can probably use QApplication::setStyleSheet() or QWidget::setStyleSheet() to get it done.
In latest QT ie on QT4..The above answers are working.
Tell which QT version u r working on...
Try the following...
QLabel{
border: 2px solid green;
border-radius: 4px;
padding: 2px;
background-image: url(images/welcome.png);
}
link