Set the QTabWidget background to be transparent by stylesheet but useless in VS2013 - c++

I set a picture as background in the mainframe and add two widgets on it: a QTableWidget and a QTabWidget.
I have set the background of tablewidget to be transparent by stylesheet
in vs2013. The table's background shows the picture I set but the horizontalheader section is still white:
TaskInfWidget_->setStyleSheet("QTableWidget{background:transparent;}\
QTableWidget::item{border-top:1px solid grey;border-bottom:none;border-right:none;border-left:none;}\
QHeaderView::section{background:transparent;color:black; font-family:宋体;font-size:15px;font-weight:200;\
border:none;}");
But when I add a tablewidget in a tabwidget and set the stylesheet of the tabwidget, it doesn't work:
QTabWidget *tab_widget=new QTabWidget;
QTableWidget *table = new QTableWidget(10, 1);
tab_widget->addtab(table,"hahaha");
tab_widget>setStyleSheet("QTabWidget::pane{background:transparent}\
QTabBar::tab{background-color:transparent;height:30px;}\
QTabBar::tab:selected{background-color:rgb(55,112,183)}\
QTabBar::tab:hover{color:rgb(235,97,0);}");
table->setStyleSheet("QTableWidget{background:transparent;\
border:3px solid rgb(30,77,135);\
selection-background-color:rgb(30,77,135);}");
I have set QTabWidget::pane{background:transparent} and QTableWidget{background:transparent}, but the background of the tablewidget is still white, not the picture of the mainframe.
This is my first time to ask question here. This question has bothered me several days. Who can tell me the reason?

Related

QPushButton with Image not getting highlighted when focused (MAC)

I have a QPushButton with image, i have set focus policy to strong focus but, while focusing that QPushButton it is not getting highlighted(no dot frame or default blue border)
You should take a look at the QPalette(in Qt Designer) of your QPushButton and in particular, the HighLight color which is supposed to handle this effect. Moreover, make sure you didn't define focusPolicy in the stylesheet of a parent of that QPushButton, as that could cause problems, because QPushButton would inherit that property.

How to make background of cell widget inside QTableWidget not selectable?

The answer https://stackoverflow.com/a/24909605/3125006 shows how to add a QPushButton into a QTableWidget cell. This works perfectly.
But then the background area around the PushButton is selectable. (Background turns into selection color when clicked). How can I prevent that?
The solution in Pogrammer_ARM's comment is a suitable workaround. With corrected case:
QTableWidget* tblSensors = new QTableWidget();
tblSensors->setStyleSheet("QTableWidget::item{ selection-background-color: rgb(255,255,255)}");

How to control background border size of QDialog with QStyleSheet

Using stylesheets, if I set background-color of a QDialog, I don't seem to be able to control the width of the visible colour - the gap between the content and the actual border. For example if I create a QDialog with only a QListWidget on it, in a QGridLayout, I see the background-color appear as a border around the QListWidget. I would like to make this thinner.
How can I reduce this "border"? It looks as thought background-clip would work if QDialog supported the box model.
I am on 4.7 if it makes any difference
That's the layout border. You can reduce it from the design editor by selecting yout QDialog then adjusting the layoutLeftMargin/layoutTopMargin/layoutRightMargin/layoutBottomMargin properties.
You can also set the border width by code by calling setContentMargins on the layout. For example:
ui->gridLayout->setContentsMargins(3,3,3,3); // sets the qdialog border width to 3px.

Qt space around QPushButton in QHBoxLayout

I have a QLabel and a QPushButton added to a QHBoxLayout. The QLabel has its margins set to 0 and the layout has margin and content margins set to 0. The label and button have the same background color and the button has border set to none. However, the button still looks with a brighter color than the label and there is some extra space around the button, so it doesn't look like it's "glued" to the label. I want them to look like one big widget.
In Qt, margins describe the space surrounding the layout. In newer versions of Qt, the margins on the top/bottom/left/right can be set individually through setContentsMargins().
The space between widgets in the same layout is described by the spacing property. The spacing has nothing to do with the margins. Try calling hboxLayout->setSpacing(0); This should work.
Some days ago I have coded a widget with similar behavior. To avoid problems with margins and colors I can recommend to use second QPushButton button instead of QLabel and set both buttons to be flat with btn->setFlat(true);

Problem in stylesheet of Qt APP

In my app, i have a section that is top widget, the color of the top widget is gray, and i've been put severl widget on top widget, like QComboBox, QLineEdit and 2 QButton, but i have a problem when i right click on QLineEdit as you seen in below picture, the color of default context of window is gray, or when i open the QComboBox the color of background is gray. I'll set the background color of two these widget to white but doesn't work. So, how can i fix this?
Sample for better understand:
http://0000.4.img98.net/out.php/i52512_problem.png
Please help me
The style sheet propagates to all the child widgets, so you have to limit their range by using the right selectors. Since the context menu is a child of the QLineEdit it is also affected.
// What you have probably done:
myLineEdit->setStyleSheet("background-color: gray");
// What you should have done:
myLineEdit->setStyleSheet("QLineEdit { background-color: gray }");
// What you should do if there might be child widgets of the same type
// but for which you don't want the style to apply:
myLineEdit->setObjectName("myLineEdit");
myLineEdit->setStyleSheet("QLineEdit#myLineEdit { background-color: gray }");
See "The Style Sheet Syntax - Selector Types" for details.