Darkgaze
Darkgaze

Reputation: 2573

Background type and color doesn´t work in Qt

I have a widget which background is not transparent but gray as you can see in this image:

The gray zone. Its set to white, but still appears gray

I have a custom widget with a layout and this ScrollArea inside with this style:

background-color: white;
margin: 5px;  /*so it appears with 5 px around. the scroll bar is separated then*/
padding: 0px;

Inside a generic QWidget for the viewport to see (setWidget) with this style:

background: transparent;  // <---- HERE IS THE PROBLEM
margin: 0px;
padding: 0px;

If i try a color and not transparent, it doesn´t work. Always gray. I also tried setAutoFillBackground(true) but didn´t work. (doesn´t work, anyway with styles).

The code for those two containers is this:

cameraModeParametersPanel_ = new QScrollArea();
(...)
cameraModeParametersPanel_->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
cameraModeParametersPanel_->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
cameraModeParametersPanel_->setWidgetResizable(true);

mainParametersLayout->addWidget( cameraModeParametersPanel_ );  // the panel


QWidget* paramPanelViewportWidget = new QWidget();
(...)

QVBoxLayout* mainCameraLayout = new QVBoxLayout(paramPanelViewportWidget);
(...)
// and then i add QGroupBoxes with titles.

Upvotes: 1

Views: 995

Answers (1)

Darkgaze
Darkgaze

Reputation: 2573

The answer to this question is to add this line of code.

paramPanelViewportWidget->setAttribute(Qt::WA_TranslucentBackground, true);

It still has some issues. Now it perfectly responds to transparent background and color background. But transparent shows what is behind the white panel containing it (the gray , blue background).

BUT this property DOESN´T work on WindowsXP. It´s a known bug of , at least, QT 4.7 which is the version i´m using.

When i resolve that last issue (which is additional to the original one) i´ll post it as an answer.

Hope it helps.

Upvotes: 1

Related Questions