[Qt-interest] implementing scrollbars
Avishek_Sharma
Avishek_Sharma at satyam.com
Thu Dec 18 07:16:13 CET 2008
Hi again,
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:(I have attached the final output in the attached document,pls view it)
1) The pic gets displayed on the textlabel but of a very small size.If you remove the text from the textbox,(here,I have put the text as 'avishek',the picture doesn't show at all....it's like the picture appears in the background of the text that you put on the textLabel.)
Also,when I tried to create the label dynamically(by using QLabel *pic=new QLabel(sv);it didn't work(didn't show the pic at all)
2)no scrollbars are appearing.
3)I tried to set the geometry of the textlabel but though it works when I comment out lines 1,2,5,6 but as soon as I bring the scrollview into picture,it shows the above described results(1 & 2).
I guess it might have to do something with 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.(Have sent a screenshot too,pls see it for the result)....working on Qt3.3
Thanks in advance.
#include<qscrollview.h>
#include<qlabel.h>
void Form1::showscrol()
{
QScrollView* sv = new QScrollView(this); //Line 1
sv->setGeometry(100,80,300,200); //line 2
textLabel1->setGeometry(100,80,300,200); //line 3
textLabel1->setPaletteBackgroundPixmap(QPixmap("/root/Albums/NEW/DSC01059.JPG")); //line4
sv->addChild(textLabel1,100,80); //line5
sv->show(); //line 6
}
-----------------------------------------------------------------------------------------------------------------
I worked on something like this recently. QScrollView will act pretty much like the parent widget of the label. Here's my code:
zoomview = new QScrollView(this);
img = new QLabel(zoomview);
zoomview->addChild(img);
zoomview->setGeometry(0, 30, 240, 290);
zoomview (the QScrollView) will hold img (the label). As img expands or contracts, zoomview will automatically display scrollbars to allow scrolling (unless you have QScrollView::setResizePolicy(QScrollView::Manual))
So basically you will need to make a qscrollview inside your form and put the label as a child of that qscrollview. Apart from setting the enlarged image as the pixmap of the label, you will also need to resize the label to the size of the new picture.
Khizer
Hi,
when implementing 'zoom in' facility,I want scrollbars to appear on the 'label' on which I am displaying the image(label is inside a form say 'Form1').
I am writing down the code for the zoom facility which I presently have with me.
void picture_display::zoomin()
{
QPixmap pm;
enum zoom_values
{
Zoom50, //Zoom50 , Zoom75,Backtonormal can be selected from a dropdown box
Zoom75,
BacktoNormal
};
switch(zoom->currentItem())
{
case Zoom50:
/* what and where to write to bring in the scroll bars*/
pm=pictureresize(path_of_pic,1500,600); //pictureresize() is a manually created function
//to resize pics
pic_display->setPaletteBackgroundPixmap(pm); //pic_display is the label on which I need to show
//the final enlarged pic with the scrollbars
break;
case Zoom75:
...................
}
I went over QScrollView and QScrollArea but couldn't understand the codes properly.
Please give me some idea on what to do.I need to do this for for Qt 3.3 and 4.3.
Thanks in advance.
DISCLAIMER:
This email (including any attachments) is intended for the sole use of the intended recipient/s and may contain material that is CONFIDENTIAL AND PRIVATE COMPANY INFORMATION. Any review or reliance by others or copying or distribution or forwarding of any or all of the contents in this message is STRICTLY PROHIBITED. If you are not the intended recipient, please contact the sender by email and delete all copies; your cooperation in this regard is appreciated.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: result.png
Type: image/png
Size: 151827 bytes
Desc: result.png
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20081218/38912b24/attachment.png
More information about the Qt-interest-old
mailing list