PDA

View Full Version : transparent QScrollArea and blurry scrolling



titanandrews
14th January 2010, 00:41
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.



QWidget* northPanel = new QWidget(this);
northPanel->setAttribute(Qt::WA_NoBackground);
// add some content to northPanel
QScrollArea* scroller = new QScrollArea(this);
scroller->setAttribute(Qt::WA_NoBackground);
scroller->setWidget(northPanel);


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

titanandrews
16th January 2010, 15:02
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



#include "testwindow.h"

#include <QLabel>
#include <QScrollArea>
#include <QVBoxLayout>

TestWindow::TestWindow(QWidget *parent, Qt::WFlags flags)
: QDialog(parent, flags)
{
ui.setupUi(this);
init();
}

TestWindow::~TestWindow()
{

}

void TestWindow::init()
{
this->setStyleSheet("QDialog { background-color: blue; }");

QVBoxLayout* layout = new QVBoxLayout(this);
QScrollArea* scroller = new QScrollArea(this);
scroller->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn );
scroller->setAttribute(Qt::WA_NoBackground);

QWidget* panel = new QWidget(this);
panel->setAttribute(Qt::WA_NoBackground);
scroller->setWidget(panel);

QHBoxLayout* panelLayout = new QHBoxLayout(this);
panelLayout->setSizeConstraint(QLayout::SetMinAndMaxSize);
panel->setLayout(panelLayout);

QLabel* label = new QLabel(this);
label->setStyleSheet("QLabel { color: red; }");
label->setText("Qt rocks!");
label->setMinimumSize(600, 600);
QFont font("Courier", 24);
label->setFont(font);
panelLayout->addWidget(label);

layout->addWidget(scroller);
setLayout(layout);
}

titanandrews
17th January 2010, 00:35
In case anyone is interested. Use this instead of the attribute.



northPanel->setStyleSheet("background: transparent");
scroller->setStyleSheet("background: transparent");