Results 1 to 11 of 11

Thread: How to build a transparent ScrollArea widget?

  1. #1
    Join Date
    Jan 2011
    Posts
    19
    Qt products
    Qt4
    Platforms
    Windows

    Default How to build a transparent ScrollArea widget?

    I'd like to build my own ScrollArea widget, which would be transparent if it overlaps other widgets or texts, based on QScrollArea.

    Basically I set WA_NoSystemBackground attribute on both ScrollArea and its content widget, but the resulting appearance was not exactly expected.
    1. the entire ScrollArea displayed a black background, I've no idea why it's black or it just meant that black represented blank background. What I expected was that it would display everything intact.
    2. the button under ScrollArea can be viewed and can't respond to mouse click, this demonstrated the transparency effect partially worked, but the button was gone away while scrolling and never got repainted.
    3. I'm afraid there is some extra paintings supposed to be handled in the case, but how?

    I've built a quick demo to show my problem, hopefully someone could give me some reference. thx.

    QTransparentScrollArea.zip
    Last edited by myfifth; 25th January 2011 at 10:33.

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How to build a transparent ScrollArea widget?

    I'd like to build my own ScrollArea widget, which would be transparent if it overlaps other widgets or texts, based on QScrollArea.
    Do mean other widgets and text of the same application or from external applications?
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Jan 2011
    Posts
    19
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to build a transparent ScrollArea widget?

    Quote Originally Posted by high_flyer View Post
    Do mean other widgets and text of the same application or from external applications?
    in same app.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to build a transparent ScrollArea widget?

    By overlapping do you mean overlapping with siblings, with cousins or with parent/children? Widgets shouldn't overlap with their cousins or siblings, they can (and do) only overlap with parent and children. I'm having a hard time understanding what you want to achieve and why but NoSystemBackground is not the way to go -- it is meant for top-level widgets only. In general if a widget is not a top-level widget, it is transparent by default so everything that goes under it should be visible.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Jan 2011
    Posts
    19
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to build a transparent ScrollArea widget?

    Quote Originally Posted by wysota View Post
    By overlapping do you mean overlapping with siblings, with cousins or with parent/children? Widgets shouldn't overlap with their cousins or siblings, they can (and do) only overlap with parent and children. I'm having a hard time understanding what you want to achieve and why but NoSystemBackground is not the way to go -- it is meant for top-level widgets only. In general if a widget is not a top-level widget, it is transparent by default so everything that goes under it should be visible.
    Overlapping with siblings, that's my requirement. I know it's sort of weird.
    If you can run my demo that would be more clear.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to build a transparent ScrollArea widget?

    So maybe you shouldn't be using widgets but rather Graphics View (maybe with QML)? By the way, your demo doesn't really tell much of a story.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How to build a transparent ScrollArea widget?

    You might find this thread interesting:
    http://www.qtcentre.org/threads/3615...sparent-widget.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  8. #8
    Join Date
    Jan 2011
    Posts
    19
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to build a transparent ScrollArea widget?

    Quote Originally Posted by wysota View Post
    So maybe you shouldn't be using widgets but rather Graphics View (maybe with QML)? By the way, your demo doesn't really tell much of a story.
    I simply wanted to demenstrate my requirement. A ScrollArea covered on another sibling button, it would look transparent and it should properly function as well.
    In summary, what I want is a scrollable widget, and it should be transparent, which means everything under it should be visible, including the content of parent, the siblings if overlapped, etc.

    I haven't learned about QGraphicsView because I'm still not quite familiar with Qt class hierarchy.
    I'll study it later anyway.
    Thx.

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to build a transparent ScrollArea widget?

    The thing is widgets aren't supposed to overlap. You can put your scrollarea on top of another widget and without any special treatment it should be transparent. But if you start putting non-transparent stuff into it, it will not be transparent anymore.
    Qt Code:
    1. #include <QtGui>
    2.  
    3. int main(int argc, char **argv){
    4. QApplication app(argc, argv);
    5. QLabel l;
    6. l.resize(600,400);
    7. l.setText("some very long text that is really extremely long so that it is long enough to be seen past the line edits");
    8. QScrollArea *area = new QScrollArea(&l);
    9. area->setGeometry(QRect(QPoint(0,0), QSize(600,400)));
    10. area->setAutoFillBackground(false);
    11. area->viewport()->setAutoFillBackground(false);
    12. QWidget *w = new QWidget;
    13. w->setAutoFillBackground(false);
    14. QVBoxLayout *la = new QVBoxLayout(w);
    15. for(int i=0;i<40;++i) {
    16. QLabel *lab = new QLabel("xyz");
    17. la->addWidget(lab);
    18. }
    19. area->setWidget(w);
    20. l.show();
    21. return app.exec();
    22. }
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  10. #10
    Join Date
    Jan 2011
    Posts
    19
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to build a transparent ScrollArea widget?

    @wysota,

    I see your idea. I know that widgets are generally not supposed to overlap with each other, Win32 doesn't support that too, so I chose Qt, however overlapping widget is primary requirement for me.
    In my case,
    1. for non-scrollable container widget, I worked it out with QFrame-subclassed widget.
    2. for scrollable container widget, I still didn't figure it out.

    I quickly went through QGraphicView, here's my doubts,
    1. what I need is a common scrollable container widget, it's not quite matched to primary usage of QGraphicView, don't know if I got it right.
    2. furthermore, there looked like no built-in QGraphicWidgets, like button, edit, etc, only a base QGraphicWidget, then I have to implement each one of them if required.

    Alternatively, I'm thinking about implementing my own scrollable widget by starting from QFrame and QScrollBar, since default QScrollArea got limitations, would it be feasible?

  11. #11
    Join Date
    Jan 2011
    Posts
    19
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to build a transparent ScrollArea widget?

    Quote Originally Posted by wysota View Post
    The thing is widgets aren't supposed to overlap. You can put your scrollarea on top of another widget and without any special treatment it should be transparent. But if you start putting non-transparent stuff into it, it will not be transparent anymore.
    Qt Code:
    1. #include <QtGui>
    2.  
    3. int main(int argc, char **argv){
    4. QApplication app(argc, argv);
    5. QLabel l;
    6. l.resize(600,400);
    7. l.setText("some very long text that is really extremely long so that it is long enough to be seen past the line edits");
    8. QScrollArea *area = new QScrollArea(&l);
    9. area->setGeometry(QRect(QPoint(0,0), QSize(600,400)));
    10. area->setAutoFillBackground(false);
    11. area->viewport()->setAutoFillBackground(false);
    12. QWidget *w = new QWidget;
    13. w->setAutoFillBackground(false);
    14. QVBoxLayout *la = new QVBoxLayout(w);
    15. for(int i=0;i<40;++i) {
    16. QLabel *lab = new QLabel("xyz");
    17. la->addWidget(lab);
    18. }
    19. area->setWidget(w);
    20. l.show();
    21. return app.exec();
    22. }
    To copy to clipboard, switch view to plain text mode 
    hi wysota, I finally figured it out.
    Just moved your code
    line 13 w->setAutoFillBackground(false)
    below
    line 19 area->setWidget(w);

    I just reviewed source code of setWidget(), unfortunately it set w->setAutoFillBackground(true) by default, so we have to reset it to false after that, then it went right.

    thx all.

Similar Threads

  1. Transparent dialog widget
    By girishgowda in forum Qt Programming
    Replies: 3
    Last Post: 2nd July 2010, 10:11
  2. How to get an area of the widget transparent...???
    By kapoorsudhish in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 5th March 2010, 05:20
  3. Qt transparent Widget
    By Vipin Vijayan in forum Qt Programming
    Replies: 2
    Last Post: 27th January 2009, 13:33
  4. Qt4.1 Transparent Widget
    By djoul in forum Qt Programming
    Replies: 14
    Last Post: 26th September 2006, 17:06
  5. transparent widget
    By hijinks in forum Qt Programming
    Replies: 2
    Last Post: 20th February 2006, 10:43

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.