Place QProgressBar text outside - qt

On my Windows machine text is displayed to the right of the progress bar.
On my Linux machine text appears in the middle of the progress bar.
If I apply style to progress bar, text appears inside on both systems. How do I get it to appear outside, like in default Windows style?
Here's the simplified version of the code I used to play with progress bars:
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
auto widget = new QWidget;
auto layout1 = new QVBoxLayout;
widget->setLayout(layout1);
auto layout2 = new QHBoxLayout;
auto progressBar = new QProgressBar;
auto spinBox = new QDoubleSpinBox;
spinBox->setRange(0,100);
spinBox->setDecimals(1);
spinBox->setSingleStep(1);
progressBar->setRange(0, 10000);
connect(spinBox, qOverload<double>(&QDoubleSpinBox::valueChanged), progressBar,
[spinBox, progressBar]
{
progressBar->setValue(spinBox->value() * 100);
progressBar->repaint();
});
layout2->addWidget(spinBox);
layout2->addWidget(progressBar);
auto textEdit = new QPlainTextEdit;
auto stylesheet = R"(
QProgressBar {
background-color: cyan;
border-radius: 1px;
text-align: right;
}
QProgressBar::chunk {
background-color: magenta;
border-radius: 1px;
}
)";
textEdit->setPlainText(stylesheet);
connect(textEdit, &QPlainTextEdit::textChanged, progressBar,
[textEdit, progressBar]
{
progressBar->setStyleSheet(textEdit->toPlainText());
});
layout1->addLayout(layout2);
layout1->addWidget(textEdit, 1);
setCentralWidget(widget);
}

The solution is to use a margin. If you change the QProgressBar section of your stylesheet to this:
QProgressBar {
background-color: cyan;
border-radius: 1px;
text-align: right;
margin-right: 4em;
}
then the right end of the progress bar will stop short of the text (which is right-aligned), resulting in the effect you are looking for.

Related

Ending a svg path drawing in FabricJs using right mouse click

I am using fabric JS version 4.5.0 working on a draw application.
I want to use the right mouse click to end the brush drawing but cannot achieve this.
please take a look at this codepen snippet (credits to michaelsboost) I am doing something similar to it.
if (tool.toString().toLowerCase() === 'pencil') {
changeObjectSelection(false);
canvas.freeDrawingBrush = new fabric.PencilBrush(canvas);
canvas.freeDrawingBrush.strokeLineCap = $('#brushStrokeCap').val(); // butt / round / square
canvas.freeDrawingBrush.strokeLineJoin = $('#brushStrokeLineJoin').val(); // bevel / round / miter
canvas.freeDrawingBrush.strokeMiterLimit = $('#brushMiter').val();
canvas.freeDrawingBrush.width = 1;
canvas.freeDrawingBrush.color = strokePickr.getColor().toRGBA().toString();
canvas.isDrawingMode = true;
}
what changes need to be added there to use left mouse click and right mouse click interchangebly to end a svg path drawing?
currently, if you select the pencil tool, clicked using your left mouse button it starts the drawing.
If you right clicked it opens a menu, select copy image, and move your mouse.
Undesired behaviour: try to left click, the whole drawing disappears.
Desired behaviour: right mouse click should end the drawing as a svg on canvas.
// Get a reference to the canvas element
var canvas = new fabric.Canvas('canvas');
canvas.isDrawingMode = true;
// Add a rectangle to the canvas
var rect = new fabric.Rect({
left: 100,
top: 100,
fill: 'green',
width: 100,
height: 100
});
canvas.add(rect);
document.onclick = hideMenu;
document.oncontextmenu = rightClick;
function hideMenu() {
document.getElementById("contextMenu").style.display = "none"
}
function rightClick(e) {
e.preventDefault();
var menu = document.getElementById("contextMenu")
menu.style.display = 'block';
menu.style.left = e.pageX + "px";
menu.style.top = e.pageY + "px";
}
.context-menu {
position: absolute;
text-align: center;
background: lightgray;
border: 1px solid black;
}
.context-menu ul {
padding: 0px;
margin: 0px;
min-width: 150px;
list-style: none;
}
.context-menu ul li {
padding-bottom: 7px;
padding-top: 7px;
border: 1px solid black;
}
.context-menu ul li a {
text-decoration: none;
color: black;
}
.context-menu ul li:hover {
background: darkgray;
}
<canvas id="canvas" width="1920px" height="1080px"></canvas>
<div id="contextMenu" class="context-menu" style="display:none">
<ul>
<li onclick="canvas.isDrawingMode = true">Drawing mode true</li>
<li onclick="canvas.isDrawingMode = false">Drawing mode false</li>
</ul>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/fabric.js/4.5.0/fabric.min.js"></script>

