Qt embedded PNG icons not coming properly - qt

I am running a Qt application in IMX6 board.
These are my platform details
Qt version = QtEmbedded 4.8
Application type = qml
Device = IMX6
I have a lot of buttons in my GUI, all are PNG files. The problem is some dark dots/lines are on top of the icon.
But the same icons are working fine in qt-x11.
Icons in Qt-embedded (lines in volume icon and date/time icons)
Icons in Qt-x11 (clear volume icon and date/time icons)
any idea why this is happening?
code snippet: setting icon path for a button
ButtonImgItem
{
id : selectID
objectName : "SelectBtnID"
btnWidth : Math.floor(Const.TYPEC_BUTTON_WIDTH * Const.X_DPI)
btnHeight : Math.floor(Const.TYPEC_BUTTON_HEIGHT * Const.Y_DPI)
imagePath : "../images/e_checkmark_zone2b.png"
btnTye : ApplicationData.BUTTON_TYPE_C
buttonState : ApplicationData.BUTTON_STATE_NORMAL
isCaligned : true
anchors.left : nextBtnID.right
anchors.leftMargin : Const.HELP_SELECTGRID_SPACE * Const.X_DPI
anchors.bottom : parent.bottom
anchors.bottomMargin : Const.HELP_SELECTGRID_BOTTOM_MARIGIN * Const.Y_DPI
onSignalBtnClicked:
{
zone3itemID.enabled = false

Related

Specify a background image via CSS in Vaadin 14 programmatically with Java

In Vaadin 14, we can set some CSS values programmatically in our Java code.
We can call getElement, then getStyle, and set the name of the CSS property along with a value.
For example, here we set the background color to green.
public class MainView extends VerticalLayout
{
public MainView ( )
{
this.getElement().getStyle().set( "background-color" , "Green" );
How do we do this for a CSS property like background-image that takes an argument of the CSS function named url?
Hard-coding the CSS path does not work.
public class MainView extends VerticalLayout
{
public MainView ( )
{
this.getElement().getStyle().set( "background-image" , "cat.jpg" );
➥ In Vaadin Flow, how to do we use Java to get CSS to find an image such as "cat.jpg"?
Furthermore, what should be the relative or absolute path to that image file be? I understand that the usual place for static images in Vaadin web app is in the src/main/resources folder.
In case of a "Plain Java Servlet" (non-Spring, non-CDI) Vaadin project, the file should go under /src/main/webapp
In case of Spring: /src/main/resources/META-INF/resources/img
Taken from official docs here: Resource Cheat Sheet
And, as #symlink has noticed in the comments, you should use a url('filename') syntax to reference an image in css : CSS background-image Property
For example, if I have a file named cat.jpg inside a /src/main/webapp/images, then this sets it getElement().getStyle().set("background-image","url('images/cat.jpg')");
Here is another example, with the picture file cat.jpg in src/main/webapp without nesting in an images folder. This is a Vaadin 14.0.10 web app, using the Plain Java Servlet technology stack option on the Start a new project with Vaadin page.
Below is the source code for an entire view using this image as a background.
Notice the first line of the constructor, where we pass "url('cat.jpg')" as an argument. See how we used single-quote marks around the file name to embed in a Java string without escaping. Fortunately the CSS specification allows for either single quotes (') or double quotes (") — quite convenient for Vaadin programmers embedding CSS within Java code.
package work.basil.example;
import com.vaadin.flow.component.button.Button;
import com.vaadin.flow.component.notification.Notification;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.router.Route;
import com.vaadin.flow.server.PWA;
/**
* The main view contains a button and a click listener.
*/
#Route ( "" )
#PWA ( name = "Project Base for Vaadin", shortName = "Project Base" )
public class MainView extends VerticalLayout
{
public MainView ( )
{
this.getElement().getStyle().set( "background-image" , "url('cat.jpg')" );
Button button = new Button( "Click me" , event -> Notification.show( "Clicked!" ) );
add( button );
}
}
And a screenshot of this web app in action. The image is cropped because of the short height of the VerticalLayout. The layout is short because it contains only a button, whose label Click me can be seen faintly in blue text on the left edge. The cropped cat’s face is repeated across the page as is the default with CSS.

Setting window opacity on Qt linuxfb plugin does not work

I want to make a mask widget(top-level, means that window) with opacity 0.75 on linuxfb.
As it is a top-level widget(means that no parent).
I cannot use stylesheet "background-color:rgba(0,0,0,75%)".
I have tried:
MaskWidget::MaskWidget() {
setWindowFlags(Qt::FramelessWindowHint);
1.
setWindowState(Qt::WindowMaximized);
this->setWindowOpacity(0.75); //show warning "This plugin does not support setting window opacity"
2.
QRect desktopRect = QApplication::desktop()->availableGeometry(this);
setGeometry(0, 0, desktopRect.width(), desktopRect.height());
setAttribute(Qt::WA_TranslucentBackground); // it seems that not work
QGraphicsOpacityEffect* oe = new QGraphicsOpacityEffect();
oe->setOpacity(0.75);
this->setGraphicsEffect(oe);
}
The above methods work well in ubuntu and windows, but in my device with QPA linuxfb not work.

Is this ListView bug?

if create WC_LISTVIEW with LVS_REPORT style and set both LVSIL_SMALL and LVSIL_STATE (or with LVS_EX_CHECKBOXES) image lists and heigth of small images is less than heigth of state images - list incorrectly displayed: small images not centered by Y, but on same line with state images, and bottom lines (exactly CY_state - CY_small) is filled by trash. for example on high DPI display, ListView with LVS_EX_CHECKBOXES use 20 pixel heigth for CY_state, if use 15 pixel small icons - will be ~next picture (left side of image). if change state images heigh to <= CY_small will be normal displayed (right side of image)
this is known bug ? or exist ways resolve this ?
yes, this is ListView bug - present in all windows versions, including latest win10 builds.
bug in function
int CLVView::ComputeCYItemSize()
here exist next code:
int CLVView::ComputeCYItemSize() // this -> CLVReportView
{
// CListView* _pListView;
CLVImageListManager* p = _pListView->_pImageListManager;
...
if (p->_himlState)
{
p->_cySmall = max(p->_cyState, p->_cySmall);// bug !! need remove this line
...
}
...
}
if 'nop'
p->_cySmall = max(p->_cyState, p->_cySmall)
under debugger - all begin working ok and have next view:

QPushButton icon maximize on resize event

I have a question about resizing an icon on a QPushButton. Target system is Qt 4.8.6 on Linux. I am using QPushButton to create buttons with icons only, no text. I would like to have the icon as large as possible centered on the button including some margin.
I do not want the button size to adapt to the image size, I want the image size to adapt to the button size, while the button size adapts automaticly to the GUI size through QGridLayout or manually resizing.
When simply creating the button, the icon is only loaded small within the middle:
const QString fileName = "Bitmaps/btn.png";
if( !QFile( fileName ).exists() )
{
qDebug() << "File not found: " << fileName;
}
const QPixmap pixmap = QPixmap( fileName );
m_btn = new QPushButton( QIcon( pixmap ), "", this );
When resizing through manual setting, the icon does not scale:
m_btn->setGeometry( QRect( 100, 100, 50, 50 ) );
To get the icon size rescaled I need to manually call setIconSize(). I can call this within the resize event of the instanciating widget.
But handling the margin still has to be calculated manually.
m_btn->setIconSize( QSize( ( m_btn->size().width() - 12 ),
( m_btn->size().height() - 12 ) ) );
But, as I get from the Qt Documentation there is a Stylesheet based layout thing called "The Box Model" which is applied to QPushButton as well.
http://doc.qt.io/qt-4.8/stylesheet-customizing.html#box-model
So my question is, how do I configure the push button icon to fill the "content" area (marked as grey in the above document).
Possibly how do I configure it, that the icon resizes automaticly?
Your help is appreciated :-)

Javafx How to display custom font in webview?

The web page uses a custom font which is not installed on my PC. In such case, WebView seems to use the default font of the operation system.
But I have the font file "xx.ttf". How can I embed the font into my application and tell WebView to use it to identify the font on the page?
Load the font:
Font.loadFont(
CustomFontWebView.class.getResource("TRON.TTF").toExternalForm(),
10
);
before you use it in the WebView:
style='font-family:"TRON"';
Here is a complete example.
The example relies on a TRON.TTF font which you can download from dafont.
Once you have downloaded the TRON.TTF font, place it in the same directory as CustomFontWebView.java and ensure that your build system copies the TRON.TTF file to the class output directory.
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.text.Font;
import javafx.scene.web.WebView;
import javafx.stage.Stage;
// demonstrates the use of a custom font in a WebView.
public class CustomFontWebView extends Application {
public static void main(String[] args) { launch(args); }
#Override public void start(Stage stage) {
stage.setTitle("TRON Synopsis");
// load the tron font.
Font.loadFont(
CustomFontWebView.class.getResource("TRON.TTF").toExternalForm(),
10
);
// use the tron font in a WebView.
WebView webView = new WebView();
webView.getEngine().loadContent(
"<body bgcolor='silver'>" +
"<div align='center'>" +
"<p style='font-family:'TRON'; font-size:20;'>" + "TRON" +
"</p>" +
"<img src='http://ia.media-imdb.com/images/M/MV5BMTY5NjM2MjAwOV5BMl5BanBnXkFtZTYwMTgyMzA5.V1.SY317.jpg' width='259' height='457'/>" +
"<p style='font-family:'TRON'; font-size:10;'>" +
"A sci-fi flick set in an alternate reality." +
"</p>" +
"</div>" +
"</body>"
);
// layout the scene.
final Scene scene = new Scene(webView, 400, 575);
stage.setScene(scene);
stage.show();
}
}
On use of the Microsoft YaHei font specifically
Microsoft YaHei works fine for me (Windows 7). My Win7 install comes with the font (and it can't be removed), so it doesn't need to be explicitly loaded - just reference the correct font family from your html and it will just work for such a Win7 install. I have a standard US edition of Win7 Pro, not a Chinese version. I did copy the msyh.ttf file from my windows/fonts directory into my project and load it via JavaFX just to make sure the loading via JavaFX works and that also worked fine. The font-family I used to set the html style css font-family specifier was "Microsoft YaHei" (instead of TRON used in the above answer example). The text I displayed to test it was 微软雅黑 and I compared the rendered text by the JavaFX app against the same text rendered in WordPad with Microsoft YaHei selected and the glyphs were identical.
Note that with JavaFX 3.0 is seems you will be able to use the css #font-face mechanism, which means you could declare the font reference in the web page's css rather than in Java code as I did in the above example. Here is a link to the relevant jira issue to track progress on implementation of this feature.

Resources