Qt and high dpi screens - qt

I've read several articles on this. So I have a Dell XPS 13 and changed the size of text, apps and other items to 200%
But I guess my question is the following. When I launch the application through Qt Designer everything looks good:
But when I run the application outside of the Designer( meaning just double clicking the application to run it), the size is different:
This toolbar is actually smaller than what the screenshot shows. So my question is there a setting I can set my application so when I launch it outside of the Designer it will look like when it was launched from the Designer?

For certain widget classes you can try to provide size measures relative to its font size with the stylesheet:
pMyWidget->setStyleSheet(
"MyWidget {" // What type is it?
"min-width: 80em;" // If the dimension
"min-height: 40em;" // attribute is
"width: 160em;" // applicable
"height: 80em;" // to this type.
// margin: // See the list
// padding: // of related
// spacing: // attributes
"}");
That "em" refers to capital "M" font size AFAIR. The tricky part here is what actual MyWidget type is and if you can apply a stylesheet like that. You can probably omit the widget type in style MyWidget {} but leave the contents yet it supposed to modify all the widgets that that one is parenting.

Related

change the style of default title in stage using javafx

I want to change the style of title in stage but i couldn't find anything.
I tried some css codes like:
.title {
-fx-font-size: 18px;
-fx-font-family: "B Homa";
}
but it didn't work for me.I searched about the style of window in javafx and I figured it out that the default style of every native window is Decorated and for designing a custom window I must use UNDERCOATED mode, but I just want to change the size and font style of native window (different font and size) .
I think this is not possible with a decorated default window. The window itself is a native window from your OS. For example on windows the window implementation is:
com.sun.glass.ui.win.WinWindowand
the title is managed in a native method:
#Override native protected boolean _setTitle(long ptr, String title);

Adding new stylesheet parameters for custom Qt widgets

I would like to add stylesheet options for a custom widget I have developed. We have extended the QPushButton to be a different colour and to flash when it is depressed. This has been done by adding a new property, background color down. And we set this in code. But I would like to set this instead using a Qt stylesheet entry, something like
QFlashingButton
{
background-color-down: yellow;
flashing-interval: 5;
}
I can see one way to do this, read out the stylesheet info using the stylesheet() method, then parse it for parameters relevant to my widget and set them. But I am wondering if there is some way to access the code Qt have themselves for processing stylesheets. At first sight of their code this seems perhaps not to be publically available.
As long as the parameter you want to control in the stylesheet is a QProperty, you can set it in the stylesheet using the syntax: qproperty-<PROPERTY_NAME>: <PROPERTY_VALUE>
I don't think property names can actually have dashes in them, so assuming your QProperties on your custom widget are actually backgroundColorDown and flashingInterval, then your stylesheet would look like:
QFlashingButton
{
qproperty-backgroundColorDown: yellow;
qproperty-flashingInterval: 5;
}

Eclipse RCP CSS pack() does not consider new font

I work on a RCP-application and use the eclipse-css-feature too change the overall font of the application. But when used, the table-elements in the main-perspective does not adapt to the changes. In createPartControl(Composite) the table is filled with content and TableColumn.pack() is called on each one. Before I changed the overall font to Verdana 9px columns always were large enough to hold their content, e.g. "My very long text that is long". Now, however, the columns only display "My very long text that i...". Re-setting the content of the table (clear, fill and pack()) during the setFocus()-function seems to be working, but it also is a pretty bad workaround. Also, this does not solve the problem that I have to wait for the first click to do this.
How do I get my application to pack() table-columns properly on startup?
This is my css:
* {
font: Verdana 8px;
background-color: White;
}
The problem is that the CSS styles are not applied until the SWT.Skin event is generated after the controls are created.
So you need to run your pack after that event. One way to do that is to use Display.asyncExec to run your pack code after the createPartControl has completed. The asyncExec Runnable should then run after the SWT.Skin.
Alternatively you can get the CSS styling engine and force the styling to happen. In a 3.x compatibility view/editor use:
IStylingEngine engine = getSite().getService(IStylingEngine.class);
engine.style(control);

