Qt space around QPushButton in QHBoxLayout - c++

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

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.

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

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?

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.

How to make a QLabel fill the child QWidget?

I have QWidget, used Lay Out in a Grid, then a QLabel, but there are some spaces between the QWidget and QLabel. How can I make them the same size and not break the layout?
I'm using this from UI editor.
When you select the widget, in the UI editor's property pane you should see the options for the layout that belongs to it (the options have a red background, and they're usually at the bottom of the list). Amongst the options are ones for setting the margin in pixels between widgets in the layout, if you set it to 0 it should solve your problem.

QWidget background color does not fully cover the QWidget

Using Qt Creator, I have set a QWidget's background property to black. However, some parts of the QWidget, more specifically, between QFrames/QGroupBoxes are still in its system's default color.
Now, I thought that the QFrames and QGroupBoxes need to have its background property set to black too, but it did not work. I have also tried setting the border-color to black, but it does not work, since by default borders, margins are set to 0.
QWidget { background: black; }
Any advice on this issue?
EDIT
The QWidgets are placed in QMdiArea. However, if I make it a QWindow, it works. However, I want the QWidgets to be in the QMdiArea. Also, if I just show the QWidgets as it is, the spaces that I have mentioned above are transparent.
It sounds like you have some widgets within another widget, and are setting the contained widgets to be black, but then the space between them is not black. If that is the case, it is likely because you have a layout in the containing widget, which allocates space between each contained widget. The empty space between widgets will be drawn with the containing widget's background color.
Found out the solution. It seems that you need to set the background color at the QMdiSubWindow, not at QWidget. Don't know why, but it seems logical.