how to set stylesheet for groupbox title in QT - qt

I have a widget with groupbox. I set the border for the groupbox using stylesheet that also works fine, but the border is not fit with the groupbox title. I searched in google, they suggest to change the groupbox title like:
QGroupBox::title {
background-color: transparent;
subcontrol-position: top left; /* position at the top left*/
padding: 2px 13px;
}
In my code i used the stylesheet like:
ui->groupBox->setStyleSheet("border: 1px solid gray;"
"border-radius: 9px;"
"margin-top: 0.5em;");
so how to apply setstylesheet property for the groupbox title, guide me.

Apply such stylesheet to parent of groupBox:
this->setStyleSheet("QGroupBox::title {"
"background-color: transparent;"
"padding-top: -24px;"
"padding-left: 8px;} ");
In my case it was MainWindow.
Also you can edit stylesheet from QtDesigner by calling "Edit styleSheet..." menu on required widget. I prefer to edit my MainWindow stylesheet to keep all code in one place.
In QtDesigner CSS will looks like this (this is stylesheet of QGroupBox parent):
QGroupBox {
border: 1px solid gray;
border-radius: 9px;
margin-top: 0.5em;
}
QGroupBox::title {
background-color: transparent;
padding-top: -24px;
padding-left: 8px;
}

Related

Putting text to border top of qlineedit

I'm working in Qt 5.12. I should create a qlineedit shape in a form, like below:
But I can not write style sheet for it.
I think I managed:
I put QLineEdit into QGroupBox, and set a layout for QGroupBox. And set both horizontal and vertical policy to preferred for QLineEdit. My Style Sheet:
QLineEdit{
border: none;
font: 10pt "Segoe UI";
}
QGroupBox {
border: 1px solid #C4C4C4;;
border-radius: 20px;
margin-top: 10px
}
QGroupBox::title {
subcontrol-origin: margin;
subcontrol-position: top left; /* position at the top left */
color: #C4C4C4;
left: 15px;
}

How to create a new menu with style and button with QMenu

I need to create a menu example like this when we click to the plus icon
I just created the text.
QMenu *menu = new QMenu(this);
menuicd->addAction("Choose the job from:");
menuicd->addAction("Our job portal");
menuicd->addAction("Our database");
menuicd->addAction("University website");
ui.plusbutton->setMenu(menu);
How can I make the white text with blue background for the options? And how can i add the cancel button in this menu?
If you want to create a custom context menu you can use a style sheet
like that:
QMenu
{
border: 1px solid #76797C;
color: #eff0f1;
margin: 2px;
}
QMenu::icon
{
margin: 5px;
}
QMenu::item
{
padding: 5px 30px 5px 30px;
margin-left: 5px;
border: 1px solid transparent; /* reserve space for selection border */
}
But this image is like a QDialog

How to style Scrollview for QCombobox?

I need to apply style sheet for the QCombobox. Can anyone please give
me an example? I thought using the QScrollView will affect the
QCombobox but it didn't. And how to limit the number of items shown in
a combo box?
You should start from official documentation for QCombobox stylesheets. Basically it is like:
QComboBox {
border: 1px solid gray;
border-radius: 3px;
padding: 1px 18px 1px 3px;
min-width: 6em;
}
QComboBox:editable {
background: white;
}
You can limit number of visible items in QComboBox by using maxVisibleItems property.

The DropDown button of ComboBox appear far from the Input Box

I am using AjaxControlToolkit's ComboBox control. The DropDown arrow appears quite far from the actual position where it should be. See this image:
How to fix this to make it appear like an ideal DropDownList?
If the image doesn't appear, click this link: http://postimage.org/image/99yqullkb/
**** Edited (CSS Code) ****
.WindowsStyle .ajax__combobox_inputcontainer .ajax__combobox_textboxcontainer input
{
margin: 0;
padding: 0px 0px 1px 0px;
border: solid 1px #7F9DB9;
border-right: 0px none;
font-size: 13px;
height: 18px;
width:200px;
}
.WindowsStyle .ajax__combobox_inputcontainer .ajax__combobox_buttoncontainer button
{
padding: 0px 0px 10px 0px;
height: 21px;
width: 21px;
}
.WindowsStyle .ajax__combobox_itemlist
{
border-color: #7F9DB9;
}
Looks like a CSS styles side-effect. Check calculated styles for arrow button and it's container with some tool like FireBug or Developer Tools.
IAE try to apply the style rule below, maybe it fix the issue:
table.ajax__combobox_inputcontainer td
{
padding: 0 !important;
text-align: left !important;
}
table.ajax__combobox_inputcontainer td.ajax__combobox_buttoncontainer button
{
margin-left: 0 !important;
}
If you are using width property like width="20%" then this problem occurs. Avoid "%" in width property and try with exact width in pixels like width="200px".

Combobox Telerik - change color

I'm using the combobox control:
http://demos.telerik.com/aspnet-mvc/razor/ComboBox?theme=vista
And I want it to be not white, like it is now. Which css property can do this? Is it possible?
I want it to look like this:
You should be able to achieve that with a custom background color on the select element and some rounded corners on its container. Try placing the combobox in a containing DIV and give it these CSS styles:
.rounded {
border-radius: 10px;
-moz-border-radius: 10px;
-webkit-border-radius: 10px;
padding: 5px;
background: #333;
}
.rounded select {
width: 100%;
background: #333;
color: #fff;
border: 0;
outline: 0;
}
http://jsfiddle.net/mpHgR/1/
It might be a little off, but it's close to what you want.

Resources