PDA

View Full Version : Translucent the toolbar in the uppler level of QWidget::winId() - how?



Jason
10th March 2010, 04:28
Hi :

I'm trying a camera preview tool under linux. It got puzzled when I want to tranlucent the toolbar widget.

I used the QLabel::winId() to display the video from the camera. A toolbar is needed to be translucent on the top level. I use setStyleSheet("background-image:url(./images/translucent.png)") to set the toolbar background be a translucent image. And I'm sure the toolbar is really translucent if the QLabel widget only displayed a picture by QLabel::setPixmap().

But when it displayed the video from winId(), the toolbar always has a default gray colorunder the background. And it can't be translucent. I doubt the winid() and common widget are different display mechanism. Thus how can i translucent the toolbar widget above the QLabel::window()? Any advice is appreciated!

Jason
10th March 2010, 09:52
Nobody met it before ?

Jason
10th March 2010, 15:46
dear bro, any advice is appreciated!

aamer4yu
10th March 2010, 16:01
WHats the background of the main window ? try setting background of mainwindow to transparent.
And is toolbar shown above label, or the main window ?

Jason
11th March 2010, 02:52
WHats the background of the main window ? try setting background of mainwindow to transparent.
And is toolbar shown above label, or the main window ?

Hi aamer4yu:
Thanks, the toolbar is shown above label. I using each of the following functions to transparent the mainwindow background, but it still doesn't work.


this->setStyleSheet(QString::fromUtf8 ("background-color:transparent;"));
this->setWindowOpacity(0.0);
this->setBackgroundRole(QPalette::Window);
this->setAttribute(Qt::WA_NoBackground);

aamer4yu
11th March 2010, 06:11
Are you using all 4 statements ? If yes, I would suggest use only the 1.setStyleSheet() statement... skip others..

Jason
11th March 2010, 07:52
Are you using all 4 statements ? If yes, I would suggest use only the 1.setStyleSheet() statement... skip others..

Every statement had been tried, stiil failed !

aamer4yu
11th March 2010, 11:27
Just try this code if it works -

QLabel *label = new QLabel();
label->setFixedSize(400,300);
label->setPixmap(QPixmap("some_pic.JPG").scaled(label->size()));

QToolBar *tb = new QToolBar(label);
tb->setStyleSheet("background-color : transparent ; color:white;");
tb->addAction("Action 1");
tb->addAction("Action 2");
tb->addAction("Action 3");
tb->resize(label->width(),tb->height());

QVBoxLayout *layout = new QVBoxLayout(this);
layout->addWidget(label);


Put it in ctor of your custom widget.

You can also replace the stylesheet line with this one -

tb->setStyleSheet("QToolBar { background-color : rgba(200,0,0,100) ; color:white; border-color: transparent;} QToolButton{background-color : transparent;} ");

Jason
12th March 2010, 05:02
Just try this code if it works -

QLabel *label = new QLabel();
label->setFixedSize(400,300);
label->setPixmap(QPixmap("some_pic.JPG").scaled(label->size()));

QToolBar *tb = new QToolBar(label);
tb->setStyleSheet("background-color : transparent ; color:white;");
tb->addAction("Action 1");
tb->addAction("Action 2");
tb->addAction("Action 3");
tb->resize(label->width(),tb->height());

QVBoxLayout *layout = new QVBoxLayout(this);
layout->addWidget(label);

Put it in ctor of your custom widget.

You can also replace the stylesheet line with this one -

tb->setStyleSheet("QToolBar { background-color : rgba(200,0,0,100) ; color:white; border-color: transparent;} QToolButton{background-color : transparent;} ");


Sorry, it still failed!
I doubt its the display difference between QLabel::winId and QLabel. I don't know the display mechanism of them......

aamer4yu
12th March 2010, 05:24
How did you try ?
I wanted you to try the following -

class MyWidget : public QWidget
{
public:
MyWidget()
{
QLabel *label = new QLabel();
label->setFixedSize(400,300);
label->setPixmap(QPixmap("some_pic.JPG").scaled(label->size()));

QToolBar *tb = new QToolBar(label);
tb->setStyleSheet("background-color : transparent ; color:white;");
tb->addAction("Action 1");
tb->addAction("Action 2");
tb->addAction("Action 3");
tb->resize(label->width(),tb->height());

QVBoxLayout *layout = new QVBoxLayout(this);
layout->addWidget(label);
};

and then in main() -

MyWidget window;
window.show();

I didnt ask you to put that in your code... just try if above works for you. I am not able to upload snapshot..otherwise I could have shown you the effect I got.

Can you try the above in a spearate application and see what you get ? May be OS might be a problem if you dont get the same effect as mine.

Jason
12th March 2010, 07:29
dear aamer4yu, I tried your codes, and the toolbar above "some_pic.JPG" is really transparent. "Action 1" , "Action 2" and "Action 3" is shown white.

aamer4yu
12th March 2010, 07:44
So I guess now you can trace why it ain't working in your code :rolleyes:

Jason
12th March 2010, 08:54
So I guess now you can trace why it ain't working in your code :rolleyes:

The problem is some functions can't be traced into, and I can't find which funcition is the key function in the large source sea。

aamer4yu
12th March 2010, 11:01
Can you show how you are adding the toolbar to the label in your code ?

Jason
12th March 2010, 12:19
Can you show how you are adding the toolbar to the label in your code ?



newTransToolBar = new QToolBar(this); // or newTransToolBar = new QToolBar(preLabel); I tried both
newTransToolBar->setFixedSize(642,53);
newTransToolBar->move(0, 0);
newTransToolBar->setStyleSheet("background-image:url(./images/translucent.png)");

aamer4yu
12th March 2010, 12:27
and what output do you get ?
Also is ur png really translucent ?

Jason
15th March 2010, 12:22
and what output do you get ?
Also is ur png really translucent ?

The png is really translucent 。 And the toolbar can be translucent if QLabel displays a picture!