Results 1 to 17 of 17

Thread: Translucent the toolbar in the uppler level of QWidget::winId() - how?

  1. #1
    Join Date
    Mar 2010
    Posts
    10
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60

    Default Translucent the toolbar in the uppler level of QWidget::winId() - how?

    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!

  2. #2
    Join Date
    Mar 2010
    Posts
    10
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: Translucent the toolbar in the uppler level of QWidget::winId() - how?

    Nobody met it before ?

  3. #3
    Join Date
    Mar 2010
    Posts
    10
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: Translucent the toolbar in the uppler level of QWidget::winId() - how?

    dear bro, any advice is appreciated!

  4. #4
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Translucent the toolbar in the uppler level of QWidget::winId() - how?

    WHats the background of the main window ? try setting background of mainwindow to transparent.
    And is toolbar shown above label, or the main window ?

  5. #5
    Join Date
    Mar 2010
    Posts
    10
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: Translucent the toolbar in the uppler level of QWidget::winId() - how?

    Quote Originally Posted by aamer4yu View Post
    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.

    Qt Code:
    1. this->setStyleSheet(QString::fromUtf8 ("background-color:transparent;"));
    2. this->setWindowOpacity(0.0);
    3. this->setBackgroundRole(QPalette::Window);
    4. this->setAttribute(Qt::WA_NoBackground);
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Translucent the toolbar in the uppler level of QWidget::winId() - how?

    Are you using all 4 statements ? If yes, I would suggest use only the 1.setStyleSheet() statement... skip others..

  7. #7
    Join Date
    Mar 2010
    Posts
    10
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: Translucent the toolbar in the uppler level of QWidget::winId() - how?

    Quote Originally Posted by aamer4yu View Post
    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 !

  8. #8
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Translucent the toolbar in the uppler level of QWidget::winId() - how?

    Just try this code if it works -
    Qt Code:
    1. QLabel *label = new QLabel();
    2. label->setFixedSize(400,300);
    3. label->setPixmap(QPixmap("some_pic.JPG").scaled(label->size()));
    4.  
    5. QToolBar *tb = new QToolBar(label);
    6. tb->setStyleSheet("background-color : transparent ; color:white;");
    7. tb->addAction("Action 1");
    8. tb->addAction("Action 2");
    9. tb->addAction("Action 3");
    10. tb->resize(label->width(),tb->height());
    11.  
    12. QVBoxLayout *layout = new QVBoxLayout(this);
    13. layout->addWidget(label);
    To copy to clipboard, switch view to plain text mode 

    Put it in ctor of your custom widget.

    You can also replace the stylesheet line with this one -
    Qt Code:
    1. tb->setStyleSheet("QToolBar { background-color : rgba(200,0,0,100) ; color:white; border-color: transparent;} QToolButton{background-color : transparent;} ");
    To copy to clipboard, switch view to plain text mode 
    Last edited by aamer4yu; 11th March 2010 at 11:35.

  9. #9
    Join Date
    Mar 2010
    Posts
    10
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: Translucent the toolbar in the uppler level of QWidget::winId() - how?

    Quote Originally Posted by aamer4yu View Post
    Just try this code if it works -
    Qt Code:
    1. QLabel *label = new QLabel();
    2. label->setFixedSize(400,300);
    3. label->setPixmap(QPixmap("some_pic.JPG").scaled(label->size()));
    4.  
    5. QToolBar *tb = new QToolBar(label);
    6. tb->setStyleSheet("background-color : transparent ; color:white;");
    7. tb->addAction("Action 1");
    8. tb->addAction("Action 2");
    9. tb->addAction("Action 3");
    10. tb->resize(label->width(),tb->height());
    11.  
    12. QVBoxLayout *layout = new QVBoxLayout(this);
    13. layout->addWidget(label);
    To copy to clipboard, switch view to plain text mode 
    Put it in ctor of your custom widget.

    You can also replace the stylesheet line with this one -
    Qt Code:
    1. tb->setStyleSheet("QToolBar { background-color : rgba(200,0,0,100) ; color:white; border-color: transparent;} QToolButton{background-color : transparent;} ");
    To copy to clipboard, switch view to plain text mode 
    Sorry, it still failed!
    I doubt its the display difference between QLabel::winId and QLabel. I don't know the display mechanism of them......

  10. #10
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Translucent the toolbar in the uppler level of QWidget::winId() - how?

    How did you try ?
    I wanted you to try the following -
    Qt Code:
    1. class MyWidget : public QWidget
    2. {
    3. public:
    4. MyWidget()
    5. {
    6. QLabel *label = new QLabel();
    7. label->setFixedSize(400,300);
    8. label->setPixmap(QPixmap("some_pic.JPG").scaled(label->size()));
    9.  
    10. QToolBar *tb = new QToolBar(label);
    11. tb->setStyleSheet("background-color : transparent ; color:white;");
    12. tb->addAction("Action 1");
    13. tb->addAction("Action 2");
    14. tb->addAction("Action 3");
    15. tb->resize(label->width(),tb->height());
    16.  
    17. QVBoxLayout *layout = new QVBoxLayout(this);
    18. layout->addWidget(label);
    19. };
    To copy to clipboard, switch view to plain text mode 
    and then in main() -
    Qt Code:
    1. MyWidget window;
    2. window.show();
    To copy to clipboard, switch view to plain text mode 

    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.

  11. The following user says thank you to aamer4yu for this useful post:

    Jason (12th March 2010)

  12. #11
    Join Date
    Mar 2010
    Posts
    10
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: Translucent the toolbar in the uppler level of QWidget::winId() - how?

    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.

  13. #12
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Translucent the toolbar in the uppler level of QWidget::winId() - how?

    So I guess now you can trace why it ain't working in your code

  14. #13
    Join Date
    Mar 2010
    Posts
    10
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: Translucent the toolbar in the uppler level of QWidget::winId() - how?

    Quote Originally Posted by aamer4yu View Post
    So I guess now you can trace why it ain't working in your code
    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。

  15. #14
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Translucent the toolbar in the uppler level of QWidget::winId() - how?

    Can you show how you are adding the toolbar to the label in your code ?

  16. #15
    Join Date
    Mar 2010
    Posts
    10
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: Translucent the toolbar in the uppler level of QWidget::winId() - how?

    Quote Originally Posted by aamer4yu View Post
    Can you show how you are adding the toolbar to the label in your code ?

    Qt Code:
    1. newTransToolBar = new QToolBar(this); // or newTransToolBar = new QToolBar(preLabel); I tried both
    2. newTransToolBar->setFixedSize(642,53);
    3. newTransToolBar->move(0, 0);
    4. newTransToolBar->setStyleSheet("background-image:url(./images/translucent.png)");
    To copy to clipboard, switch view to plain text mode 

  17. #16
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Translucent the toolbar in the uppler level of QWidget::winId() - how?

    and what output do you get ?
    Also is ur png really translucent ?

  18. #17
    Join Date
    Mar 2010
    Posts
    10
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: Translucent the toolbar in the uppler level of QWidget::winId() - how?

    Quote Originally Posted by aamer4yu View Post
    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!

Similar Threads

  1. Vista top-level frameless qwidget with dropshadow
    By zebylong in forum Qt Programming
    Replies: 0
    Last Post: 2nd October 2009, 18:18
  2. Problem with the QWidget::winId() method
    By yellowmat in forum Qt Programming
    Replies: 5
    Last Post: 22nd April 2008, 13:15
  3. How do I natively move a QWidget top-level window?
    By codeslicer in forum Qt Programming
    Replies: 3
    Last Post: 17th February 2008, 22:08
  4. Winid issue with Qt
    By Pragya in forum Qt Programming
    Replies: 6
    Last Post: 7th June 2007, 14:10
  5. Replies: 4
    Last Post: 4th June 2007, 13:07

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.