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

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

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;
}

Line below and to the right of a button

You can see that the buttons have one darkish line at the bottom and to the right. How can I achieve this effect? Right now all I have is
#button {
background-color:blue;
}
Here's what you can do:
#button {
border: none; // clear default button border
border-bottom: 2px solid gray; // set bottom border
border-right: 2px solid gray; // set right border
}

how to set stylesheet for groupbox title in 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;
}

Hide QScrollBar arrows

How to hide QScrollBar arrows?
I need to hide in horizontal scrollbar.
I was trying to hide with setStyleSheet:
setStyleSheet(" QScrollBar:left-arrow:horizontal, QScrollBar::right-arrow:horizontal { height:0px; }" )
but it doesn't work.
If you need to hide just the arrows inside buttons then you can try to set background and border in this way:
QScrollBar::right-arrow:horizontal, QScrollBar::left-arrow:horizontal
{
border: none;
background: none;
color: none;
}
If you want to hide whole buttons then you go with code below.
QScrollBar::add-line:horizontal {
border: none;
background: none;
}
QScrollBar::sub-line:horizontal {
border: none;
background: none;
}
I know this is an old question, but I've ran into an issue with this question's approved answer, and I've found a fix for it so I'm going to leave this here in case someone runs into the same problem that I did.
While the accepted answer suggests setting border, background and color to none, this only visually hides the scrollbar arrows. What I mean by this is that you can still click them, and the scrollbar's handle, while it can move to the place they occupied, can not be clicked on if your cursor is in the area the arrow buttons occupied.
To also functionally hide them, you should set their width and height styles to 0px as well. This will make it so you can click on the handle if the scrollbar's handle is in the area the arrow-buttons occupied.
In order to hide a scroll bar you can set the scroll bar policy for that particular scroll bar (horizontal in your case). For example:
QScrollBar scrollBar;
scrollBar.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
Create a QScrollBar and assign it this stylesheet and this should do the trick. See example below.
QScrollBar:vertical {
width: 15px;
background: #f1f1f1;
}
QScrollBar::handle:vertical {
background: #888;
}
QScrollBar::add-line:vertical {
border: 2px solid gray;
background: #f1f1f1;
}
QScrollBar::sub-line:horizontal {
border: 2px solid gray;
background: #f1f1f1;
}
QScrollBar::handle:hover:vertical {
background: #555;
}

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".

Resources