CSS and Layout Issues in codenameone

Point 1. The image shows the simulator with the title in black letters. In the next section of the image it shows what is configured in the CSS and finally its application in the inspector. I tried assigning other UIIDs in the inspector and it changes everything except the color of the letters.
My CSS mapping code.
public class Tarifa extends Form {
Idioma idioma;
public Tarifa() {
this.setLayout(new BorderLayout());
this.setScrollable(true);
Usuario iU = Usuario.getInstancia();
idioma = new Idioma(iU.getIdioma());
this.setTitle(idioma.getMensaje2());
this.getToolbar().setUIID("Titulo");
}
}
In point 2 I need to place the icons as close to the right of the form and therefore the search fields grow but I can't make it happen.
My code in that case is:
Style s = UIManager.getInstance().getComponentStyle("ButtonUtil");
// Contenedor de Lugar de Inicio
Button btInicio = new Button(idioma.getMensaje5(), FontImage.createMaterial(FontImage.MATERIAL_FLAG, s, 4), "ButtonBusqueda");
Button btLocalizar = new Button(FontImage.createMaterial(FontImage.MATERIAL_LOCATION_PIN, s, 4));
Container cnInicio1 = new Container(new BorderLayout());
cnInicio1.addComponent(BorderLayout.CENTER, btInicio);
cnInicio1.addComponent(BorderLayout.EAST, btLocalizar);
Container cnInicio = new Container(new BoxLayout(BoxLayout.Y_AXIS));
cnInicio.addComponent(new Label(idioma.getMensaje5()));
cnInicio.addComponent(cnInicio1);
My CSS is:
ButtonBusqueda {
font-family: "native:MainRegular";
font-size: 2.5mm;
color: blue;
text-align: left;
border: 1pt solid gray;
padding: 1mm;
margin-left: 1mm;
margin-top: 1mm;
}
ButtonUtil {
font-family: "native:MainRegular";
font-size: 3mm;
color: blue;
text-align: left;
margin: 0mm;
paddin: 0mm;
}
You are customizing the container surrounding the title (the title area). Unlike normal CSS properties aren't inherited directly in our CSS. We have explicit hierarchies and the title (which you can see is below the renamed UIID) inherits its styles from Label.
Using this style should let you customize the title font:
Title {
...
}

How to create dynamic custom style on mat -dialog on each mat-table row with top triangle in Angular - Material

Here is my sample code.
Please find my working sample code here
I need to set triangle on right top corner in mat-dialog box - Angular.
I am getting top right corner triangle dialog box using static css on last row.
But here not able to get on each row on change request button click.
The below code is for the Dialog box Component
openDialog(Id, Currency, Amount, Reason, StatusDescription, payment, event) {
let targetAttr = event.target.getBoundingClientRect();
const dialogConfig = new MatDialogConfig();
dialogConfig.disableClose = true;
dialogConfig.autoFocus = true;
dialogConfig.data = {
Id: Id,
Reason: Reason,
StatusDescription: StatusDescription
};
dialogConfig.position = {
top: targetAttr.y + targetAttr.height + 10 + "px",
left: targetAttr.x - targetAttr.width - 20 + "px"
};
dialogConfig.panelClass = ['my-panel','arrow-top'];
const dialogRef = this.dialog.open(EditingDialogComponent, dialogConfig);
dialogRef.afterClosed().subscribe(
data => {
console.log("Dialog output:", data)
}
);
}
The Below code is from style.scss
/* Add application styles & imports to this file! */
#import "~#angular/material/prebuilt-themes/indigo-pink.css";
.my-panel {
overflow: hidden !important;
border-radius: 5px !important;
padding: 0px !important;
color: #fff;
}
.my-panel.arrow-top {
margin-top: 40px;
}
.my-panel.arrow-top:after {
content: " ";
position: absolute;
right: 100px;
top: 365px;
border-top: none;
border-right: 15px solid transparent;
border-left: 15px solid transparent;
border-bottom: 15px solid gray;
}
I am getting like this.
But I want dialog box with upper arrow on each row under change request button click event

QStatusBar remove padding

