For instance, in my C++ code:
setStyleSheet
(
"QPushButton{background-color:#9dce2c; border-radius:7px; border:1px solid #83c41a; color:#000000; font-size:15px; font-weight:bold; padding:4px 24px; text-decoration:none; }"
"QPushButton:pressed { border:2px; solid black; }"
"QPushButton:hover { background-color:grey; }"
"QPushButton:focus { outline: none; }"
"QGroupBox { font-size:15px; font-weight:bold; padding:6px 0px; text-decoration:underline; }"
);
Any ideas?
C and C++ automatically concatenate adjacent string literals, so you can just do
setStyleSheet
(
"QPushButton{background-color:#9dce2c; border-radius:7px;"
" border:1px solid #83c41a; color:#000000; font-size:15px;"
" font-weight:bold; padding:4px 24px; text-decoration:none; }"
// ...
);
and it will work as intended. (The indentation is not necessary here, but I think it would be good style to indicate that the second and third lines here are intended to be continuations of the first.)
Brian's got the right idea (indeed - you were already using this technique, with all the long lines being concatenated), but if you want there to be one space after each semi-colon, you'll need to move the quotes correspondingly....
setStyleSheet
(
"QPushButton{background-color:#9dce2c; border-radius:7px; "
"border:1px solid #83c41a; color:#000000; font-size:15px; "
"font-weight:bold; padding:4px 24px; text-decoration:none; }"
"QPushButton:pressed { border:2px; solid black; }"
"QPushButton:hover { background-color:grey; }"
"QPushButton:focus { outline: none; }"
"QGroupBox { font-size:15px; font-weight:bold; padding:6px 0px; "
"text-decoration:underline; }"
);
(You can end lines with \n" to inject newlines if you want the output easier to read).
Related
I want to find and mark all the code that doesn't fit my regex.
[^\}]*navbar[^\{]*\{[^\}]*[\}\s]*
Basically I want to mark everything beside red-highlighted part
my-regex-at-work.jpg
The code:
.pull-right>.dropdown-menu {
right: 0;
left: auto
}
.dropup .caret,
.navbar-fixed-bottom .dropdown .caret {
content: "";
border-top: 0;
border-bottom: 4px dashed;
border-bottom: 4px solid\9
}
.dropup .dropdown-menu,
.navbar-fixed-bottom .dropdown .dropdown-menu {
top: auto;
margin-bottom: 2px
bottom: 100%;
}
#media (min-width:768px) {
.navbar-right .dropdown-menu {
right: 0;
left: auto
}
.navbar-right .dropdown-menu-left {
right: auto;
left: 0
}
}
.btn-group,
.btn-group-vertical {
position: relative;
display: inline-block;
vertical-align: middle
}
My ideas do not work
[^[^\}]*navbar[^\{]*\{[^\}]*[\}\s]*]
[^[[^\}]*navbar[^\{]*\{[^\}]*[\}\s]*]]
it seems to be not possible with notepad++ because of backtracking, it could be done if regex engine supports control verbs:
[^\}]*navbar[^\{]*\{[^\}]*[\}\s]*(*SKIP)(?!)|.*
regex101
to tell to the engine to skip the matched part and fail, otherwise when engine fails to match it continues with input cursor on next character.
Append \K|.* to your regex:
[^\}]*navbar[^\{]*\{[^\}]*[\}\s]*\K|.*
Then hit Mark All button.
I have a foreach that uses a Glob function in order to get some .htm files and finally put that content in one echo.
I Tried to replace one specific phrase located in all this .htm files with some data that I extract from the each .htm filename.
So,
$juzgado_radicado generates a number like ---> 004
$year_radicado generates a number like ---> 2015
$radicado_radicado generates a number like ---> 00911
That numbers are changing depending of foreach iteration getting a new file name.
But at the end I use preg_replace or str_replace in order to change a phrase inside the each .htm document but instead replacing the numbers in each iteration I only get the same result in all replaces. So I get something like "00911" in all .htm files and it have to be something like "00911" and "00577" por example.
I don't know why preg_replace and str_replace have this behaviour inside the foreach loop.
$directory2 = "/Applications/XAMPP/xamppfiles/htdocs/tecnojuridica/finalizado/";
$array_filename = glob($directory2 . "*.htm");
$string = '';
foreach($array_filename as $filename)
{
$xml_file = file_get_contents($filename, FILE_TEXT);
preg_match('/[0-9]{23}/', $filename, $match);
$radicado = $match[0];
// 002
$juzgado_radicado = substr($radicado, -14, 3);
// 2015
$year_radicado = substr($radicado, -11, 4);
// 00958
$radicado_radicado = substr($filename, -7, 5);
// Dom Object
$dom = new DOMDocument('1.0', 'utf-8');
$dom->xmlStandalone = true;
$dom->loadHTML($xml_file);
$content_node = $dom->getElementById("divrandom");
$mega = $dom->saveXML($content_node);
$string2 = preg_replace('/Datos del Proceso/', ' <font size="30"> <span style="background-color: #73A6FF; color: #fff; display: inline-block; padding: 3px 10px; font-weight: bold; border-radius: 5px;">' . $juzgado_radicado . '</span> <span style="background-color: #73A6FF; color: #fff; display: inline-block; padding: 3px 10px; font-weight: bold; border-radius: 5px;">' . $year_radicado . '</span> <span style="background-color: #73A6FF; color: #fff; display: inline-block; padding: 3px 10px; font-weight: bold; border-radius: 5px;">' . $radicado_radicado . ' </span> </font>', $mega);
$string.= $mega . ',';
}
echo utf8_decode($string2);
Thanks in advance.
I've found the Answer: You have to replace at star of the foreach loop not with Php Dom Document Objects.
If you tried to make replacement into Dom Objects it's possible that fails because str_replace of preg_replace can't make all iterations with different replace data.
Having trouble understanding how to programmatically set a stylesheet to be applied on several (or even all) widgets in Qt Creator 4.1 (Qt 5.7) with C++.
For example, say I have 3 progress bar widgets; I have explicitly set each with the same stylesheet with css like so:
ui->c1->setStyleSheet("QProgressBar {"
"background-color: #74c8ff;"
"color: #0a9dff;"
"border-style: outset;"
"border-width: 2px;"
"border-color: #74c8ff;"
"border-radius: 7px;"
"text-align: left; }"
"QProgressBar::chunk {"
"background-color: #010327; }");
ui->c2->setStyleSheet("QProgressBar {"
"background-color: #74c8ff;"
"color: #0a9dff;"
"border-style: outset;"
"border-width: 2px;"
"border-color: #74c8ff;"
"border-radius: 7px;"
"text-align: left; }"
"QProgressBar::chunk {"
"background-color: #010327; }");
ui->c3->setStyleSheet("QProgressBar {"
"background-color: #74c8ff;"
"color: #0a9dff;"
"border-style: outset;"
"border-width: 2px;"
"border-color: #74c8ff;"
"border-radius: 7px;"
"text-align: left; }"
"QProgressBar::chunk {"
"background-color: #010327; }");
I would like to use the Qt Stylesheets to create a stylesheet for my widgets and avoid all this code suplication.
After reading the docs, the syntax would be like this :
QProgressBar
{
background: #74c8ff;
color: #0a9dff;
border-style: outset;
border-width: 2px;
border-color: #74c8ff;
border-radius: 7px;
text-align: left;
}
QProgressBar::chunk
{
background-color: #010327;
}
but, apparently you cannot copy the parameter names as used in a setStylesheet with css directly to a syntax like the one above.
I also tried something like this
QProgressBar.setStyleSheet("QProgressBar {"
"background-color: #74c8ff;"
"color: #0a9dff;"
"border-style: outset;"
"border-width: 2px;"
"border-color: #74c8ff;"
"border-radius: 7px;"
"text-align: left; }"
"QProgressBar::chunk {"
"background-color: #010327; }");
None of the above worked (undeclared identifiers and syntax errors).
Could someone provide an example of how you can achieve defining a single stylesheet with the above parameters to be applied for all widgets? If you could point to a resource (I could not find anything!) that explains the available parameters to achive my goal, that would be as good).
Finally, if such a stylesheet is created for all progress bars, how can I exclude one progress bar (or any widget for that matter) from having that stylesheet and have instead a different one?
Use qApp->setStyleSheet instead of QProgressBar.setStyleSheet to set stylesheet for all widgets in your application. More examples here: http://doc.qt.io/qt-5/stylesheet-examples.html
I'm writing an app for a touchscreen, and the default handle is too small to grab reliably, so I want to make it bigger. According to the official documentation, several answers on SE, and a couple of other forums, this ought to work in a QWidget's constructor:
sliderGrandMaster = new QSlider(Qt::Vertical, panelRight);
sliderGrandMaster->setGeometry( appdata->buttonBorder , //Left
buttonTopRight + appdata->buttonBorder , //Top
halfwidth - (2 * appdata->buttonBorder), //Width
buttonRemainingHeight - (2 * appdata->buttonBorder)); //Height
sliderGrandMaster->setRange(0, RANGE_MAX);
sliderGrandMaster->setTickInterval(RANGE_MAX / 10);
sliderGrandMaster->setTickPosition(QSlider::TicksBothSides);
QString temp = QString("handle:vertical { background: green; height: %1px; margin: 0 -%2px; }")
.arg(buttonRemainingHeight / 5)
.arg(halfwidth / 3);
sliderGrandMaster->setStyleSheet(temp);
But it seems to have no effect. The handle is the same small size regardless of what values I put in the stylesheet, and it's not even green.
With my values at runtime, temp ends up being handle:vertical { background: green; height: 66px; margin: 0 -32px; }. The size of the slider is 94px wide by 331px tall.
Am I missing something?
Edit:
This:
QString temp = QString("QSlider::handle { background: green; height: %1px; width: %1px; margin: 0 -%2px; }")
.arg(buttonRemainingHeight / 5)
.arg(halfwidth / 3);
sliderGrandMaster->setStyleSheet(temp);
at least got it green. But the size is still wrong. Qt version 5.4.2
You can change the size of the handle just with a simple stylesheet. Example :
Is done with the following stylesheet :
QSlider::groove:horizontal
{
border:none;
margin-top: 10px;
margin-bottom: 10px;
height: 10px;
}
QSlider::sub-page
{
background: rgb(164, 192, 2);
}
QSlider::add-page
{
background: rgb(70, 70, 70);
}
QSlider::handle
{
background: white;
border: 3px solid black;
width: 60px; // **Change the width here**
margin: -30px 0;
}
Ok, using Qt 5.6.1 I got some progress on this. The following code
QSlider* slider = new QSlider(this);
slider->setOrientation(Qt::Horizontal);
slider->setStyleSheet("QSlider::groove:horizontal { "
"border: 1px solid #999999; "
"height: 20px; "
"background: qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 #B1B1B1, stop:1 #c4c4c4); "
"margin: 2px 0; "
"} "
"QSlider::handle:horizontal { "
"background: qlineargradient(x1:0, y1:0, x2:1, y2:1, stop:0 #b4b4b4, stop:1 #8f8f8f); "
"border: 1px solid #5c5c5c; "
"width: 30px; "
"margin: -2px 0px; "
"} ");
QVBoxLayout *layout = new QVBoxLayout();
layout->addWidget(slider);
layout->addWidget(new QSlider(Qt::Horizontal, this));
setLayout(layout);
may be placed into an emty QWidget to work. It simply adds two QSliders, one of which is modified using a style sheet.
As you may see, I used to change the groove too and it is working as intended. But there are strange issues which could be a bug at all. Try commenting out some properties of the groove style sheet, like border, background and margin. If there are no effective properties, the width property of the handle is dropped. As I cannot find any constraint in the documentation, I wonder why this happens.
Also note the issues drawing the border around the handle. Seems to need some more fine tuning. ;)
Summing things up the quick solution for you should be added some default properties for the groove.
This is my regular expression to get "left" and its value.
/(left\s*:\s*)(\d+)?(px)/
My problem is, it pulls padding-left and left.
vertical-align: top; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; display: list-item; width: 420px; position: absolute; top: 0px; left: 700px; height: 580px;
How can I get "left" and its value only?
I put a \s in front of left and that works... But I can't always guarantee there will be a space in front of left.
Thanks...
/(?:^|[^-])(left)\s*:\s*(\d+|auto)([a-z]{2})?/
Will fetch what you want with "left" in group 1, "700" in group 2 and "px" in group 3
(?:^|[^-]) = The start of the string, or a non-hyphen character
(left) = The word left (capture group 1)
\s*:\s* = A colon with optional space characters either side
(\d+|auto) = One or more numbers, or the string "auto" (capture group 2)
([a-z]{2})? = Two letters, e.g. "px" "em" "pt" (capture group 3 - optional)
Instead of using a RegEx, you could use a CSS parser. This is a more robust solution as a parser is better suited for this task.
An example using Python and cssutils
example.css
.myClass {
border: 1px solid black;
margin-left: 100px;
left: 700px;
padding-left: 50px;
}
get-left.py
#!/usr/bin/env python
import cssutils
sheet = cssutils.parseFile('example.css')
for rule in sheet:
if rule.type == rule.STYLE_RULE:
for prop in rule.style:
if prop.name == 'left':
print("{0}: {1}".format(prop.name, prop.value))
In this Python script, prop.name will return the name of the property and prop.value its value.
output
$ ./get-left.py
left: 700px