Material TextInput Difficult to Identify - qt

I'm trying to render a simple TextInput using QML with the following markup:
TextInput {
id: input
text: "some text box that has no easy way to identify"
font {
pointSize: 16
family: "Segoe UI Light"
}
}
What's actually rendering is this:
Notice how there is no way to identify the TextInput without the "default text" I've added. I would have expected something like the following (where there is an underline identifying the TextInput)
Things tried:
Isolated Text Input
Text Input in a Pane
Text Input in a Layout
Not exactly sure why it's not rendering correctly.

Based on #splaytreez's comment. I was incorrectly using TextInput but should have used TextField. Hopefully someone else finds this useful; although, I do feel it's a silly mistake.

Related

It is possible to set the CSS white-space of a QtQuick Label to pre-wrap?

I have a QtQuick Label in a QML file like so:
import QtQuick.Controls 1.3 as Controls
Controls.Label {
id: lbl
text: "This is some <b>bold text</b> with extra white space"
}
If the text property of my label contains any HTML, then the label renders it as HTML and the multiple spaces in the original text are compressed down to a single space (if the text contains no HTML then it is rendered as normal text and the spaces are preserved).
QWidget has a setStyleSheet method that apparently supports the style "white-space: pre-wrap" which is what I need to get the HTML rendering to preserve the whitespace, but I'm not sure if I can apply this to a Label in a QML file. Is there any way to achieve this?
Edit: This answer: https://stackoverflow.com/a/2756376/14606 shows setting the styleSheet property for a QLabel. Is there any way to write a function that will let me pass my QtQuick Label and cast it as a QLabel and set the stylesheet in this way?
All you need to know is how to apply css in qml, instead of code (widget.setStyleSheet("...")) ?
Have you tried this?
Controls.Label {
id: lbl;
white-space: pre-wrap;
text: "This is some <b>bold text</b> with extra white space";
}
edit: Since white-space is not a property of Label, you need to set this property for the label text.
If possible (just guessing) use:
Controls.Label.Text {
white-space: pre-wrap;
But if not, use this workaround:
Controls.Label {
id: lbl;
textFormat: Text.RichText;
text: "<style>white-space: pre-wrap;</style>This is some <b>bold text</b> with extra white space";
}
You can actually achieve what I was looking for (a Label that can display HTML while preserving white space) by doing a text replace on your original string and replacing all regular spaces (" ") with ​ (which is a zero-length string followed by a regular string). The Label will then faithfully render consecutive spaces, as if the white-space style had been set to pre-wrap. Unfortunately this only kind of works (for my purposes at least) since the Label does not handle line wrapping the same way in both cases.

Strikethrough for Label, getting the Text subnode of a Label using lookup

I have multiple identical Task objects in a VBox, I am attempting to format the text of a Label of certain tasks with a strikethrough. From what I know, this can only be done on the text subnode of the Label.
The below code returns me a null pointer:
label.lookup(".text");
Yet, I can achieve my formatting of the strikethrough with this line in CSS:
#label .text {
-fx-strikethrough: true;
}
Is there a way to achieve the strikethrough effect using the inline code method?Or is there any workaround using CSS? Thanks.
The issue with my implementation was that I was fixated with using a common CSS stylesheet for all of the Task objects. The most simple solution was to access the text subnode in the Label as shown above, and create multiple stylesheets for each task according to whether the style is required or not:
if(isStrikethrough) {
label.getStylesheets.addAll(getClass().getResource("Strikethrough.css").toExternalForm());
} else {
label.getStylesheets.addAll(getClass().getResource("NoStrikethrough.css").toExternalForm());
}
Many thanks to James_D for helping me with such an amateur question, haha

Printing Textarea Text - Full Length (Height)?

I have a webform my client wants users to be able to print out. It works fine with a little styling using CSS, however, I have several textaear fields. If a user types more than the height of the textarea the type is cutoff when printed.
I have tried textarea{height:100%;} and textarea{height:auto;} in the print stylesheet but neither of those works.
Is there a way to resize the textarea field to the size of the text for the print only version? I would prefer a CSS solution if possible that I can insert into my print stylesheet. If this isn't possible javascript solution would work.
Screenshot Comparison:
Note: If I cannot affect just the print version I can considered using JS to auto-resize the textarea field as someone is typing.
This worked for me (adapted from this JS and this jQuery):
function resizeAndPrint() {
var _print = window.print;
window.print = function() {
$('textarea').each(function() {
$(this).height($(this).prop('scrollHeight'));
});
_print();
}
window.print();
}
This problem exist in firefox browser.
Please open the html file in chrome browser for printing text between textarea tags. There is no need apply style and script for printing large text of textarea.
Steps to follow:
open HTML file in chrome browser.
Click Ctrl + P.
Click on Save button ( Select PDF format ).
Open PDF file ( See all text between textarea whether it is moves to second page if excess text contains)
Click Print button.

Inconsistent style of disabled components in ExtJS

I have an ExtJS form that uses hbox-layout containers to create sentences that contain form inputs and there is a requirement to disable the form under certain conditions. The hbox-layout containers have a series of radio, text, checkbox, and textfield components. You can see an example on jsfiddle.
This is an answered question here on SO that doesn't fully work for me because if you disable something that isn't a field (like the text component I'm using) the disable style is different - it appears to mask the component instead of just graying out the text. When nested components are disabled, the mask gradients stack. Examples of this scenario are illustrated on this jsfiddle.
Is there a way to override how text handles its styling when it becomes disabled? I think that may be the easiest solution.
You'll have to handpick each style fix, but yes that's completely possible. Just addCls to give a hook for your CSS...
For example, using the following CSS:
.my-disabled-ct text {
opacity: .3;
}
You can give a similar disabled look both to fields and text items with the following code:
var rootCt = Ext.getCmp('lotsOfItems');
rootCt.query('field').forEach(function(field) {
field.disable();
});
rootCt.query('container').forEach(function(ct) {
ct.addCls('my-disabled-ct');
});
You should probably avoid using disable on field since Ext put a mask over them then (though you could probably hide it with CSS).
You could add the class and target the CSS directly to text items however, why not? In this case, you would query for 'text' and use addCls on them, with this kind of CSS:
text.my-disabled-cls {opacity: .3;}
That goes without saying that you'll restore your components look to "not disabled" by removing the CSS class with the same query and the removeCls method.

Qt Stylesheet for QMessageBox

I am using stylesheets. I want to set style information for the main message text and the informative text for a QMessageBox. Is it possible to access these sub-controls ?
Yes it is possible. The trick is to know how to select the sub-controls. Here's how you can change the style of the text, in this example I make the dialog grey and the text off-white:
QMessageBox {
background-color: #333333;
}
QMessageBox QLabel {
color: #aaa;
}
The second clause uses a Descendant Selector which in this case means "any QLabel that is a descendant of a QMessageBox including children and grandchildren etc". You can be more specific and only select children with QMessageBox > QLabel
I found this information here http://qt-project.org/doc/qt-4.8/stylesheet-syntax.html
Just use rich text - with the exception for the detailed text since it's always interpreted as plain text.
Take a look at the documentation here.
You can simply do QMessageBox {font:...} in the stylesheet or with setStyleSheet(...)
Unless you trying to set the style for the main message text separately from the informative text... is that what you are trying to do?

Resources