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.
Code:
northPanel->setAttribute(Qt::WA_NoBackground);
// add some content to northPanel
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
1 Attachment(s)
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
Code:
#include "testwindow.h"
#include <QLabel>
#include <QScrollArea>
#include <QVBoxLayout>
TestWindow
::TestWindow(QWidget *parent, Qt
::WFlags flags
){
ui.setupUi(this);
init();
}
TestWindow::~TestWindow()
{
}
void TestWindow::init()
{
this->setStyleSheet("QDialog { background-color: blue; }");
scroller->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
scroller->setAttribute(Qt::WA_NoBackground);
panel->setAttribute(Qt::WA_NoBackground);
scroller->setWidget(panel);
panelLayout
->setSizeConstraint
(QLayout::SetMinAndMaxSize);
panel->setLayout(panelLayout);
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);
}
Re: transparent QScrollArea and blurry scrolling
In case anyone is interested. Use this instead of the attribute.
Code:
northPanel->setStyleSheet("background: transparent");
scroller->setStyleSheet("background: transparent");