Styling QML without manually marking each property to be styled

I know that QML does not support CSS styling like widgets do, and I have read up on alternative approaches to styling/theming:
https://qt-project.org/wiki/QmlStyling
http://www.slideshare.net/BurkhardStubert/practical-qml-key-navigation/34
Common for these approaches is that they require the developer to specify the parts of the QML that can be styled, either by binding to a property in a “styling QML file/singleton”, or by using a Loader to load a different QML component based on style name. What I would like is something that works like the "id" selector in CSS instead of the "class" selector, so that the individual QML files do not have to know whether they will be styled later on or not.
My current approach make all the QML files look similar to this (using approach in link 2):
Main.qml
Rectangle {
Id: background
color: g_theme.background.color
//g_theme is defined in root context and loaded dynamically
}
What I would like to do is:
Main.qml
Rectangle {
Id: background
color: “green” // default color
}
And then have a styling file that defines (or similar)
Main.qml #background.color: red
Is this possible at the moment, or something that is in the pipeline for a future Qt version, or will the preferred way of styling continue to be something similar to the approach described in the links above?
The preferred way isn't applying a style on default components, but deriving from these components to create pre-styled custom components.
What I do for my projects :
First, I create one centralized 'theme' file, as a JavaScript shared module :
// MyTheme.js
.pragma library;
var bgColor = "steelblue";
var fgColor = "darkred";
var lineSize = 2;
var roundness = 6;
Next, I create custom components that rely on it :
// MyRoundedRect.qml
import QtQuick 2.0;
import "MyTheme.js" as Theme;
Rectangle {
color: Theme.bgColor;
border {
width: Theme.lineSize;
color: Theme.fgColor;
}
radius: Theme.roundness;
}
Then, I can use my pre-styled component everywhere with a single line of code :
MyRoundedRect { }
And this method has a huge advantage : it's really object-oriented, not simple skinning.
If you want you can even add nested objects in your custom component, like text, image, shadow, etc... or even some UI logic, like color-change on mouse hover.
PS : yeah one can use QML singleton instead of JS module, but it requires extra qmldir file and is supported only from Qt 5.2, which can be limiting. And obviously, a C++ QObject inside a context property would also work (e.g. if you want to load skin properties from a file on the disk...).
It could also be helpful to look at Qt Quick Controls Styles
When using Controls Styles it is not necessary to explicitly assign each property in the target control. All properties can be defined in a separate [ControlName]Style component (e.g. ButtonStyle).
Then in target component (e.g. Button) you can just reference to style component in one line of code.
The only one downside here is that Style components are available for Qt Quick Controls only. Not for any Qt Component.

Qt: Background color on QStandardItem using StyleSheet

I have a class that inherits QStandardItem and I put the elements in a QTreeWidget. The class receives notifications from the outside and I want to change the background color of the item based on what happened.
If I do not use stylesheets, it works just fine, like this:
void myClass::onExternalEvent()
{
setBackground(0, QColor(255,0,0)));
}
However, as soon as I put a stylesheet on the QTreeWidget, this has no effect : the stylesheet seems to override the setBackground() call.
So I tried :
void myClass::onExternalEvent()
{
this->setStyleSheet("background-color: red");
}
but this is probably all wrong, it changed the color of some other element on my screen, not sure why.
Does anyone have an idea on how I can alter the background color like with setBackgroundColor but still be able to use stylesheet on my QTreeWidget?
Palettes propagate to the children of a widget, and it's bad to mix and match style-sheet controls and native controls (I do not have a citation for the latter handy, but I have read it in the QT docs somewhere).
That being said, try setting setAutoFillBackground(false) on your QStandardItem derived class.
EDIT: Sorry - also, are you specifying the QTreeWidget in the stylesheet or just setting "background-color:"? If you specify the QTreeWidget only in the stylesheet that might take care of it as well.
QTreeWidget { background-color: white; }
But I think you still have to set the autoFillBackground(false).

Resources