[Qt-interest] FW: Scrolling Contents in QScrollArea
Sujan Dasmahapatra
sdh at lmwindpower.com
Wed Feb 2 11:40:43 CET 2011
Hi Nikos
Thanks for reply. See I have done that for example.
I have subclassed QScrollArea for some other functionalities , such as printing etc. See the code snippet below
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Class MyScrollArea : public QScrollArea
{
Q_OBJECT
Public:
MyScrollArea(QWidget *parent=0);
~MyScrollArea();
};
MyScrollArea::MyScrollArea()
{
QPushButton *button1, *button2;
button1 = new QPushButton(this);
button2 = new QPushButton(this);
setWidget(button1);
setWidget(button2);
}
I want the buttons to one on extreme left and one on extreme right so that I need to scroll them to see.
This much is my code...But I am not able to see the scrollbars on the scrollarea and not able to scroll even. Please tell me what
Can be done on this. Thanks sujan
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Kind Regards,
Sujan Dasmahapatra
Project Leader, Aero Group
Aero Group
Tel +91 80 66470248
Mob
sdh at lmwindpower.com
LM Wind Power Blades
lmwindpower.com
Together we capture the wind to power a cleaner world
This e-mail and any attachments are confidential. If you are not the named or intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Any unauthorized disclosure, use or storage is prohibited and might be unlawful.
-----Original Message-----
From: qt-interest-bounces+sdh=lmwindpower.com at qt.nokia.com [mailto:qt-interest-bounces+sdh=lmwindpower.com at qt.nokia.com] On Behalf Of Nikos Chantziaras
Sent: Wednesday, February 02, 2011 2:58 PM
To: qt-interest at qt.nokia.com
Subject: Re: [Qt-interest] FW: Scrolling Contents in QScrollArea
Do not override scrollContentsBy(). You are not allowed to move the
scrollbars in that function. Also, you should not attempt to move the
widgets manually. QScrollArea will do that for you. You only need to
add the widgets you want into the QScrollArea. Everything else happens
automatically when the user moves the scrollbars.
If you want to scroll programatically, simply use the setValue()
function of the scrollbars from wherever you want, *except* from
scrollContentsBy() which, again, you should not be overriding for this
purpose.
On 02/02/2011 11:00 AM, Sujan Dasmahapatra wrote:
> See I have many widgets that's on the QScrollArea, those are already
> added to the QScrollArea. How can we move all of them together as we
> scroll.. That's what I am looking for. Please help me. Thanks sujan
>
> Kind Regards,
>
> *Sujan Dasmahapatra
> *Project Leader, Aero Group
> Aero Group
>
> Tel +91 80 66470248
> Mob
>
> sdh at lmwindpower.com <mailto:%25EMAIL%25>
>
> *LM Wind Power Blades*
>
> lmwindpower.com
>
> /Together we capture the wind to power a cleaner world/
>
> This e-mail and any attachments are confidential. If you are not the
> named or intended recipient, please notify the sender immediately and do
> not disclose the contents to any other person, use it for any purpose,
> or store or copy the information in any medium. Any unauthorized
> disclosure, use or storage is prohibited and might be unlawful.
>
> *From:*qt-interest-bounces+sdh=lmwindpower.com at qt.nokia.com
> [mailto:qt-interest-bounces+sdh=lmwindpower.com at qt.nokia.com] *On Behalf
> Of *Bo Thorsen
> *Sent:* Wednesday, February 02, 2011 1:30 PM
> *To:* qt-interest at qt.nokia.com
> *Subject:* Re: [Qt-interest] Scrolling Contents in QScrollArea
>
> Den 02-02-2011 08:01, Sujan Dasmahapatra skrev:
>
> Dear Friends
>
> I am using a QScrollArea which I can see some contents in it. By using
> the following code snippet I am able to see both the vertical and
> horizontal scrollbar. I am also implementing the virtual function
>
> //////////////////////////////////////////////////////////////////////////////////////////////////////////
>
>
> #include <QScrollArea>
>
> Class PageForGraph : public QScrollArea
>
> {
>
> Q_OBJECT
>
> Public:
>
> PageForGraph(QWidget *parent=0);
>
> virtual ~PageForGraph();
>
> };
>
> PageForGraph::PageForGraph(QWidget *parent)
>
> {
>
> verticalScrollBar()->setRange(0, 2 * desk->height());
>
> horizontalScrollBar()->setRange(0, 2 * desk->width());
>
> }
>
> void PageForGraph::scrollContentsBy(int dx, int dy)
>
> {
>
> widget()->move(widget()->x() + dx, widget()->y() + dy);
>
> const int x = horizontalScrollBar()->value() + dx;
>
> horizontalScrollBar()->setValue( x );
>
> const int y = verticalScrollBar()->value() + dy;
>
> verticalScrollBar()->setValue( y );
>
> update();
>
> }
>
> But when I moving the scrollbar my contents are not moving. Any help
> would be highly appreciated. Thanks sujan
>
>
> You are moving in the wrong direction here. Implement your graph widget
> to show off the graph and add it to a QScrollArea. And remember to set
> the size of the widget.
>
> If you want to implement a widget that has it's own scrollbars, then
> subclass QWidget, add two scrollbars yourself, and paint the widget
> according to the scrollbar positions.
>
> And please read the documentation for the class:
> http://doc.qt.nokia.com/4.7/qscrollarea.html.
>
> Bo Thorsen,
>
> Fionia Software.
>
>
>
> --
>
>
>
> Expert Qt and C++ developer for hire
>
> Contact me if you need expert Qt help
>
> http://www.fioniasoftware.dk
>
_______________________________________________
Qt-interest mailing list
Qt-interest at qt.nokia.com
http://lists.qt.nokia.com/mailman/listinfo/qt-interest
More information about the Qt-interest-old
mailing list