PDA

View Full Version : implementing 'scrollview'



rishiraj
18th December 2008, 10:54
Hi ,
I created a simple form with a textlabel (textlabel1) and a dropdownbox .If you select any option from the dropdownbox,you should have a pic displayed in the textlabel and have scrollbars on the sides if picture size exceeds the textlabel's area.
The problems that I am having are....
1) The scrollview shows up with the scrollbars but the picture isn't displayed anywhere.

2) If i have some text on top of my text label then a small portion of the picture appears in the background of the text.


3)I tried to set the geometry of the textlabel but though it works when I comment out all the lines except textLabel1->setGeometry(100,80,300,200);
textLabel1->setPaletteBackgroundPixmap(QPixmap("/root/Albums/NEW/DSC01059.JPG"));

But, as soon as I bring the scrollview into picture,it shows the above described results(1 & 2).
I guess it might have something to dowith the label being made a child of the scrollview....I don't know how to get around this problem......Please provide a solution for it,I have been trying for the last 2 days(newbie)

I have attached the code below,please check it out and let me know of the mistakes in it and what changes to make....working on Qt3.3
Thanks in advance.



#include<qscrollview.h>
#include<qlabel.h>


void Form1::showscrol()
{
QScrollView* sv = new QScrollView(this);

sv->setVScrollBarMode(QScrollView::AlwaysOn);
sv->setHScrollBarMode(QScrollView::AlwaysOn);
sv->setGeometry(100,80,300,200);
textLabel1->setGeometry(100,80,300,200);

textLabel1->setPaletteBackgroundPixmap(QPixmap("/root/Albums/NEW/DSC01059.JPG"));
sv->addChild(textLabel1,100,80);
sv->show();


}

wysota
18th December 2008, 12:23
Try this:

QScrollView *sv = new QScrollView(this);
QLabel *label = new QLabel(sv->viewport());
sv->addChild(label);
label->setPixmap(myPixmap); // where myPixmap is... your pixmap