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;");
Related
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.
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.
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
)
In my qt C++ gui application, I have a QMessageBox with 3 buttons and some standard functionality. I want to decorate all these with stylesheets and fonts and what not.
I am successfully able to do the following -
i. Set MessageBox background.
ii. Set Button background.
void MainWindow::on_pushButton_clicked()
{
QMessageBox msgbox;
msgbox.setInformativeText("YOLO");
msgbox.setStandardButtons(QMessageBox::Ok|QMessageBox::No|QMessageBox::Cancel);
msgbox.setWindowFlags(Qt::FramelessWindowHint);
msgbox.setStyleSheet("QMessageBox { background-image: url(:/res/bk.jpg) }");
msgbox.button(QMessageBox::Ok)->setStyleSheet("QPushButton { background-image: url(:/res/green_bk.jpg) }");
msgbox.button(QMessageBox::No)->setStyleSheet("QPushButton { background-image: url(:/res/red_bk.jpeg) }");
msgbox.exec();
}
But I am stuck on how to set a font (type and size) to the InformativeText field, and also how to make it Bold. I have referred to the InformativeText Properties but I am unable to sort things out. Any ideas on how to achieve this ? Thanks.
As an added query, can I change the fonts (type and size) of buttons as well and set Bold Italics etc ?
EDIT
I did the following changes to my code, and the results are baffling,
QFont font;
font.setBold(true);
msgbox.setFont(font);
After doing this, my informationText has become bold, my cancel button has become bold. But the Ok and No buttons are normal (non-bold). If I remove the setStylesheets for the two buttons, only then are they becoming bold (which is useless, since I want background images).
Any ideas to have a synergy in all these ???
I found solution for your problems.
QMessageBox msg(QMessageBox::Information,"Hey", "Dude", QMessageBox::Ok);
QFont font;
font.setBold(true);
msg.setFont(font);
msg.button(QMessageBox::Ok)->setFont(font);
msg.exec();
I am trying to modify the QTableView to always show all editors. I am ok with the workaround to call openPersistentEditor() on all cells.
However I'd like the content of the cells to not be selected and no text cursor for empty fields.
This is what I get:
And this is what I'd like to have:
I tried using clearSelection() and clearFocus() but that does not do the trick. If I click on each cell I get the desired result and I could do the same thing programmatically, but I'd to know if there's a more direct way.
I had this exact same issue. I ended up just adjusting the selection color and selection background color on the QLineEdits. You can do it on all QLineEdits or just on a custom QLineEdit by giving each editor an object name and referencing that in the stylesheet.
/* applies to all QLineEdits in the application */
QLineEdit {
selection-background-color: white;
selection-color: black
}
/* applies to all QLineEdits with the object name "custom" in the application */
QLineEdit#custom {
selection-background-color: white;
selection-color: black
}