Results 1 to 3 of 3

Thread: transparent QScrollArea and blurry scrolling

  1. #1
    Join Date
    Jan 2010
    Posts
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default transparent QScrollArea and blurry scrolling

    Hi All,

    I have the following code to create a QScrollArea that is transparent with it's content also being transparent. So I want the northPanel's parent to show through.

    Qt Code:
    1. QWidget* northPanel = new QWidget(this);
    2. northPanel->setAttribute(Qt::WA_NoBackground);
    3. // add some content to northPanel
    4. QScrollArea* scroller = new QScrollArea(this);
    5. scroller->setAttribute(Qt::WA_NoBackground);
    6. scroller->setWidget(northPanel);
    To copy to clipboard, switch view to plain text mode 

    This works fine. However, when I scroll, the northPanel becomes blurred. I'm pretty sure it's because NoBackground attribute causes those widgets to not paint the background. What am I missing here? How do I make a transparent QScrollArea? Do I need to force a repaint or something?

    many thanks,

    B

  2. #2
    Join Date
    Jan 2010
    Posts
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: transparent QScrollArea and blurry scrolling

    Hi Guys,

    I still have not figured out how to handle this. Here is a code sample. A VS project is also attached. If you make the window small and scroll the scroller horizontally and vertically, you will see the QLabel text blurring. ( I'm not sure blur is the correct word to use. )
    In this example, the scroller is not really transparent ( not sure why ), but anyway that's not the point. It shows the effect I am trying to show. ( actually not show.

    many thanks,

    B

    Qt Code:
    1. #include "testwindow.h"
    2.  
    3. #include <QLabel>
    4. #include <QScrollArea>
    5. #include <QVBoxLayout>
    6.  
    7. TestWindow::TestWindow(QWidget *parent, Qt::WFlags flags)
    8. : QDialog(parent, flags)
    9. {
    10. ui.setupUi(this);
    11. init();
    12. }
    13.  
    14. TestWindow::~TestWindow()
    15. {
    16.  
    17. }
    18.  
    19. void TestWindow::init()
    20. {
    21. this->setStyleSheet("QDialog { background-color: blue; }");
    22.  
    23. QVBoxLayout* layout = new QVBoxLayout(this);
    24. QScrollArea* scroller = new QScrollArea(this);
    25. scroller->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
    26. scroller->setAttribute(Qt::WA_NoBackground);
    27.  
    28. QWidget* panel = new QWidget(this);
    29. panel->setAttribute(Qt::WA_NoBackground);
    30. scroller->setWidget(panel);
    31.  
    32. QHBoxLayout* panelLayout = new QHBoxLayout(this);
    33. panelLayout->setSizeConstraint(QLayout::SetMinAndMaxSize);
    34. panel->setLayout(panelLayout);
    35.  
    36. QLabel* label = new QLabel(this);
    37. label->setStyleSheet("QLabel { color: red; }");
    38. label->setText("Qt rocks!");
    39. label->setMinimumSize(600, 600);
    40. QFont font("Courier", 24);
    41. label->setFont(font);
    42. panelLayout->addWidget(label);
    43.  
    44. layout->addWidget(scroller);
    45. setLayout(layout);
    46. }
    To copy to clipboard, switch view to plain text mode 
    Attached Files Attached Files

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

    Default Re: transparent QScrollArea and blurry scrolling

    In case anyone is interested. Use this instead of the attribute.

    Qt Code:
    1. northPanel->setStyleSheet("background: transparent");
    2. scroller->setStyleSheet("background: transparent");
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. QScrollArea scrolling down not up
    By ntp in forum Qt Programming
    Replies: 5
    Last Post: 20th August 2008, 18:23
  2. QScrollArea transparent
    By bunjee in forum Qt Programming
    Replies: 3
    Last Post: 23rd June 2008, 14:55
  3. Replies: 2
    Last Post: 10th March 2008, 21:16
  4. Scrolling bar problem in QScrollArea
    By YuriyRusinov in forum Qt Programming
    Replies: 1
    Last Post: 4th February 2007, 22:22
  5. Replies: 2
    Last Post: 8th October 2006, 21:14

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.