Gtk progressbar setting CSS min-width has no effect - c++

I try to use a smaller horizontal Gtk::ProgressBar in my project.
The standard minimum width as defined in /usr/share/themes/Adwaita-maia/gtk-4.0/gtk.css is 150px :
progressbar.horizontal > trough {
min-width: 150px;
}
When I change the 150px to 50px in this file I can squeeze the Gtk::ProgressBar smaller than 150px in the application.
So I tried to override this. In the header file, there are the class members
Gtk::ProgressBar **progressBar_channel_buffers;
Glib::RefPtr<Gtk::CssProvider> m_refCssProvider;
In the constructor, I tried
m_refCssProvider = Gtk::CssProvider::create();
m_refCssProvider->load_from_data("progressbar.horizontal {"
"min-width: 50px;"
"}");
progressBar_channel_buffers = new Gtk::ProgressBar*[num_channels];
for (int i = 0; i < num_channels; i++){
progressBar_channel_buffers[i] = new Gtk::ProgressBar;
progressBar_channel_buffers[i]->get_style_context()->add_provider(m_refCssProvider, 1000);
}
This has no effect and I wonder why. When I change for example another CSS property I can see an effect. As an example
m_refCssProvider->load_from_data("progressbar.horizontal > trough, progressbar.horizontal > trough > progress {"
"min-height: 50px;"
"}");
shows the expected effect.
Can you please help me? What am I doing wrong? I started programming Gtk(mm) this week and now I am at a point where I have no idea.

If I am reading your code correctly above, I think the only thing you did incorrectly was mistype the style attribute you were wanting to modify (height instead of width). In your code snippet, it states:
m_refCssProvider->load_from_data("progressbar.horizontal {"
"min-height: 50px;"
"}");
Whereas, I think you meant to type:
m_refCssProvider->load_from_data("progressbar.horizontal {"
"min-width: 50px;"
"}");
Also, having poked around in the source code for GTK4, I did see that the progressbar widget is actually comprised of a child "trough" widget and a child "progress" widget. That leads me to deduce that the ultimate minimum width of the progress bar that is displayed would be limited to the largest value for minimum width for either the progress bar widget or its children widgets. Therefore, you would need to utilize the "load_from_data" statement where you not only apply the minimum width value to the progress bar node, but also to the trough node and the progress node.
I hope that makes sense.
Regards.

Related

Unable to increase size of QToolButton (with Button style set to Qt::ToolButtonTextBesideIcon)

