How to remove outline on QToolButton - c++

I'm developing Qt application for Mac OS X.
Problem is when I create QToolButton it apears with some outline.
http://i.stack.imgur.com/vqtP9.png
I use next stylesheet
QToolButton {
border: 1px solid #575757;
border-radius: 4px;
}
How to remove the outline?
ANSWER:
I didn't mentioned that I'm adding this item to statusBar().
To remove border around the item I used:
QStatusBar::item {border: 0px;}

Have you tried this ?
QToolButton {
border: 1px solid #575757;
border-radius: 4px;
background-color: palette(base);
}
Usually, web best-practices recommand that if you change one color, you have to change them all.
It is likely that you will also have to change the text color as well to avoid potential issues on some computers with non-default window text color.

use this :
yourWidgetElement->setFocusPolicy(Qt::NoFocus ) ;

Related

How can I remove the "padding" of a QTabWidget?

I have a QTabWidget with a QTableWidget inside, as the example below:
But it has a "padding" (at least I think it is a padding) in the QTabWidget (marked as red in the figure).
How can I remove that or expand the QTableWidget to fill the QTabWidget area?
I am using Qt 5.3.
Try something like this :
tabwidget.setStyleSheet("QTabWidget::pane {
margin: 0px,1px,1px,1px;
border: 2px solid #020202;
border-radius: 7px;
padding: 1px;
background-color: #E6E6E3;
}");
Hope this help you
The problem seems to be related to the "pane" margin of the QTabWidget.
I solved the problem by using this on the stylesheet:
QTabWidget::pane {
border: 0 solid white;
margin: -13px -9px -13px -9px;
}
When you put QTableWidget to QTabWidget tab, you can right click on it (QTabWidget) and select Lay out -> Lay out vertically (for example, or horizontally), this will add an verticalLayout element and place your QTableWidget into it, filling the whole tab. Then, select newly created verticalLayout, scroll down to Layout section, and from here you can control layoutLeftMargin, layoutTopMargin, layoutRightMargin and layoutBottomMargin properties:
Setting all of them to 0, will give you desired result (no stylesheets involved):

Set border for QSpinBox when focused

For already existed Qt project I'd like set border for focused widgets through qss-fle. But I faced out with some unexpected result. When I change border of QSpinBox (and QDoubleSpinBox) border will change as I expect but up-button and down-button change too and look ugly.
Here is my style definition (full example available here):
QSpinBox:focus
{
border-width: 2px;
border-style: solid;
border-color: green;
}
My question is: how to change appearance of border and simultaneously preserve appearance of up-button and down-button. Solution what I am looking for shouldn't be cross platform or cross version.
My environment:
- KUbuntu 15.10 (amd64);
- Qt 5.4 (x64).
Update:
Here is one more example with another style:
QSpinBox
{
border-width: 2px;
border-style: solid;
border-color : red;
}
QSpinBox:hover
{
border-width: 2px;
border-style: solid;
border-color: blue;
}
The widget looks like this:
When you apply a style sheet to the QSpinBox, this widget is completely painted using the QStyleSheetStyle (this class is not part of the public API).
So you have to either style your spin box completely, including the up/down buttons or not to use the style sheet at all.
That up/down buttons are not separated widgets, so you can't apply a different style to them.
So I suggest to subclass the QSpinBox and reimplement the paintEvent() method. In your paintEvent() method you will just call it's default implementation and than you will draw a rectangle around.
try to edit your qss file with another random style to see if it's consistent.
QSpinBox
{
border-width: 2px;
border-style: solid;
border-color : red;
}
QSpinBox:hover
{
border-width: 2px;
border-style: solid;
border-color: blue;
}
Edit :
I see that your arrows are still in bad form so I would suggest you two things :
style also your up-down arrows with background image property or so (take a screen shot of the desired arrows..or so)
forger to style this part via stylesheet and override the "QPaintEvent onFocus handler" by code. Setting the border as green wouldn't be so painful

qt widen QScrollBar when hover using StyleSheet

I'm trying to change the width of a vertical QScrollBar with a custom stylesheet like
QScrollBar:vertical
{
border: 2px solid grey;
background: #32CC99;
width: 10px;
margin: 22px 0 22px 0;"
}
QScrollBar:vertical:hover {
background: red;
width: 25px ;
}
It doesn't work. Did I make any mistake? Can't we change the width of widget in run-time?
You should try
QScrollBar::handle:hover {
background: red;
width: 25px;
}
It works for me
I don't think there is a way of doing this by using the stylesheets alone.
You could create your own scrollbar and override the enterEvent and leaveEvent and change the stylesheet there.
You could also install an event filter to your existing scrollbar (you can get your scrollbar by using the QAbstractScrollArea::verticalScrollBar() function) and listen to the same events and change the stylesheet there.

QTabBar::setTabButton center button

I'm trying to customize a QTabBar button in Qt/C++ by making it show up as italic and the only way I've found is to use setTabButton and give it a custom widget, which is a QLabel in my case. However, setTabButton's position parameter only has Left or Right as options (See code below). Now it looks weird next to the other tabs which are all centered.
tab_bar->setTabButton(index, QTabBar::RightSide,((QWidget*)(tab_label)));
Note, there is a stylesheet applied to the whole application... not sure if that would cause the issue to be more apparent.
Stylesheet for that label is:
QLabel#GrainButton {
background-color: transparent;
border: 0px solid transparent;
margin: 0px;
padding: 0px;
min-width: 20px;
border: 0px solid transparent;
border-radius: 0px;
}
Any thoughts of how to center this?
You can create a custom widget instead of your QLabel. In this widget you can set a QHBoxLayout with 2 placeholders widgets.
QHBoxLayout:
PlaceHolder( sizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); )
YourLabel
PlaceHolder( sizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); )
This may place your widget in the center.
Inherit QProxyStyle and override drawItemPixmap, the pixmap will shown in the center.

CSS set QTableView background color?

I want to set the background color of all cell in a QTableView Object using css.
something along the lines of...
ui.tableView->setStyleSheet("QTableView { background-color: red; color: yellow");
Is this possible? If so how would I do it?
Change the css attribute to "background-color", and then your example looks good to go.
Reference:
http://doc.qt.nokia.com/4.7-snapshot/stylesheet-reference.html
I think the following piece of qss can do the trick:
QTableView::item {
border: 1px solid #d9d9d9;
border-top-color: transparent;
border-bottom-color: transparent;
}
Most of the qss examples for QTreeView work also for QTableView
http://qt-project.org/doc/qt-4.8/stylesheet-examples.html#customizing-qtreeview