Qt:Документация 4.3.2/qscrollarea

Материал из Wiki.crossplatform.ru

Перейти к: навигация, поиск
40px Внимание: Актуальная версия перевода документации находится здесь

__NOTOC__

Image:qt-logo.png

Главная · Все классы · Основные классы · Классы по группам · Модули · Функции

Image:trolltech-logo.png

Содержание

[править] QScrollArea Class Reference
[модуль QtGui ]

The QScrollArea class provides a scrolling view onto another widget. More...

 #include <QScrollArea>

Inherits QAbstractScrollArea.

[править] Свойства

  • 2 свойства унаследованных от QAbstractScrollArea
  • 6 свойства унаследованных от QFrame
  • 56 свойства унаследованных от QWidget
  • 1 свойство унаследованное от QObject

[править] Открытые функции

  • 15 открытых функций унаследованных от QAbstractScrollArea
  • 13 открытых функций унаследованных от QFrame
  • 201 открытых функций унаследованных от QWidget
  • 29 открытых функций унаследованных от QObject
  • 12 открытых функций унаследованных от QPaintDevice

[править] Дополнительные унаследованные члены

  • 19 открытых слотов унаследованных от QWidget
  • 1 открытый слот унаследованный от QObject
  • 1 сигнал унаследованный от QWidget
  • 1 сигнал унаследованный от QObject
  • 4 статических открытых члена унаследованных от QWidget
  • 5 статических открытых члена унаследованных от QObject
  • 16 защищенных функций унаследованных от QAbstractScrollArea
  • 38 защищенных функций унаследованных от QWidget
  • 7 защищенных функций унаследованных от QObject
  • 1 защищенная функция унаследованна от QPaintDevice
  • 1 защищенный слот унаследованный от QAbstractScrollArea
  • 1 защищенный слот унаследованный от QWidget

[править] Подробное описание

The QScrollArea class provides a scrolling view onto another widget.

A scroll area is used to display the contents of a child widget within a frame. If the widget exceeds the size of the frame, the view can provide scroll bars so that the entire area of the child widget can be viewed. The child widget must be specified with setWidget(). For example:

 QLabel *imageLabel = new QLabel;
 QImage image("happyguy.png");
 imageLabel->setPixmap(QPixmap::fromImage(image));
 
 scrollArea = new QScrollArea;
 scrollArea->setBackgroundRole(QPalette::Dark);
 scrollArea->setWidget(imageLabel);

The code above creates a scroll area (shown in the images below) containing an image label. When scaling the image, the scroll area can provide the necessary scroll bars:


Файл:Qscrollarea-noscrollbars.png Файл:Qscrollarea-onescrollbar.png Файл:Qscrollarea-twoscrollbars.png

The scroll bars appearance depends on the currently set scroll bar policies. You can control the appearance of the scroll bars using the inherited functionality from QAbstractScrollArea.

For example, you can set the QAbstractScrollArea::horizontalScrollBarPolicy and QAbstractScrollArea::verticalScrollBarPolicy properties. Or if you want the scroll bars to adjust dynamically when the contents of the scroll area changes, you can use the horizontalScrollBar() and verticalScrollBar() functions (which enable you to access the scroll bars) and set the scroll bars' values whenever the scroll area's contents change, using the QScrollBar::setValue() function.

You can retrieve the child widget using the widget() function. The view can be made to be resizable with the setWidgetResizable() function. The alignment of the widget can be specified with setAlignment().

When using a scroll area to display the contents of a custom widget, it is important to ensure that the size hint of the child widget is set to a suitable value. If a standard QWidget is used for the child widget, it may be necessary to call QWidget::setMinimumSize() to ensure that the contents of the widget are shown correctly within the scroll area.

Two convenience functions ensureVisible() and ensureWidgetVisible() ensure a certain region of the contents is visible inside the viewport, by scrolling the contents if necessary.

For a complete example using the QScrollArea class, see the Image Viewer example. The example shows how to combine QLabel and QScrollArea to display an image.

See also QAbstractScrollArea, QScrollBar, and Image Viewer Example.


[править] Описание свойств

[править]
alignment : Qt::Alignment

This property holds the alignment of the scroll area's widget.

By default, the widget stays rooted to the top-left corner of the scroll area.

This property was introduced in Qt 4.2.

Функции доступа:

  • Qt::Alignment alignment () const
  • void setAlignment ( Qt::Alignment )

[править]
widgetResizable : bool

This property holds whether the scroll area should resize the view widget.

If this property is set to false (the default), the scroll area honors the size of its widget. Regardless of this property, you can programmatically resize the widget using widget()-> resize(), and the scroll area will automatically adjust itself to the new size.

If this property is set to true, the scroll area will automatically resize the widget in order to avoid scroll bars where they can be avoided, or to take advantage of extra space.

Функции доступа:

  • bool widgetResizable () const
  • void setWidgetResizable ( bool resizable )

[править] Описание функций-членов

[править]
QScrollArea::QScrollArea ( QWidget * parent = 0 )

Constructs an empty scroll area with the given parent.

See also setWidget().

[править]
QScrollArea::~QScrollArea ()

Destroys the scroll area and its child widget.

See also setWidget().

[править]
void QScrollArea::ensureVisible ( int x, int y, int xmargin = 50, int ymargin = 50 )

Scrolls the contents of the scroll area so that the point (x, y) is visible inside the region of the viewport with margins specified in pixels by xmargin and ymargin. If the specified point cannot be reached, the contents are scrolled to the nearest valid position. The default value for both margins is 50 pixels.

[править]
void QScrollArea::ensureWidgetVisible ( QWidget * childWidget, int xmargin = 50, int ymargin = 50 )

Scrolls the contents of the scroll area so that the childWidget of QScrollArea::widget() is visible inside the viewport with margins specified in pixels by xmargin and ymargin. If the specified point cannot be reached, the contents are scrolled to the nearest valid position. The default value for both margins is 50 pixels.

This function was introduced in Qt 4.2.

[править]
void QScrollArea::setWidget ( QWidget * widget )

Sets the scroll area's widget.

The widget becomes a child of the scroll area, and will be destroyed when the scroll area is deleted or when a new widget is set.

Note that if the scroll area is visible when the widget is added, you must show() it explicitly.

See also widget().

[править]
QWidget * QScrollArea::takeWidget ()

Removes the scroll area's widget, and passes ownership of the widget to the caller.

See also widget().

[править]
QWidget * QScrollArea::widget () const

Returns the scroll area's widget, or 0 if there is none.

See also setWidget().


Copyright © 2007 Trolltech Trademarks
Qt 4.3.2