I have a QTextEdit where I do display some HTML. Could I apply a stylesheet to that very HTML content?
Do not confuse it with applying a Qt stylesheet to the QTextEdit (that I know). I want to change the appearance of what is in the QTextEdit widget ("HTML").
--- edit ----
Related: Default HTML style for controls in the Qt library
You can have a look at Qt ignores CSS in QTextDocument which uses QTextDocument and the defaultStyleSheet property / setDefaultStyleSheet() http://doc.qt.io/qt-5/qtextdocument.html#defaultStyleSheet-prop
Note that QTextEdit only supports the following html subset http://doc.qt.io/qt-5/richtext-html-subset.html if you want to do more then that you are probably best of using the QWebkit or QWebEngine modules depending on which Qt version your targeting.
As per Qt5, many CSS properties are supported:
The following table lists the CSS properties supported by Qt's rich text engine.
The best way to apply them is to start your document with <style> and use classes. However the <node style=""> attribute also works.
Related
I know that the Qt QTextDocument and the Qt QML Text type support a set of supported tags and supported CSS properties, forming a subset of HTML 4.
But is there any way to extend which tags I can use? For example when I'd want to render custom XML without first converting it to HTML (via Qt's XSL-T or other means). Or similarly, when I'd want to visually implement an element not yet supported by Qt's subset of HTML 4.
Indeed you can, though this is undocumented behavior and you should be aware of the risks (such as, this behavior could vanish in future versions of Qt). Basically you can just use whatever tag names you want and style them with the available CSS properties. I tested this with Qt 5.12.
Demonstration with a document that you can try in QML Text (and by extension also QTextDocument, though I did not test that explicitly):
<html>
<head>
<style>test-tag { font-weight: bold; }</style>
</head>
<body>
<test-tag>Hello Test Tag!</test-tag>
</body>
</html>
Pretty cool 🙂
If you use tag names containing a dash "-" character, your custom tags are even valid HTML5, compliant with the Custom Elements Specification (details).
I am using Primefaces 5.0.I want to use or bootstrap css to Primefaces custom components like List, table, selectOneListbox.
I am to apply css to normal component like button, link etc.
It's possible, but due to reason that a internal structure of Primefaces's components are different from a plain HTML components with which Bootstrap supposed to work you will need to make hard job to accomplish that. You will need to debug every Primefaces component to see its internal structure and change Bootstrap's css file that it will correspond to internal classes of Primefaces's component.
Actually you have three alternatives (maybe more):
Like BalusC mentioned, Primefaces has its own implementation of Bootstrap theme: you can see it here: http://www.primefaces.org/themes IMHO, best option
Use Bootfaces JSF library: http://www.bootsfaces.net/ Pay attention that it's pretty new library and possible buggy. There isn't big community support like for Primefaces library.
Make you own Composite (or Custom) Components with desired structure and styling.
Qt (and therefore PyQt) allows you to add a QSS (Qt Style Sheet) file to a QApplication, and one to each individual widget you create. You can set your application's style sheet with the following Python/PyQt code:
# app is a QApplication and styleSheet is a str.
app.setStyleSheet(styleSheet)
However, the setStyleSheet() function only allows you to specify one QSS file for the QApplication. This is unlike CSS, which allows any number of style sheets to be applied to a single webpage.
I'm writing a program in PyQt which will allow user-customizable themes. The program has a main QSS file, and themes should be able to contain additional QSS which would be cascaded on top of it. However, due to this apparent Qt limitation, this doesn't seem possible.
One idea I've thought of is that I could assign the program's default style sheet to the QApplication, and the current theme's style sheet to the QMainWindow. This seems like a workaround rather than a good idea, though.
Is there a good way to add two Qt Style Sheets like this?
You can do:
app.setStyleSheet(stylesheet1 + stylesheet2)
This will work the same as normal HTML, where the stylesheets are simply concatenated together in the order in which they appear in the document. After that, the standard rules of CSS specificity apply.
I have a web application and for that we have CSS. We are porting the UI to JavaFX and intend to style it exactly the same way as it there on the web application. I tried loading the CSS which is used in the web project for this, but the style does not get reflected.
After a bit of searching i figured out that Oracle has created something called JavaFX CSS which is similar to CSS but not exactly CSS.
What I wanted to find out: is there some easy way to convert my (web) CSS to JavaFX CSS?
some easy way to convert my (web) CSS to JavaFx CSS
There is no automated convertor for this task. I advise you to take a little bit of your CSS and try to manually convert it by hand.
You, may be able to use analysis tools such as the CSS Analyzer in SceneBuilder to help with this task.
Refer to the JavaFX CSS Reference whilst performing your conversion.
If you have specific issues on converting elements or attributes between your JavaFX and HTML css files, then post new questions regarding those conversion difficulties.
We are porting the UI to JavaFx and intend to style it exactly the same way as it there on the Web Application.
That's going to be a little tricky if you have a lot of CSS. JavaFX CSS is not the same as web based HTML css. JavaFX CSS files share a common syntactic format with HTML CSS, but all of the css attributes in JavaFX differ from those found in HTML CSS.
HTML CSS can specify layout properties to be rendered by an HTML rendering engine. The JavaFX layout and rendering engine works differently from HTML, so HTML CSS based layout specifiers won't have direct equivalents in any of JavaFX CSS, JavaFX code or FXML defined layout managers.
Still, JavaFX CSS is very flexible. Many things are similar to HTML css (like region background and color specifiers), so it is possible to convert the gist of the HTML CSS to JavaFX CSS with acceptable accuracy in a reasonable amount of time, provided you are pretty skilled in both CSS forms. Just don't expect your JavaFX application and your web application to look or behave exactly the same.
Oracle has created something call JavaFX CSS which is similar to CSS but not exactly CSS.
JavaFX CSS is really just CSS in terms of its syntax and file format. CSS as used in JavaFX follows all of the basic syntax and data types of W3C CSS.
W3C CSS is what you term in your question as plain CSS or (web) CSS. There are many extensions and proposed extensions to W3C CSS and many of these extensions aren't even well supported across major browsers.
Consider using WebView for some parts of your application
Rather than port your entire application from HTML to JavaFX, you may want to keep some of the application in HTML and port other parts of the application to JavaFX controls.
JavaFX includes a WebView component which can be easily embedded in a JavaFX application. WebView can accurately render HTML, and it can parse and understand W3C CSS. You could use some of your existing CSS and HTML to style and render parts of your JavaFX application.
Because JavaFX CSS and W3C CSS share a common file format, you could even place both JavaFX CSS styles and W3C CSS styles in the same CSS file and the JavaFX and WebView runtimes would be clever enough to apply the appropriate styles when rendering their specific components.
See Also
JavaFX CSS Reference Guide
Learning CSS (JavaFx style)
I'm developing a multi-module application using GWT 2.5.1. I'm not using any GWT theme. I want to customize the style for some of the GWT widgets, for example Button and CheckBox.
I see two solutions:
Write a CSS file loaded in the application (link in the HTML page). The CSS will contain CSS rules using GWT defined names, like .gwt-Button for buttons and .gwt-CheckBox, .gwt-CheckBox-disabled for checkboxes. This solution don't takes the advantage of CSS optimizations made by the GWT compiler.
Use a CssResource and set the style name each time I use a Button or a Checkbox. This solution will take advantage of CSS optimizations but it requires to set the style name every time I create a new Widget.
There are other solutions? Which is the correct one?
You can put those styles in a CssResource as well.
Just put #external on top of those styles in your css file, and you are good to go.
For example:
#external gwt-DatePicker;
.gwt-DatePicker {
...
}
Hope it helps.
Other solution: Button is html element button and Checkbox an html element input[type=checkbox]. So you could set styles on those elements and use css selectors for specific states. i.e. button:disabled. That way you won't have to set style names, or don't have lots of extra style names and use cleaner css.
You could subclass whatever widgets you want to style (e.g. MyButton), and have your subclass either just add a style name to each widget that gets created, or do the styling inline using calls to this.setWidth(), this.getElement().getStyle.setXXX.
Also, what optimizations does the GWT compiler perform on CSS? I know that it will obfuscate style names to avoid collisions, but I'm not sure CSS is even able to be optimized?
I would personally use emanuele's solution, but just to offer an alternative: you can use a widget's getElement() method to access style names directly, so if you really want to, you can override the style names with ones you created. This gets rather difficult, however, with larger widgets and panels that have multiple styles.