I have a small qt application written in c++. I want the same application to run in small embedded device with a touchscreen but the size of few QToolButton was too small to be visible comfortably. I have tired to increase the size by modifying following function (adding setfont member call):
QToolButton* ColorToolBar::setupToolButton(QString name, QString iconPath, bool isCheckable)
{
QToolButton *p_btn = new QToolButton(this);
p_btn->setCheckable(isCheckable);
p_btn->setIcon(QIcon(iconPath));
p_btn->setIconSize(QSize(ICON_WIDTH, ICON_HEIGHT));
p_btn->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
QFont font = p_btn->font();
font.setPointSize(10);
p_btn->setFont(font);
if (!name.isEmpty())
p_btn->setText(name);
p_btn->setMinimumWidth(MINIMUM_WIDTH);
p_btn->setMinimumHeight(MINIMUM_HEIGHT);
return p_btn;
}
I am able to change the Icon size using setIconSize member function but setPointSize and setFont doesn't do anything. I want to have larger text and icon.
I have a class AdvancePlotToolBar which has all the QToolButton.My qss file looks like :
AdvancePlotToolBar QToolButton {
border: none;
padding-right: 10px;
padding-bottom: 5px;
}
AdvancePlotToolBar QToolButton:hover {
border-bottom: 3px solid #52ce90;
padding-bottom: 5px;
}
AdvancePlotToolBar QToolButton:pressed {
border-bottom: 3px solid #52ce90;
}
AdvancePlotToolBar QToolButton:checked {
border-bottom: 3px solid #52ce90;
margin: 0px;
}
EDIT:
The code below shows how I add QToolButton to the layout of AdvancePlotToolbar.
AdvancePlotToolBar::AdvancePlotToolBar(QWidget *parent) : QWidget(parent)
{
transformationButton_ = setupToolButton("Transformations", "://images//summation.png", true);
QHBoxLayout *layout = new QHBoxLayout;
layout->addWidget(transformationButton_);
setLayout(layout);
}
Setting a style sheet is overriding the font size you're setting in the C++ code. Try it w/out any style sheet applied (even to QApplication) and check. (Also How to set the font size of the label on pushbutton in Qt? )
I have the same issue with a completely custom QToolButton which overrides initStyleOption() and sets own font details in there (so it happens each time just before the button is painted, unrelated to setFont() at all). This works until an app-wide style-sheet is applied (even if it doesn't affect QToolButton directly! *), or a style sheet is applied specifically to the button instance or to its parent. I haven't tracked down where exactly this is happening (somewhere in QStyleSheetStyle I imagine), so I do not have a workaround yet **. In your case since you're using CSS for the tool button anyway, that would probably be best place to set the font size as well.
* The reason setting a style sheet may affect elements which are not styled specifically in the CSS rules is that the whole underlying QStyle is replaced with QStyleSheetStyle, and the original style (Fusion, WindowsVista, Macintosh, etc) becomes a proxy/fallback for QStyleSheetStyle. Or IOW all painting is filtered through the CSS style first. This includes setting style sheet on individual elements as well as globally on QApplication.
** I suspect this is a Qt bug.

qt set max height to a dropdown combobox (style cleanlooks)

I'm working on a software which contains combobox with a lot of items inside, the problem is when I click on it the list is too large and I can't see all of the items by scrolling on it.
The style cleanlooks is used (that's why the combobox have a too large size) but I can't change it so I'm looking for a solution to set a maximum size.
I found nothing about this on the web, neither in the documentation.
I tried to use the size policy but doesn't work. I also tried to get the QLineEdit used by the combobox and to set a QSize on it and finally to by setting stylesheet on the combobox and on the QLineEdit but nothing worked properly.
What I tried with the QSize and the stylesheet :
sz = QSize(20, 20)
combo.view().setGridSize(sz)
combo.view().setStyleSheet("""QListView { max-height: 50px; background-color: yellow; } """)
combo.setStyleSheet("""QComboBox { max-height: 30px; background-color: pink; } """)
EDIT: After the comment of #Vladimir Bershov I tried to set correctly the size with : setMaxVisibleItems() but as said in the doc ("Note: This property is ignored for non-editable comboboxes in styles that returns true for QStyle::SH_ComboBox_Popup") the property is ignored.
So I looked for modify the QStyle Hint to unset the SH_ComboBox_Popup but as explained on this post that's impossible.
If you have any suggestions I'm listening.
Thanks.
Like explained in the comments there's no available solutions in PyQt4
This line worked for me when I was trying to minimize the height of the QComboBox dropdown in Qt/C++.
ComboBox->setStyleSheet("combobox-popup: 0;");

How to prevent a slide from becoming blurry when moving to next slide?

I'd like to prevent a specific slide of my deck to become blurry when moving to next slide.
How can I achieve that?
In the default themes, incrementally displayed elements that are not active anymore are made half-opaque (blurry). You can thus force a given element to be always fully opaque.
For example, you can replace :
<div class="slide">should stay opaque</div>
by
<div class="slide" style="opacity: 1.0" >should stay opaque</div>
Alternatively, if you are used to CSS, you can also modify the stylesheet and for example add a class "stay" to your element and, in your CSS:
.stay { opacity: 1.0 !important; }

Customize the size of a modal window in ShinyBS

I recently used shinyBS to create a modal window, as in
bsModal(id, title, trigger, ..., size)
The size argument is either 'small' or 'large' (or absent).
As you can see, even the large window is pretty small and things get packed in pretty tightly:
Is there any possible hack anyone out there has found that can help to customize the size of the window?
I know this topice is old but since I found a solution I post it for the person going here to find an answer.
You can do it by changing the CSS style. At the begging of your app just precise :
.modal-lg {
width: 4000px;
}
or
.modal-lg {
width: 95%;
}
To change the size of the size = "large"argument in the modal or
.modal-sm {
width: 40px;
}
to change for the small one. Of course change the px to change the size as you want to.
In your application, put the code here to have it available for your app:
dashboardBody(
tags$head(tags$style(HTML('
.modal-lg {
width: 4000px;
}
'))),
#ALL YOUR APP GOES HERE
)

QToolButton and color

I'm trying to make a simple design to select a color and I'm using a QToolButton to open a QColorDialog.
My problem is that I would like the QToolButton to be of the selected color but I've only suceeded to set the background color, which is not what I want.
Here is a picture:
My code:
QColor color = QColorDialog::getColor(m_couleur);
if (color.isValid()) m_couleur=color;
m_labelCouleur->setPalette(QPalette(m_couleur));
m_labelCouleur->setAutoFillBackground(true);
m_buttonCouleur->setPalette(QPalette(m_couleur));
m_buttonCouleur->setAutoFillBackground(true);
Basically I would like the QToolButton to look something like this:
edit: Can anyone explain to me why the website won't let me add "Hi everybody" at the beginning?
QColor color = QColorDialog::getColor(m_couleur);
QPixmap px(20, 20);
px.fill(color);
m_buttonCouleur->setIcon(px);
No CSS involved in this case is (for me ofcourse) big pro
Use the setStylesheet function in order to change the background color of your button
m_buttonCouleur->setStyleSheet(QString("QToolButton{ background: %1; }").arg(m_couleur.name()));
I've done exactly that by using a QPushButton and setting its style sheet to the result from the color picker. I guess a tool button should probably be the same.
button->setStyleSheet(QString("background-color: %1; "
"border: 1px; "
"border-color: black; "
"border-style: outset;").arg(color.name()));