I want to add a colored Widget over the full QStatusBar. I added a QLabel with red background-color but there is a padding around the label, which i can't remove.
what i tried:
setSizeGripEnabled(false)
setStyleSheet("QStatusBar { border: 0px; padding: 0px; margin: 0px; }"
"QStatusBar::item { border: 0px; padding: 0px; margin: 0px; }"
layout()->setContentsMargins(0, 0, 0, 0);
Update: Example Code:
QWidget *w = new QWidget;
QHBoxLayout *layout = new QHBoxLayout;
QStatusBar *statusBar = new QStatusBar;
QLabel *label = new QLabel("Example");
w->setStyleSheet("background-color: green");
label->setStyleSheet("background-color: red");
statusBar->addPermanentWidget(label, 1);
statusBar->layout()->setContentsMargins(0, 0, 0, 0);
statusBar->setSizeGripEnabled(false);
setStatusBar(statusBar);
w->setLayout(layout);
setCentralWidget(w);
}
I think it is not possible without pointer hacking or reimplementing all QStatusBar functionality because QStatusBar implementation based on pimpl idiom, which means some implementation hidden in private headers and borders between QStatusBar widget and children widgets are hardcoded in qstatusbar.cpp
QRect ir = item->w->geometry().adjusted(-2, -1, 2, 1);
...
QStyleOption opt(0);
opt.rect = ir;
...
style()->drawPrimitive(QStyle::PE_FrameStatusBarItem, &opt, &p, item->w);
QStatusBar{
min-height: 20px;
}
use the min-height css property.

Is it possible to style two children differently in a GtkButton depending on its state?

GTK3: I have two GtkLabel widgets in a GtkButton (via a HBox) like this:
[name_label (black) value_label (grey)] - button inactive (white background)
[name_label (white) value_label (yellow)] - button active (black background)
When the button is toggled I want the background to turn black and the two labels should change color accordingly.
Is it possible to do this using CSS only?
This is what I have tried:
from gi.repository import Gtk, Gdk
window = Gtk.Window()
button = Gtk.Button()
hbox = Gtk.HBox()
name = Gtk.Label('Name')
value = Gtk.Label('Value')
value.set_name('value')
hbox.set_spacing(10)
hbox.pack_start(name, expand=False, fill=True, padding=0)
hbox.pack_start(value, expand=False, fill=True, padding=0)
button.add(hbox)
window.add(button)
window.connect('destroy', Gtk.main_quit)
window.show_all()
screen = Gdk.Screen.get_default()
css_provider = Gtk.CssProvider()
css_provider.load_from_path('style.css')
context = Gtk.StyleContext()
context.add_provider_for_screen(screen, css_provider, Gtk.STYLE_PROVIDER_PRIORITY_USER)
Gtk.main()
style.css:
.button {
background-color: white;
background-image: none;
}
.button #value {
color: grey;
}
.button:active {
background-color: black;
background-image: none;
color: white;
}
.button:active #value {
color: yellow;
}
The value label remains gray when the button is pressed, so the last section does not apply. Is this something that is expected?
Ok, so I can get this to work by dynamically adding a class to the value label e.g. like this but the original question remains: Can it be done using CSS only?
EDIT: In newer versions of GTK3, e.g. 3.18.9 (the one that is included in Ubuntu Xenial), the CSS-only solution works as expected!
I leave the old solution below for those who are stuck with an older GTK version.
from gi.repository import Gtk, Gdk
window = Gtk.Window()
button = Gtk.Button()
hbox = Gtk.HBox()
name = Gtk.Label('Name')
value = Gtk.Label('Value')
value.set_name('value')
hbox.set_spacing(10)
hbox.pack_start(name, expand=False, fill=True, padding=0)
hbox.pack_start(value, expand=False, fill=True, padding=0)
button.add(hbox)
window.add(button)
window.connect('destroy', Gtk.main_quit)
window.show_all()
screen = Gdk.Screen.get_default()
css_provider = Gtk.CssProvider()
css_provider.load_from_path('style.css')
context = Gtk.StyleContext()
context.add_provider_for_screen(screen, css_provider, Gtk.STYLE_PROVIDER_PRIORITY_USER)
ctx = value.get_style_context()
def active(widget):
ctx.add_class('active_value')
def inactive(widget):
ctx.remove_class('active_value')
button.connect('pressed', active)
button.connect('released', inactive)
Gtk.main()
And the corresponding CSS:
.button {
background-color: white;
background-image: none;
}
.button #value {
color: gray;
}
.button #value.active_value { /* value label when the button is pressed */
color:yellow;
}
.button:active {
background-color: black;
background-image: none;
color: white;
}

Resources