PDA

View Full Version : QScrollArea - Painting happens in background , not in correct widget



bensh
17th March 2010, 21:46
Hi,

i trying to Port a GUI from QT3 to QT4.

The Scrolling in my Widget was implemented using QScrollview.

The painting works correct, but the Pixmap is painted in the background (not the correct widget) in full size and there are no scrollbars.

I think, that the setting of the widget is not happening correct..

The painting is done on viewport()..

Here's the piece of code I think the problem lies:


xxx::xxx(..* , ..* ..) : QScrollArea(parent) {
...

QWidget* widget = new QWidget;
QVBoxLayout* layout = new QVBoxLayout(this);

widget->setLayout(layout);
setWidget(widget);

setBackgroundRole(QPalette::Dark);

...


}


Thx in advance
--
bensh

nish
18th March 2010, 06:37
i suppose you are using the paintevent of your XXX::XXX class?

bensh
18th March 2010, 08:21
yep.. thats what I do..

aamer4yu
18th March 2010, 11:58
Where and how are you painting the pixmap ?

bensh
18th March 2010, 21:59
Thanks for the fast reply..

First in RefreshPixmap the pixmap is created (this works fine.. because it's painted correct, but in the wrong widget)

Then I'm calling from PaintEvent a draw-function where the pixmap is painted onto the widget (viewport()).

Somewhere below has to be the problem, but I already tried everything :((



void xxx::paintEvent(QPaintEvent* event) {


QPainter p;

if (m_Pixmap.isNull()) refreshPixmap();
draw(event->rect().x(), event->rect().y(), event->rect().width(), event->rect().height(),&p);


}

void xxx::draw(int cx, int cy, int cw, int ch, QPainter* p) {
p->begin(viewport());
p->drawPixmap(0, 0, m_Pixmap);

p->drawPixmap(QRectF(cx - this->geometry().x(), cy- this->geometry().y(), cw, ch), m_Pixmap, QRectF(cx- this->geometry().x(), cy - this->geometry().y(), cw, ch));
}

bensh
19th March 2010, 19:13
:(................