Don't reference widgets/widgets in example doc.
Change-Id: Ie1fe516f75ca8c1b2233dc6bb2b887b55593e730 Reviewed-by: Martin Smith <martin.smith@nokia.com>bb10
parent
eede34aa6b
commit
3ef3c662fe
|
|
@ -26,7 +26,7 @@
|
|||
****************************************************************************/
|
||||
|
||||
/*!
|
||||
\example widgets/widgets/analogclock
|
||||
\example widgets/analogclock
|
||||
\title Analog Clock Example
|
||||
|
||||
The Analog Clock example shows how to draw the contents of a custom
|
||||
|
|
@ -45,11 +45,11 @@
|
|||
We subclass \l QWidget and reimplement the standard
|
||||
\l{QWidget::paintEvent()}{paintEvent()} function to draw the clock face:
|
||||
|
||||
\snippet widgets/widgets/analogclock/analogclock.h 0
|
||||
\snippet widgets/analogclock/analogclock.h 0
|
||||
|
||||
\section1 AnalogClock Class Implementation
|
||||
|
||||
\snippet widgets/widgets/analogclock/analogclock.cpp 1
|
||||
\snippet widgets/analogclock/analogclock.cpp 1
|
||||
|
||||
When the widget is constructed, we set up a one-second timer to
|
||||
keep track of the current time, and we connect it to the standard
|
||||
|
|
@ -60,8 +60,8 @@
|
|||
Finally, we resize the widget so that it is displayed at a
|
||||
reasonable size.
|
||||
|
||||
\snippet widgets/widgets/analogclock/analogclock.cpp 8
|
||||
\snippet widgets/widgets/analogclock/analogclock.cpp 10
|
||||
\snippet widgets/analogclock/analogclock.cpp 8
|
||||
\snippet widgets/analogclock/analogclock.cpp 10
|
||||
|
||||
The \c paintEvent() function is called whenever the widget's
|
||||
contents need to be updated. This happens when the widget is
|
||||
|
|
@ -80,10 +80,10 @@
|
|||
can fit the clock face inside the widget. It is also useful to determine
|
||||
the current time before we start drawing.
|
||||
|
||||
\snippet widgets/widgets/analogclock/analogclock.cpp 11
|
||||
\snippet widgets/widgets/analogclock/analogclock.cpp 12
|
||||
\snippet widgets/widgets/analogclock/analogclock.cpp 13
|
||||
\snippet widgets/widgets/analogclock/analogclock.cpp 14
|
||||
\snippet widgets/analogclock/analogclock.cpp 11
|
||||
\snippet widgets/analogclock/analogclock.cpp 12
|
||||
\snippet widgets/analogclock/analogclock.cpp 13
|
||||
\snippet widgets/analogclock/analogclock.cpp 14
|
||||
|
||||
The contents of custom widgets are drawn with a QPainter.
|
||||
Painters can be used to draw on any QPaintDevice, but they are
|
||||
|
|
@ -116,37 +116,37 @@
|
|||
hour and minute. This means that the hand will be shown rotated clockwise
|
||||
by the required amount.
|
||||
|
||||
\snippet widgets/widgets/analogclock/analogclock.cpp 15
|
||||
\snippet widgets/widgets/analogclock/analogclock.cpp 16
|
||||
\snippet widgets/analogclock/analogclock.cpp 15
|
||||
\snippet widgets/analogclock/analogclock.cpp 16
|
||||
|
||||
We set the pen to be Qt::NoPen because we don't want any outline,
|
||||
and we use a solid brush with the color appropriate for
|
||||
displaying hours. Brushes are used when filling in polygons and
|
||||
other geometric shapes.
|
||||
|
||||
\snippet widgets/widgets/analogclock/analogclock.cpp 17
|
||||
\snippet widgets/widgets/analogclock/analogclock.cpp 19
|
||||
\snippet widgets/analogclock/analogclock.cpp 17
|
||||
\snippet widgets/analogclock/analogclock.cpp 19
|
||||
|
||||
We save and restore the transformation matrix before and after the
|
||||
rotation because we want to place the minute hand without having to
|
||||
take into account any previous rotations.
|
||||
|
||||
\snippet widgets/widgets/analogclock/analogclock.cpp 20
|
||||
\snippet widgets/analogclock/analogclock.cpp 20
|
||||
\codeline
|
||||
\snippet widgets/widgets/analogclock/analogclock.cpp 21
|
||||
\snippet widgets/analogclock/analogclock.cpp 21
|
||||
|
||||
We draw markers around the edge of the clock for each hour. We
|
||||
draw each marker then rotate the coordinate system so that the
|
||||
painter is ready for the next one.
|
||||
|
||||
\snippet widgets/widgets/analogclock/analogclock.cpp 22
|
||||
\snippet widgets/widgets/analogclock/analogclock.cpp 23
|
||||
\snippet widgets/analogclock/analogclock.cpp 22
|
||||
\snippet widgets/analogclock/analogclock.cpp 23
|
||||
|
||||
The minute hand is rotated in a similar way to the hour hand.
|
||||
|
||||
\snippet widgets/widgets/analogclock/analogclock.cpp 25
|
||||
\snippet widgets/analogclock/analogclock.cpp 25
|
||||
\codeline
|
||||
\snippet widgets/widgets/analogclock/analogclock.cpp 26
|
||||
\snippet widgets/analogclock/analogclock.cpp 26
|
||||
|
||||
Again, we draw markers around the edge of the clock, but this
|
||||
time to indicate minutes. We skip multiples of 5 to avoid drawing
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@
|
|||
****************************************************************************/
|
||||
|
||||
/*!
|
||||
\example widgets/widgets/calculator
|
||||
\example widgets/calculator
|
||||
\title Calculator Example
|
||||
|
||||
The example shows how to use signals and slots to implement the
|
||||
|
|
@ -49,7 +49,7 @@
|
|||
|
||||
\section1 Calculator Class Definition
|
||||
|
||||
\snippet widgets/widgets/calculator/calculator.h 0
|
||||
\snippet widgets/calculator/calculator.h 0
|
||||
|
||||
The \c Calculator class provides a simple calculator widget. It
|
||||
inherits from QDialog and has several private slots associated
|
||||
|
|
@ -65,8 +65,8 @@
|
|||
multiplicative operators (\uicontrol{\unicode{215}}, \uicontrol{\unicode{247}}). The other buttons
|
||||
have their own slots.
|
||||
|
||||
\snippet widgets/widgets/calculator/calculator.h 1
|
||||
\snippet widgets/widgets/calculator/calculator.h 2
|
||||
\snippet widgets/calculator/calculator.h 1
|
||||
\snippet widgets/calculator/calculator.h 2
|
||||
|
||||
The private \c createButton() function is used as part of the
|
||||
widget construction. \c abortOperation() is called whenever a
|
||||
|
|
@ -74,12 +74,12 @@
|
|||
applied to a negative number. \c calculate() applies a binary
|
||||
operator (\uicontrol{+}, \uicontrol{-}, \uicontrol{\unicode{215}}, or \uicontrol{\unicode{247}}).
|
||||
|
||||
\snippet widgets/widgets/calculator/calculator.h 3
|
||||
\snippet widgets/widgets/calculator/calculator.h 4
|
||||
\snippet widgets/widgets/calculator/calculator.h 5
|
||||
\snippet widgets/widgets/calculator/calculator.h 6
|
||||
\snippet widgets/widgets/calculator/calculator.h 7
|
||||
\snippet widgets/widgets/calculator/calculator.h 8
|
||||
\snippet widgets/calculator/calculator.h 3
|
||||
\snippet widgets/calculator/calculator.h 4
|
||||
\snippet widgets/calculator/calculator.h 5
|
||||
\snippet widgets/calculator/calculator.h 6
|
||||
\snippet widgets/calculator/calculator.h 7
|
||||
\snippet widgets/calculator/calculator.h 8
|
||||
|
||||
These variables, together with the contents of the calculator
|
||||
display (a QLineEdit), encode the state of the calculator:
|
||||
|
|
@ -125,24 +125,24 @@
|
|||
they can be applied immediately since the operand is already
|
||||
known when the operator button is clicked.
|
||||
|
||||
\snippet widgets/widgets/calculator/calculator.h 9
|
||||
\snippet widgets/calculator/calculator.h 9
|
||||
\codeline
|
||||
\snippet widgets/widgets/calculator/calculator.h 10
|
||||
\snippet widgets/calculator/calculator.h 10
|
||||
|
||||
Finally, we declare the variables associated with the display and the
|
||||
buttons used to display numerals.
|
||||
|
||||
\section1 Calculator Class Implementation
|
||||
|
||||
\snippet widgets/widgets/calculator/calculator.cpp 0
|
||||
\snippet widgets/calculator/calculator.cpp 0
|
||||
|
||||
In the constructor, we initialize the calculator's state. The \c
|
||||
pendingAdditiveOperator and \c pendingMultiplicativeOperator
|
||||
variables don't need to be initialized explicitly, because the
|
||||
QString constructor initializes them to empty strings.
|
||||
|
||||
\snippet widgets/widgets/calculator/calculator.cpp 1
|
||||
\snippet widgets/widgets/calculator/calculator.cpp 2
|
||||
\snippet widgets/calculator/calculator.cpp 1
|
||||
\snippet widgets/calculator/calculator.cpp 2
|
||||
|
||||
We create the QLineEdit representing the calculator's display and
|
||||
set up some of its properties. In particular, we set it to be
|
||||
|
|
@ -150,13 +150,13 @@
|
|||
|
||||
We also enlarge \c{display}'s font by 8 points.
|
||||
|
||||
\snippet widgets/widgets/calculator/calculator.cpp 4
|
||||
\snippet widgets/calculator/calculator.cpp 4
|
||||
|
||||
For each button, we call the private \c createButton() function with
|
||||
the proper text label and a slot to connect to the button.
|
||||
|
||||
\snippet widgets/widgets/calculator/calculator.cpp 5
|
||||
\snippet widgets/widgets/calculator/calculator.cpp 6
|
||||
\snippet widgets/calculator/calculator.cpp 5
|
||||
\snippet widgets/calculator/calculator.cpp 6
|
||||
|
||||
The layout is handled by a single QGridLayout. The
|
||||
QLayout::setSizeConstraint() call ensures that the \c Calculator
|
||||
|
|
@ -172,7 +172,7 @@
|
|||
column; for these we must also pass a row span and a column
|
||||
span.
|
||||
|
||||
\snippet widgets/widgets/calculator/calculator.cpp 7
|
||||
\snippet widgets/calculator/calculator.cpp 7
|
||||
|
||||
Pressing one of the calculator's digit buttons will emit the
|
||||
button's \l{QToolButton::clicked()}{clicked()} signal, which will
|
||||
|
|
@ -198,8 +198,8 @@
|
|||
|
||||
At the end, we append the new digit to the value in the display.
|
||||
|
||||
\snippet widgets/widgets/calculator/calculator.cpp 8
|
||||
\snippet widgets/widgets/calculator/calculator.cpp 9
|
||||
\snippet widgets/calculator/calculator.cpp 8
|
||||
\snippet widgets/calculator/calculator.cpp 9
|
||||
|
||||
The \c unaryOperatorClicked() slot is called whenever one of the
|
||||
unary operator buttons is clicked. Again a pointer to the clicked
|
||||
|
|
@ -215,8 +215,8 @@
|
|||
digit will be considered as a new operand, instead of being
|
||||
appended to the current value.
|
||||
|
||||
\snippet widgets/widgets/calculator/calculator.cpp 10
|
||||
\snippet widgets/widgets/calculator/calculator.cpp 11
|
||||
\snippet widgets/calculator/calculator.cpp 10
|
||||
\snippet widgets/calculator/calculator.cpp 11
|
||||
|
||||
The \c additiveOperatorClicked() slot is called when the user
|
||||
clicks the \uicontrol{+} or \uicontrol{-} button.
|
||||
|
|
@ -226,16 +226,16 @@
|
|||
multiplicative operators, since these have higher precedence than
|
||||
additive operators:
|
||||
|
||||
\snippet widgets/widgets/calculator/calculator.cpp 12
|
||||
\snippet widgets/widgets/calculator/calculator.cpp 13
|
||||
\snippet widgets/calculator/calculator.cpp 12
|
||||
\snippet widgets/calculator/calculator.cpp 13
|
||||
|
||||
If \uicontrol{\unicode{215}} or \uicontrol{\unicode{247}} has been clicked earlier, without clicking
|
||||
\uicontrol{=} afterward, the current value in the display is the right
|
||||
operand of the \uicontrol{\unicode{215}} or \uicontrol{\unicode{247}} operator and we can finally
|
||||
perform the operation and update the display.
|
||||
|
||||
\snippet widgets/widgets/calculator/calculator.cpp 14
|
||||
\snippet widgets/widgets/calculator/calculator.cpp 15
|
||||
\snippet widgets/calculator/calculator.cpp 14
|
||||
\snippet widgets/calculator/calculator.cpp 15
|
||||
|
||||
If \uicontrol{+} or \uicontrol{-} has been clicked earlier, \c sumSoFar is
|
||||
the left operand and the current value in the display is the
|
||||
|
|
@ -243,8 +243,8 @@
|
|||
operator, \c sumSoFar is simply set to be the text in the
|
||||
display.
|
||||
|
||||
\snippet widgets/widgets/calculator/calculator.cpp 16
|
||||
\snippet widgets/widgets/calculator/calculator.cpp 17
|
||||
\snippet widgets/calculator/calculator.cpp 16
|
||||
\snippet widgets/calculator/calculator.cpp 17
|
||||
|
||||
Finally, we can take care of the operator that was just clicked.
|
||||
Since we don't have the right-hand operand yet, we store the clicked
|
||||
|
|
@ -252,49 +252,49 @@
|
|||
apply the operation later, when we have a right operand, with \c
|
||||
sumSoFar as the left operand.
|
||||
|
||||
\snippet widgets/widgets/calculator/calculator.cpp 18
|
||||
\snippet widgets/calculator/calculator.cpp 18
|
||||
|
||||
The \c multiplicativeOperatorClicked() slot is similar to \c
|
||||
additiveOperatorClicked(). We don't need to worry about pending
|
||||
additive operators here, because multiplicative operators have
|
||||
precedence over additive operators.
|
||||
|
||||
\snippet widgets/widgets/calculator/calculator.cpp 20
|
||||
\snippet widgets/calculator/calculator.cpp 20
|
||||
|
||||
Like in \c additiveOperatorClicked(), we start by handing any
|
||||
pending multiplicative and additive operators. Then we display \c
|
||||
sumSoFar and reset the variable to zero. Resetting the variable
|
||||
to zero is necessary to avoid counting the value twice.
|
||||
|
||||
\snippet widgets/widgets/calculator/calculator.cpp 22
|
||||
\snippet widgets/calculator/calculator.cpp 22
|
||||
|
||||
The \c pointClicked() slot adds a decimal point to the content in
|
||||
\c display.
|
||||
|
||||
\snippet widgets/widgets/calculator/calculator.cpp 24
|
||||
\snippet widgets/calculator/calculator.cpp 24
|
||||
|
||||
The \c changeSignClicked() slot changes the sign of the value in
|
||||
\c display. If the current value is positive, we prepend a minus
|
||||
sign; if the current value is negative, we remove the first
|
||||
character from the value (the minus sign).
|
||||
|
||||
\snippet widgets/widgets/calculator/calculator.cpp 26
|
||||
\snippet widgets/calculator/calculator.cpp 26
|
||||
|
||||
The \c backspaceClicked() removes the rightmost character in the
|
||||
display. If we get an empty string, we show "0" and set \c
|
||||
waitingForOperand to \c true.
|
||||
|
||||
\snippet widgets/widgets/calculator/calculator.cpp 28
|
||||
\snippet widgets/calculator/calculator.cpp 28
|
||||
|
||||
The \c clear() slot resets the current operand to zero. It is
|
||||
equivalent to clicking \uicontrol Backspace enough times to erase the
|
||||
entire operand.
|
||||
|
||||
\snippet widgets/widgets/calculator/calculator.cpp 30
|
||||
\snippet widgets/calculator/calculator.cpp 30
|
||||
|
||||
The \c clearAll() slot resets the calculator to its initial state.
|
||||
|
||||
\snippet widgets/widgets/calculator/calculator.cpp 32
|
||||
\snippet widgets/calculator/calculator.cpp 32
|
||||
|
||||
The \c clearMemory() slot erases the sum kept in memory, \c
|
||||
readMemory() displays the sum as an operand, \c setMemory()
|
||||
|
|
@ -304,18 +304,18 @@
|
|||
equalClicked() to update \c sumSoFar and the value in the
|
||||
display.
|
||||
|
||||
\snippet widgets/widgets/calculator/calculator.cpp 34
|
||||
\snippet widgets/calculator/calculator.cpp 34
|
||||
|
||||
The private \c createButton() function is called from the
|
||||
constructor to create calculator buttons.
|
||||
|
||||
\snippet widgets/widgets/calculator/calculator.cpp 36
|
||||
\snippet widgets/calculator/calculator.cpp 36
|
||||
|
||||
The private \c abortOperation() function is called whenever a
|
||||
calculation fails. It resets the calculator state and displays
|
||||
"####".
|
||||
|
||||
\snippet widgets/widgets/calculator/calculator.cpp 38
|
||||
\snippet widgets/calculator/calculator.cpp 38
|
||||
|
||||
The private \c calculate() function performs a binary operation.
|
||||
The right operand is given by \c rightOperand. For additive
|
||||
|
|
@ -327,7 +327,7 @@
|
|||
|
||||
Let's now take a look at the \c Button class:
|
||||
|
||||
\snippet widgets/widgets/calculator/button.h 0
|
||||
\snippet widgets/calculator/button.h 0
|
||||
|
||||
The \c Button class has a convenience constructor that takes a
|
||||
text label and a parent widget, and it reimplements QWidget::sizeHint()
|
||||
|
|
@ -336,7 +336,7 @@
|
|||
|
||||
\section1 Button Class Implementation
|
||||
|
||||
\snippet widgets/widgets/calculator/button.cpp 0
|
||||
\snippet widgets/calculator/button.cpp 0
|
||||
|
||||
The buttons' appearance is determined by the layout of the
|
||||
calculator widget through the size and
|
||||
|
|
@ -348,8 +348,8 @@
|
|||
expand to fill available space. Without this call, the different
|
||||
buttons in a same column would have different widths.
|
||||
|
||||
\snippet widgets/widgets/calculator/button.cpp 1
|
||||
\snippet widgets/widgets/calculator/button.cpp 2
|
||||
\snippet widgets/calculator/button.cpp 1
|
||||
\snippet widgets/calculator/button.cpp 2
|
||||
|
||||
In \l{QWidget::sizeHint()}{sizeHint()}, we try to return a size
|
||||
that looks good for most buttons. We reuse the size hint of the
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@
|
|||
|
||||
/*!
|
||||
\title Calendar Widget Example
|
||||
\example widgets/widgets/calendarwidget
|
||||
\example widgets/calendarwidget
|
||||
|
||||
The Calendar Widget example shows use of \c QCalendarWidget.
|
||||
|
||||
|
|
@ -84,9 +84,9 @@
|
|||
|
||||
Here is the definition of the \c Window class:
|
||||
|
||||
\snippet widgets/widgets/calendarwidget/window.h 0
|
||||
\snippet widgets/calendarwidget/window.h 0
|
||||
\dots
|
||||
\snippet widgets/widgets/calendarwidget/window.h 1
|
||||
\snippet widgets/calendarwidget/window.h 1
|
||||
|
||||
As is often the case with classes that represent self-contained
|
||||
windows, most of the API is private. We will review the private
|
||||
|
|
@ -96,7 +96,7 @@
|
|||
|
||||
Let's now review the class implementation, starting with the constructor:
|
||||
|
||||
\snippet widgets/widgets/calendarwidget/window.cpp 0
|
||||
\snippet widgets/calendarwidget/window.cpp 0
|
||||
|
||||
We start by creating the four \l{QGroupBox}es and their child
|
||||
widgets (including the QCalendarWidget) using four private \c
|
||||
|
|
@ -116,7 +116,7 @@
|
|||
|
||||
Let's move on to the \c createPreviewGroupBox() function:
|
||||
|
||||
\snippet widgets/widgets/calendarwidget/window.cpp 9
|
||||
\snippet widgets/calendarwidget/window.cpp 9
|
||||
|
||||
The \uicontrol Preview group box contains only one widget: the
|
||||
QCalendarWidget. We set it up, connect its
|
||||
|
|
@ -128,7 +128,7 @@
|
|||
and several widgets are set up the same way; we look at parts of
|
||||
its implementation here and skip the rest:
|
||||
|
||||
\snippet widgets/widgets/calendarwidget/window.cpp 10
|
||||
\snippet widgets/calendarwidget/window.cpp 10
|
||||
\dots
|
||||
|
||||
We start with the setup of the \uicontrol{Week starts on} combobox.
|
||||
|
|
@ -142,7 +142,7 @@
|
|||
C++ will happily convert any enum value to \c int.
|
||||
|
||||
\dots
|
||||
\snippet widgets/widgets/calendarwidget/window.cpp 11
|
||||
\snippet widgets/calendarwidget/window.cpp 11
|
||||
\dots
|
||||
|
||||
After creating the widgets, we connect the signals and slots. We
|
||||
|
|
@ -150,14 +150,14 @@
|
|||
public slots provided by QComboBox.
|
||||
|
||||
\dots
|
||||
\snippet widgets/widgets/calendarwidget/window.cpp 12
|
||||
\snippet widgets/calendarwidget/window.cpp 12
|
||||
|
||||
At the end of the function, we call the slots that update the calendar to ensure
|
||||
that the QCalendarWidget is synchronized with the other widgets on startup.
|
||||
|
||||
Let's now take a look at the \c createDatesGroupBox() private function:
|
||||
|
||||
\snippet widgets/widgets/calendarwidget/window.cpp 13
|
||||
\snippet widgets/calendarwidget/window.cpp 13
|
||||
|
||||
In this function, we create the \uicontrol {Minimum Date}, \uicontrol {Maximum Date},
|
||||
and \uicontrol {Current Date} editor widgets,
|
||||
|
|
@ -166,9 +166,9 @@
|
|||
set in \c createPrivewGroupBox(); we can then set the widgets
|
||||
default values to the calendars values.
|
||||
|
||||
\snippet widgets/widgets/calendarwidget/window.cpp 14
|
||||
\snippet widgets/calendarwidget/window.cpp 14
|
||||
\dots
|
||||
\snippet widgets/widgets/calendarwidget/window.cpp 15
|
||||
\snippet widgets/calendarwidget/window.cpp 15
|
||||
|
||||
We connect the \c currentDateEdit's
|
||||
\l{QDateEdit::}{dateChanged()} signal directly to the calendar's
|
||||
|
|
@ -180,20 +180,20 @@
|
|||
|
||||
Here is the \c createTextFormatsGroup() function:
|
||||
|
||||
\snippet widgets/widgets/calendarwidget/window.cpp 16
|
||||
\snippet widgets/calendarwidget/window.cpp 16
|
||||
|
||||
We set up the \uicontrol {Weekday Color} and \uicontrol {Weekend Color} comboboxes
|
||||
using \c createColorCombo(), which instantiates a QComboBox and
|
||||
populates it with colors ("Red", "Blue", etc.).
|
||||
|
||||
\snippet widgets/widgets/calendarwidget/window.cpp 17
|
||||
\snippet widgets/calendarwidget/window.cpp 17
|
||||
|
||||
The \uicontrol {Header Text Format} combobox lets the user change the
|
||||
text format (bold, italic, or plain) used for horizontal and
|
||||
vertical headers. The \uicontrol {First Friday in blue} and \uicontrol {May 1
|
||||
in red} check box affect the rendering of specific dates.
|
||||
|
||||
\snippet widgets/widgets/calendarwidget/window.cpp 18
|
||||
\snippet widgets/calendarwidget/window.cpp 18
|
||||
|
||||
We connect the check boxes and comboboxes to various private
|
||||
slots. The \uicontrol {First Friday in blue} and \uicontrol {May 1 in red}
|
||||
|
|
@ -201,7 +201,7 @@
|
|||
which is also called when the calendar switches month.
|
||||
|
||||
\dots
|
||||
\snippet widgets/widgets/calendarwidget/window.cpp 19
|
||||
\snippet widgets/calendarwidget/window.cpp 19
|
||||
|
||||
At the end of \c createTextFormatsGroupBox(), we call private
|
||||
slots to synchronize the QCalendarWidget with the other widgets.
|
||||
|
|
@ -210,7 +210,7 @@
|
|||
functions. Let's now take a look at the other private functions
|
||||
and slots.
|
||||
|
||||
\snippet widgets/widgets/calendarwidget/window.cpp 20
|
||||
\snippet widgets/calendarwidget/window.cpp 20
|
||||
|
||||
In \c createColorCombo(), we create a combobox and populate it with
|
||||
standard colors. The second argument to QComboBox::addItem()
|
||||
|
|
@ -219,7 +219,7 @@
|
|||
This function was used to set up the \uicontrol {Weekday Color}
|
||||
and \uicontrol {Weekend Color} comboboxes.
|
||||
|
||||
\snippet widgets/widgets/calendarwidget/window.cpp 1
|
||||
\snippet widgets/calendarwidget/window.cpp 1
|
||||
|
||||
When the user changes the \uicontrol {Week starts on} combobox's
|
||||
value, \c firstDayChanged() is invoked with the index of the
|
||||
|
|
@ -231,12 +231,12 @@
|
|||
verticalHeaderChanged() are very similar to \c firstDayChanged(),
|
||||
so they are omitted.
|
||||
|
||||
\snippet widgets/widgets/calendarwidget/window.cpp 2
|
||||
\snippet widgets/calendarwidget/window.cpp 2
|
||||
|
||||
The \c selectedDateChanged() updates the \uicontrol{Current Date}
|
||||
editor to reflect the current state of the QCalendarWidget.
|
||||
|
||||
\snippet widgets/widgets/calendarwidget/window.cpp 3
|
||||
\snippet widgets/calendarwidget/window.cpp 3
|
||||
|
||||
When the user changes the minimum date, we tell the
|
||||
QCalenderWidget. We also update the \uicontrol {Maximum Date} editor,
|
||||
|
|
@ -244,12 +244,12 @@
|
|||
date, QCalendarWidget will automatically adapt its maximum date
|
||||
to avoid a contradicting state.
|
||||
|
||||
\snippet widgets/widgets/calendarwidget/window.cpp 4
|
||||
\snippet widgets/calendarwidget/window.cpp 4
|
||||
|
||||
\c maximumDateChanged() is implemented similarly to \c
|
||||
minimumDateChanged().
|
||||
|
||||
\snippet widgets/widgets/calendarwidget/window.cpp 5
|
||||
\snippet widgets/calendarwidget/window.cpp 5
|
||||
|
||||
Each combobox item has a QColor object as user data corresponding to the
|
||||
item's text. After fetching the colors from the comboboxes, we
|
||||
|
|
@ -260,13 +260,13 @@
|
|||
specify various character formatting information. In this
|
||||
example, we only show a subset of the possibilities.
|
||||
|
||||
\snippet widgets/widgets/calendarwidget/window.cpp 6
|
||||
\snippet widgets/calendarwidget/window.cpp 6
|
||||
|
||||
\c weekendFormatChanged() is the same as \c
|
||||
weekdayFormatChanged(), except that it affects Saturday and
|
||||
Sunday instead of Monday to Friday.
|
||||
|
||||
\snippet widgets/widgets/calendarwidget/window.cpp 7
|
||||
\snippet widgets/calendarwidget/window.cpp 7
|
||||
|
||||
The \c reformatHeaders() slot is called when the user
|
||||
changes the text format of
|
||||
|
|
@ -275,7 +275,7 @@
|
|||
have been to store \l{QTextCharFormat} values alongside the combobox
|
||||
items.)
|
||||
|
||||
\snippet widgets/widgets/calendarwidget/window.cpp 8
|
||||
\snippet widgets/calendarwidget/window.cpp 8
|
||||
|
||||
In \c reformatCalendarPage(), we set the text format of the first
|
||||
Friday in the month and May 1 in the current year. The text
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@
|
|||
****************************************************************************/
|
||||
|
||||
/*!
|
||||
\example widgets/widgets/charactermap
|
||||
\example widgets/charactermap
|
||||
\title Character Map Example
|
||||
|
||||
The Character Map example shows how to create a custom widget that can
|
||||
|
|
@ -59,7 +59,7 @@ and interaction features.
|
|||
|
||||
The class definition looks like this:
|
||||
|
||||
\snippet widgets/widgets/charactermap/characterwidget.h 0
|
||||
\snippet widgets/charactermap/characterwidget.h 0
|
||||
|
||||
The widget does not contain any other widgets, so it must provide its own
|
||||
size hint to allow its contents to be displayed correctly.
|
||||
|
|
@ -87,7 +87,7 @@ Since the widget is to be used as a simple canvas, the constructor just
|
|||
calls the base class constructor and defines some default values for
|
||||
private data members.
|
||||
|
||||
\snippet widgets/widgets/charactermap/characterwidget.cpp 0
|
||||
\snippet widgets/charactermap/characterwidget.cpp 0
|
||||
|
||||
We initialize \c currentKey with a value of -1 to indicate
|
||||
that no character is initially selected. We enable mouse tracking to
|
||||
|
|
@ -96,21 +96,21 @@ allow us to follow the movement of the cursor across the widget.
|
|||
The class provides two functions to allow the font and style to be set up.
|
||||
Each of these modify the widget's display font and call update():
|
||||
|
||||
\snippet widgets/widgets/charactermap/characterwidget.cpp 1
|
||||
\snippet widgets/charactermap/characterwidget.cpp 1
|
||||
\codeline
|
||||
\snippet widgets/widgets/charactermap/characterwidget.cpp 2
|
||||
\snippet widgets/charactermap/characterwidget.cpp 2
|
||||
|
||||
We use a fixed size font for the display. Similarly, a fixed size hint is
|
||||
provided by the sizeHint() function:
|
||||
|
||||
\snippet widgets/widgets/charactermap/characterwidget.cpp 3
|
||||
\snippet widgets/charactermap/characterwidget.cpp 3
|
||||
|
||||
Three standard event functions are implemented so that the widget
|
||||
can respond to clicks, provide tooltips, and render the available
|
||||
characters. The paintEvent() shows how the contents of the widget are
|
||||
arranged and displayed:
|
||||
|
||||
\snippet widgets/widgets/charactermap/characterwidget.cpp 6
|
||||
\snippet widgets/charactermap/characterwidget.cpp 6
|
||||
|
||||
A QPainter is created for the widget and, in all cases, we ensure that the
|
||||
widget's background is painted. The painter's font is set to the
|
||||
|
|
@ -119,19 +119,19 @@ user-specified display font.
|
|||
The area of the widget that needs to be redrawn is used to determine which
|
||||
characters need to be displayed:
|
||||
|
||||
\snippet widgets/widgets/charactermap/characterwidget.cpp 7
|
||||
\snippet widgets/charactermap/characterwidget.cpp 7
|
||||
|
||||
Using integer division, we obtain the row and column numbers of each
|
||||
characters that should be displayed, and we draw a square on the widget
|
||||
for each character displayed.
|
||||
|
||||
\snippet widgets/widgets/charactermap/characterwidget.cpp 8
|
||||
\snippet widgets/widgets/charactermap/characterwidget.cpp 9
|
||||
\snippet widgets/charactermap/characterwidget.cpp 8
|
||||
\snippet widgets/charactermap/characterwidget.cpp 9
|
||||
|
||||
The symbols for each character in the array are drawn within each square,
|
||||
with the symbol for the most recently selected character displayed in red:
|
||||
|
||||
\snippet widgets/widgets/charactermap/characterwidget.cpp 10
|
||||
\snippet widgets/charactermap/characterwidget.cpp 10
|
||||
|
||||
We do not need to take into account the difference between the area
|
||||
displayed in the viewport and the area we are drawing on because
|
||||
|
|
@ -139,7 +139,7 @@ everything outside the visible area will be clipped.
|
|||
|
||||
The mousePressEvent() defines how the widget responds to mouse clicks.
|
||||
|
||||
\snippet widgets/widgets/charactermap/characterwidget.cpp 5
|
||||
\snippet widgets/charactermap/characterwidget.cpp 5
|
||||
|
||||
We are only interested when the user clicks with the left mouse button
|
||||
over the widget. When this happens, we calculate which character was
|
||||
|
|
@ -158,7 +158,7 @@ The mouseMoveEvent() maps the mouse cursor's position in global
|
|||
coordinates to widget coordinates, and determines the character that
|
||||
was clicked by performing the calculation
|
||||
|
||||
\snippet widgets/widgets/charactermap/characterwidget.cpp 4
|
||||
\snippet widgets/charactermap/characterwidget.cpp 4
|
||||
|
||||
The tooltip is given a position defined in global coordinates.
|
||||
|
||||
|
|
@ -171,7 +171,7 @@ interface.
|
|||
|
||||
The class definition looks like this:
|
||||
|
||||
\snippet widgets/widgets/charactermap/mainwindow.h 0
|
||||
\snippet widgets/charactermap/mainwindow.h 0
|
||||
|
||||
The main window contains various widgets that are used to control how
|
||||
the characters will be displayed, and defines the findFonts() function
|
||||
|
|
@ -188,7 +188,7 @@ some standard widgets (two comboboxes, a line edit, and a push button).
|
|||
We also construct a CharacterWidget custom widget, and add a QScrollArea
|
||||
so that we can view its contents:
|
||||
|
||||
\snippet widgets/widgets/charactermap/mainwindow.cpp 0
|
||||
\snippet widgets/charactermap/mainwindow.cpp 0
|
||||
|
||||
QScrollArea provides a viewport onto the \c CharacterWidget when we set
|
||||
its widget and handles much of the work needed to provide a scrolling
|
||||
|
|
@ -198,11 +198,11 @@ The font combo box is automatically popuplated with a list of available
|
|||
fonts. We list the available styles for the current font in the style
|
||||
combobox using the following function:
|
||||
|
||||
\snippet widgets/widgets/charactermap/mainwindow.cpp 1
|
||||
\snippet widgets/charactermap/mainwindow.cpp 1
|
||||
|
||||
The line edit and push button are used to supply text to the clipboard:
|
||||
|
||||
\snippet widgets/widgets/charactermap/mainwindow.cpp 2
|
||||
\snippet widgets/charactermap/mainwindow.cpp 2
|
||||
|
||||
We also obtain a clipboard object so that we can send text entered by the
|
||||
user to other applications.
|
||||
|
|
@ -211,7 +211,7 @@ Most of the signals emitted in the example come from standard widgets.
|
|||
We connect these signals to slots in this class, and to the slots provided
|
||||
by other widgets.
|
||||
|
||||
\snippet widgets/widgets/charactermap/mainwindow.cpp 4
|
||||
\snippet widgets/charactermap/mainwindow.cpp 4
|
||||
|
||||
The font combobox's
|
||||
\l{QFontComboBox::currentFontChanged()}{currentFontChanged()} signal is
|
||||
|
|
@ -225,7 +225,7 @@ directly to the character widget.
|
|||
The final two connections allow characters to be selected in the character
|
||||
widget, and text to be inserted into the clipboard:
|
||||
|
||||
\snippet widgets/widgets/charactermap/mainwindow.cpp 5
|
||||
\snippet widgets/charactermap/mainwindow.cpp 5
|
||||
|
||||
The character widget emits the characterSelected() custom signal when
|
||||
the user clicks on a character, and this is handled by the insertCharacter()
|
||||
|
|
@ -235,20 +235,20 @@ the clicked() signal, and we handle this with the updateClipboard() function.
|
|||
The remaining code in the constructor sets up the layout of the central widget,
|
||||
and provides a window title:
|
||||
|
||||
\snippet widgets/widgets/charactermap/mainwindow.cpp 6
|
||||
\snippet widgets/charactermap/mainwindow.cpp 6
|
||||
|
||||
The font combobox is automatically populated with a list of available font
|
||||
families. The styles that can be used with each font are found by the
|
||||
findStyles() function. This function is called whenever the user selects a
|
||||
different font in the font combobox.
|
||||
|
||||
\snippet widgets/widgets/charactermap/mainwindow.cpp 7
|
||||
\snippet widgets/charactermap/mainwindow.cpp 7
|
||||
|
||||
We begin by recording the currently selected style, and we clear the
|
||||
style combobox so that we can insert the styles associated with the
|
||||
current font family.
|
||||
|
||||
\snippet widgets/widgets/charactermap/mainwindow.cpp 8
|
||||
\snippet widgets/charactermap/mainwindow.cpp 8
|
||||
|
||||
We use the font database to collect the styles that are available for the
|
||||
current font, and insert them into the style combobox. The current item is
|
||||
|
|
@ -259,7 +259,7 @@ widget and the main window's push button. The insertCharacter() function is
|
|||
used to insert characters from the character widget when the user clicks a
|
||||
character:
|
||||
|
||||
\snippet widgets/widgets/charactermap/mainwindow.cpp 9
|
||||
\snippet widgets/charactermap/mainwindow.cpp 9
|
||||
|
||||
The character is inserted into the line edit at the current cursor position.
|
||||
|
||||
|
|
@ -267,7 +267,7 @@ The main window's "To clipboard" push button is connected to the
|
|||
updateClipboard() function so that, when it is clicked, the clipboard is
|
||||
updated to contain the contents of the line edit:
|
||||
|
||||
\snippet widgets/widgets/charactermap/mainwindow.cpp 10
|
||||
\snippet widgets/charactermap/mainwindow.cpp 10
|
||||
|
||||
We copy all the text from the line edit to the clipboard, but we do not clear
|
||||
the line edit.
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@
|
|||
indexAt(). However, the view needs to maintain strict control over its look and
|
||||
feel, so we also provide implementations for a number of other functions:
|
||||
|
||||
\snippet widgets/widgets/itemviews/chart/pieview.h 0
|
||||
\snippet widgets/itemviews/chart/pieview.h 0
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@
|
|||
****************************************************************************/
|
||||
|
||||
/*!
|
||||
\example widgets/widgets/codeeditor
|
||||
\example widgets/codeeditor
|
||||
\title Code Editor Example
|
||||
|
||||
The Code Editor example shows how to create a simple editor that
|
||||
|
|
@ -80,13 +80,13 @@
|
|||
extend the editor with breakpoints or other code editor features.
|
||||
The widget would then help in the handling of mouse events.
|
||||
|
||||
\snippet widgets/widgets/codeeditor/codeeditor.h extraarea
|
||||
\snippet widgets/codeeditor/codeeditor.h extraarea
|
||||
|
||||
\section1 CodeEditor Class Definition
|
||||
|
||||
Here is the code editor's class definition:
|
||||
|
||||
\snippet widgets/widgets/codeeditor/codeeditor.h codeeditordefinition
|
||||
\snippet widgets/codeeditor/codeeditor.h codeeditordefinition
|
||||
|
||||
In the editor we resize and draw the line numbers on the \c
|
||||
LineNumberArea. We need to do this when the number of lines in the
|
||||
|
|
@ -102,37 +102,37 @@
|
|||
We will now go through the code editors implementation, starting
|
||||
off with the constructor.
|
||||
|
||||
\snippet widgets/widgets/codeeditor/codeeditor.cpp constructor
|
||||
\snippet widgets/codeeditor/codeeditor.cpp constructor
|
||||
|
||||
In the constructor we connect our slots to signals in
|
||||
QPlainTextEdit. It is necessary to calculate the line number area
|
||||
width and highlight the first line when the editor is created.
|
||||
|
||||
\snippet widgets/widgets/codeeditor/codeeditor.cpp extraAreaWidth
|
||||
\snippet widgets/codeeditor/codeeditor.cpp extraAreaWidth
|
||||
|
||||
The \c lineNumberAreaWidth() function calculates the width of the
|
||||
\c LineNumberArea widget. We take the number of digits in the last
|
||||
line of the editor and multiply that with the maximum width of a
|
||||
digit.
|
||||
|
||||
\snippet widgets/widgets/codeeditor/codeeditor.cpp slotUpdateExtraAreaWidth
|
||||
\snippet widgets/codeeditor/codeeditor.cpp slotUpdateExtraAreaWidth
|
||||
|
||||
When we update the width of the line number area, we simply call
|
||||
QAbstractScrollArea::setViewportMargins().
|
||||
|
||||
\snippet widgets/widgets/codeeditor/codeeditor.cpp slotUpdateRequest
|
||||
\snippet widgets/codeeditor/codeeditor.cpp slotUpdateRequest
|
||||
|
||||
This slot is invoked when the editors viewport has been scrolled.
|
||||
The QRect given as argument is the part of the editing area that
|
||||
is do be updated (redrawn). \c dy holds the number of pixels the
|
||||
view has been scrolled vertically.
|
||||
|
||||
\snippet widgets/widgets/codeeditor/codeeditor.cpp resizeEvent
|
||||
\snippet widgets/codeeditor/codeeditor.cpp resizeEvent
|
||||
|
||||
When the size of the editor changes, we also need to resize the
|
||||
line number area.
|
||||
|
||||
\snippet widgets/widgets/codeeditor/codeeditor.cpp cursorPositionChanged
|
||||
\snippet widgets/codeeditor/codeeditor.cpp cursorPositionChanged
|
||||
|
||||
When the cursor position changes, we highlight the current line,
|
||||
i.e., the line containing the cursor.
|
||||
|
|
@ -151,13 +151,13 @@
|
|||
block, the cursor should be moved with QTextCursor::movePosition()
|
||||
from a position set with \l{QTextCursor::}{setPosition()}.
|
||||
|
||||
\snippet widgets/widgets/codeeditor/codeeditor.cpp extraAreaPaintEvent_0
|
||||
\snippet widgets/codeeditor/codeeditor.cpp extraAreaPaintEvent_0
|
||||
|
||||
The \c lineNumberAreaPaintEvent() is called from \c LineNumberArea
|
||||
whenever it receives a paint event. We start off by painting the
|
||||
widget's background.
|
||||
|
||||
\snippet widgets/widgets/codeeditor/codeeditor.cpp extraAreaPaintEvent_1
|
||||
\snippet widgets/codeeditor/codeeditor.cpp extraAreaPaintEvent_1
|
||||
|
||||
We will now loop through all visible lines and paint the line
|
||||
numbers in the extra area for each line. Notice that in a plain
|
||||
|
|
@ -169,7 +169,7 @@
|
|||
and adjust these values by the height of the current text block in
|
||||
each iteration in the loop.
|
||||
|
||||
\snippet widgets/widgets/codeeditor/codeeditor.cpp extraAreaPaintEvent_2
|
||||
\snippet widgets/codeeditor/codeeditor.cpp extraAreaPaintEvent_2
|
||||
|
||||
Notice that we check if the block is visible in addition to check
|
||||
if it is in the areas viewport - a block can, for example, be
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@
|
|||
****************************************************************************/
|
||||
|
||||
/*!
|
||||
\example widgets/widgets/digitalclock
|
||||
\example widgets/digitalclock
|
||||
\title Digital Clock Example
|
||||
|
||||
The Digital Clock example shows how to use QLCDNumber to display a
|
||||
|
|
@ -44,11 +44,11 @@
|
|||
and implement a private slot called \c showTime() to update the clock
|
||||
display:
|
||||
|
||||
\snippet widgets/widgets/digitalclock/digitalclock.h 0
|
||||
\snippet widgets/digitalclock/digitalclock.h 0
|
||||
|
||||
\section1 DigitalClock Class Implementation
|
||||
|
||||
\snippet widgets/widgets/digitalclock/digitalclock.cpp 0
|
||||
\snippet widgets/digitalclock/digitalclock.cpp 0
|
||||
|
||||
In the constructor, we first change the look of the LCD numbers. The
|
||||
QLCDNumber::Filled style produces raised segments filled with the
|
||||
|
|
@ -59,8 +59,8 @@
|
|||
call the \c showTime() slot; without this call, there would be a one-second
|
||||
delay at startup before the time is shown.
|
||||
|
||||
\snippet widgets/widgets/digitalclock/digitalclock.cpp 1
|
||||
\snippet widgets/widgets/digitalclock/digitalclock.cpp 2
|
||||
\snippet widgets/digitalclock/digitalclock.cpp 1
|
||||
\snippet widgets/digitalclock/digitalclock.cpp 2
|
||||
|
||||
The \c showTime() slot is called whenever the clock display needs
|
||||
to be updated.
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@
|
|||
****************************************************************************/
|
||||
|
||||
/*!
|
||||
\example widgets/widgets/elidedlabel
|
||||
\example widgets/elidedlabel
|
||||
\group all-examples
|
||||
\title Elided Label Example
|
||||
|
||||
|
|
@ -51,7 +51,7 @@
|
|||
the \c ElidedLabel class:
|
||||
|
||||
|
||||
\snippet widgets/widgets/elidedlabel/elidedlabel.h 0
|
||||
\snippet widgets/elidedlabel/elidedlabel.h 0
|
||||
|
||||
The \c isElided property depends the font, text content and geometry of the
|
||||
widget. Whenever any of these change, the \c elisionChanged() signal might
|
||||
|
|
@ -65,11 +65,11 @@
|
|||
policy to be horizontally expanding, since it's meant to fill the width of
|
||||
its container and grow vertically.
|
||||
|
||||
\snippet widgets/widgets/elidedlabel/elidedlabel.cpp 0
|
||||
\snippet widgets/elidedlabel/elidedlabel.cpp 0
|
||||
|
||||
Changing the \c content require a repaint of the widget.
|
||||
|
||||
\snippet widgets/widgets/elidedlabel/elidedlabel.cpp 1
|
||||
\snippet widgets/elidedlabel/elidedlabel.cpp 1
|
||||
|
||||
QTextLayout is used in the \c paintEvent() to divide the \c content into
|
||||
lines, that wrap on word boundaries. Each line, except the last visible
|
||||
|
|
@ -77,7 +77,7 @@
|
|||
method of QTextLine will draw the line using the coordinate point as the
|
||||
top left corner.
|
||||
|
||||
\snippet widgets/widgets/elidedlabel/elidedlabel.cpp 2
|
||||
\snippet widgets/elidedlabel/elidedlabel.cpp 2
|
||||
|
||||
Unfortunately, QTextLayout does not elide text, so the last visible line
|
||||
has to be treated differently. This last line is elided if it is too wide.
|
||||
|
|
@ -86,12 +86,12 @@
|
|||
|
||||
Finally, one more line is created to see if everything fit on this line.
|
||||
|
||||
\snippet widgets/widgets/elidedlabel/elidedlabel.cpp 3
|
||||
\snippet widgets/elidedlabel/elidedlabel.cpp 3
|
||||
|
||||
If the text was elided and wasn't before or vice versa, cache it in
|
||||
\c elided and emit the change.
|
||||
|
||||
\snippet widgets/widgets/elidedlabel/elidedlabel.cpp 4
|
||||
\snippet widgets/elidedlabel/elidedlabel.cpp 4
|
||||
|
||||
|
||||
\section1 TestWidget Class Definition
|
||||
|
|
@ -99,55 +99,55 @@
|
|||
\c TestWidget is a QWidget and is the main window of the example. It
|
||||
contains an \c ElidedLabel which can be resized with two QSlider widgets.
|
||||
|
||||
\snippet widgets/widgets/elidedlabel/testwidget.h 0
|
||||
\snippet widgets/elidedlabel/testwidget.h 0
|
||||
|
||||
\section1 TestWidget Class Implementation
|
||||
|
||||
The constructor initializes the whole widget. Strings of different length
|
||||
are stored in \c textSamples. The user is able to switch between these.
|
||||
|
||||
\snippet widgets/widgets/elidedlabel/testwidget.cpp 0
|
||||
\snippet widgets/elidedlabel/testwidget.cpp 0
|
||||
|
||||
An \c ElidedLabel is created to contain the first of the sample strings.
|
||||
The frame is made visible to make it easier to see the actual size of the
|
||||
widget.
|
||||
|
||||
\snippet widgets/widgets/elidedlabel/testwidget.cpp 1
|
||||
\snippet widgets/elidedlabel/testwidget.cpp 1
|
||||
|
||||
The buttons and the elision label are created. By connecting the
|
||||
\c elisionChanged() signal to the \c setVisible() slot of the \c label,
|
||||
it will act as an indicator to when the text is elided or not. This signal
|
||||
could, for instance, be used to make a "More" button visible, or similar.
|
||||
|
||||
\snippet widgets/widgets/elidedlabel/testwidget.cpp 2
|
||||
\snippet widgets/elidedlabel/testwidget.cpp 2
|
||||
|
||||
The \c widthSlider and \c heightSlider specify the size of the
|
||||
\c elidedText. Since the y-axis is inverted, the \c heightSlider has to be
|
||||
inverted to act appropriately.
|
||||
|
||||
\snippet widgets/widgets/elidedlabel/testwidget.cpp 3
|
||||
\snippet widgets/elidedlabel/testwidget.cpp 3
|
||||
|
||||
The components are all stored in a QGridLayout, which is made the layout of
|
||||
the \c TestWidget.
|
||||
|
||||
\snippet widgets/widgets/elidedlabel/testwidget.cpp 4
|
||||
\snippet widgets/elidedlabel/testwidget.cpp 4
|
||||
|
||||
On the Maemo platform, windows are stuck in landscape mode by default. With
|
||||
this attribute set, the window manager is aware that this window can be
|
||||
rotated.
|
||||
|
||||
\snippet widgets/widgets/elidedlabel/testwidget.cpp 5
|
||||
\snippet widgets/elidedlabel/testwidget.cpp 5
|
||||
|
||||
The \c widthSlider and \c heightSlider have the exact same length as the
|
||||
dimensions of the \c elidedText. The maximum value for both of them is
|
||||
thus their lengths, and each tick indicates one pixel.
|
||||
|
||||
\snippet widgets/widgets/elidedlabel/testwidget.cpp 6
|
||||
\snippet widgets/elidedlabel/testwidget.cpp 6
|
||||
|
||||
The \c switchText() slot simply cycles through all the available sample
|
||||
texts.
|
||||
|
||||
\snippet widgets/widgets/elidedlabel/testwidget.cpp 7
|
||||
\snippet widgets/elidedlabel/testwidget.cpp 7
|
||||
|
||||
These slots set the width and height of the \c elided text, in response to
|
||||
changes in the sliders.
|
||||
|
|
@ -157,6 +157,6 @@
|
|||
The \c main() function creates an instance of \c TestWidget fullscreen and
|
||||
enters the message loop.
|
||||
|
||||
\snippet widgets/widgets/elidedlabel/main.cpp 0
|
||||
\snippet widgets/elidedlabel/main.cpp 0
|
||||
*/
|
||||
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@
|
|||
****************************************************************************/
|
||||
|
||||
/*!
|
||||
\example widgets/widgets/groupbox
|
||||
\example widgets/groupbox
|
||||
\title Group Box Example
|
||||
|
||||
The Group Box example shows how to use the different kinds of group
|
||||
|
|
@ -54,7 +54,7 @@
|
|||
functions to construct each group box and populate it with different
|
||||
selections of button widgets:
|
||||
|
||||
\snippet widgets/widgets/groupbox/window.h 0
|
||||
\snippet widgets/groupbox/window.h 0
|
||||
|
||||
In the example, the widget will be used as a top-level window, so
|
||||
the constructor is defined so that we do not have to specify a parent
|
||||
|
|
@ -65,12 +65,12 @@
|
|||
The constructor creates a grid layout and fills it with each of the
|
||||
group boxes that are to be displayed:
|
||||
|
||||
\snippet widgets/widgets/groupbox/window.cpp 0
|
||||
\snippet widgets/groupbox/window.cpp 0
|
||||
|
||||
The functions used to create each group box each return a
|
||||
QGroupBox to be inserted into the grid layout.
|
||||
|
||||
\snippet widgets/widgets/groupbox/window.cpp 1
|
||||
\snippet widgets/groupbox/window.cpp 1
|
||||
|
||||
The first group box contains and manages three radio buttons. Since
|
||||
the group box contains only radio buttons, it is exclusive by
|
||||
|
|
@ -78,7 +78,7 @@
|
|||
We check the first radio button to ensure that the button group
|
||||
contains one checked button.
|
||||
|
||||
\snippet widgets/widgets/groupbox/window.cpp 3
|
||||
\snippet widgets/groupbox/window.cpp 3
|
||||
|
||||
We use a vertical layout within the group box to present the
|
||||
buttons in the form of a vertical list, and return the group
|
||||
|
|
@ -89,52 +89,52 @@
|
|||
unchecked, so the group box itself must be checked before any of
|
||||
the radio buttons inside can be checked.
|
||||
|
||||
\snippet widgets/widgets/groupbox/window.cpp 4
|
||||
\snippet widgets/groupbox/window.cpp 4
|
||||
|
||||
The group box contains three exclusive radio buttons, and an
|
||||
independent checkbox. For consistency, one radio button must be
|
||||
checked at all times, so we ensure that the first one is initially
|
||||
checked.
|
||||
|
||||
\snippet widgets/widgets/groupbox/window.cpp 5
|
||||
\snippet widgets/groupbox/window.cpp 5
|
||||
|
||||
The buttons are arranged in the same way as those in the first
|
||||
group box.
|
||||
|
||||
\snippet widgets/widgets/groupbox/window.cpp 6
|
||||
\snippet widgets/groupbox/window.cpp 6
|
||||
|
||||
The third group box is constructed with a "flat" style that is
|
||||
better suited to certain types of dialog.
|
||||
|
||||
\snippet widgets/widgets/groupbox/window.cpp 7
|
||||
\snippet widgets/groupbox/window.cpp 7
|
||||
|
||||
This group box contains only checkboxes, so it is non-exclusive by
|
||||
default. This means that each checkbox can be checked independently
|
||||
of the others.
|
||||
|
||||
\snippet widgets/widgets/groupbox/window.cpp 8
|
||||
\snippet widgets/groupbox/window.cpp 8
|
||||
|
||||
Again, we use a vertical layout within the group box to present
|
||||
the buttons in the form of a vertical list.
|
||||
|
||||
\snippet widgets/widgets/groupbox/window.cpp 9
|
||||
\snippet widgets/groupbox/window.cpp 9
|
||||
|
||||
The final group box contains only push buttons and, like the
|
||||
second group box, it is checkable.
|
||||
|
||||
\snippet widgets/widgets/groupbox/window.cpp 10
|
||||
\snippet widgets/groupbox/window.cpp 10
|
||||
|
||||
We create a normal button, a toggle button, and a flat push button:
|
||||
|
||||
\snippet widgets/widgets/groupbox/window.cpp 11
|
||||
\snippet widgets/groupbox/window.cpp 11
|
||||
|
||||
Push buttons can be used to display popup menus. We create one, and
|
||||
attach a simple menu to it:
|
||||
|
||||
\snippet widgets/widgets/groupbox/window.cpp 12
|
||||
\snippet widgets/groupbox/window.cpp 12
|
||||
|
||||
Finally, we lay out the widgets vertically, and return the group box
|
||||
that we created:
|
||||
|
||||
\snippet widgets/widgets/groupbox/window.cpp 13
|
||||
\snippet widgets/groupbox/window.cpp 13
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@
|
|||
****************************************************************************/
|
||||
|
||||
/*!
|
||||
\example widgets/widgets/icons
|
||||
\example widgets/icons
|
||||
\title Icons Example
|
||||
|
||||
The Icons example shows how QIcon can generate pixmaps reflecting
|
||||
|
|
@ -246,7 +246,7 @@
|
|||
|
||||
\image icons_preview_area.png Screenshot of IconPreviewArea.
|
||||
|
||||
\snippet widgets/widgets/icons/iconpreviewarea.h 0
|
||||
\snippet widgets/icons/iconpreviewarea.h 0
|
||||
|
||||
The \c IconPreviewArea class inherits QWidget. It displays the
|
||||
generated pixmaps corresponding to an icon's possible states and
|
||||
|
|
@ -264,7 +264,7 @@
|
|||
|
||||
\section2 IconPreviewArea Class Implementation
|
||||
|
||||
\snippet widgets/widgets/icons/iconpreviewarea.cpp 0
|
||||
\snippet widgets/icons/iconpreviewarea.cpp 0
|
||||
|
||||
In the constructor we create the labels displaying the headers and
|
||||
the icon's generated pixmaps, and add them to a grid layout.
|
||||
|
|
@ -300,24 +300,24 @@
|
|||
Another approach is to add this line directly to the \c .pro
|
||||
file.
|
||||
|
||||
\snippet widgets/widgets/icons/iconpreviewarea.cpp 1
|
||||
\snippet widgets/icons/iconpreviewarea.cpp 1
|
||||
\codeline
|
||||
\snippet widgets/widgets/icons/iconpreviewarea.cpp 2
|
||||
\snippet widgets/icons/iconpreviewarea.cpp 2
|
||||
|
||||
The public \c setIcon() and \c setSize() functions change the icon
|
||||
or the icon size, and make sure that the generated pixmaps are
|
||||
updated.
|
||||
|
||||
\snippet widgets/widgets/icons/iconpreviewarea.cpp 3
|
||||
\snippet widgets/icons/iconpreviewarea.cpp 3
|
||||
\codeline
|
||||
\snippet widgets/widgets/icons/iconpreviewarea.cpp 4
|
||||
\snippet widgets/icons/iconpreviewarea.cpp 4
|
||||
|
||||
We use the \c createHeaderLabel() and \c createPixmapLabel()
|
||||
functions to create the preview area's labels displaying the
|
||||
headers and the icon's generated pixmaps. Both functions return
|
||||
the QLabel that is created.
|
||||
|
||||
\snippet widgets/widgets/icons/iconpreviewarea.cpp 5
|
||||
\snippet widgets/icons/iconpreviewarea.cpp 5
|
||||
|
||||
We use the private \c updatePixmapLabel() function to update the
|
||||
generated pixmaps displayed in the preview area.
|
||||
|
|
@ -333,7 +333,7 @@
|
|||
|
||||
\image icons-example.png Screenshot of the Icons example
|
||||
|
||||
\snippet widgets/widgets/icons/mainwindow.h 0
|
||||
\snippet widgets/icons/mainwindow.h 0
|
||||
|
||||
The MainWindow class inherits from QMainWindow. We reimplement the
|
||||
constructor, and declare several private slots:
|
||||
|
|
@ -354,7 +354,7 @@
|
|||
|
||||
\section2 MainWindow Class Implementation
|
||||
|
||||
\snippet widgets/widgets/icons/mainwindow.cpp 0
|
||||
\snippet widgets/icons/mainwindow.cpp 0
|
||||
|
||||
In the constructor we first create the main window's central
|
||||
widget and its child widgets, and put them in a grid layout. Then
|
||||
|
|
@ -366,7 +366,7 @@
|
|||
associated radio button, making the current value of the spin box
|
||||
the icon's initial size.
|
||||
|
||||
\snippet widgets/widgets/icons/mainwindow.cpp 1
|
||||
\snippet widgets/icons/mainwindow.cpp 1
|
||||
|
||||
The \c about() slot displays a message box using the static
|
||||
QMessageBox::about() function. In this example it displays a
|
||||
|
|
@ -378,7 +378,7 @@
|
|||
parent, and if that fails, it tries the active window. As a last
|
||||
resort it uses the QMessageBox's Information icon.
|
||||
|
||||
\snippet widgets/widgets/icons/mainwindow.cpp 2
|
||||
\snippet widgets/icons/mainwindow.cpp 2
|
||||
|
||||
In the \c changeStyle() slot we first check the slot's
|
||||
parameter. If it is false we immediately return, otherwise we find
|
||||
|
|
@ -394,8 +394,8 @@
|
|||
pointers are much easier to diagnose than crashes due to unsafe
|
||||
casts.
|
||||
|
||||
\snippet widgets/widgets/icons/mainwindow.cpp 3
|
||||
\snippet widgets/widgets/icons/mainwindow.cpp 4
|
||||
\snippet widgets/icons/mainwindow.cpp 3
|
||||
\snippet widgets/icons/mainwindow.cpp 4
|
||||
|
||||
Once we have the action, we extract the style name using
|
||||
QAction::data(). Then we create a QStyle object using the static
|
||||
|
|
@ -414,7 +414,7 @@
|
|||
group box and in the end call the \c changeSize() slot to update
|
||||
the icon's size.
|
||||
|
||||
\snippet widgets/widgets/icons/mainwindow.cpp 5
|
||||
\snippet widgets/icons/mainwindow.cpp 5
|
||||
|
||||
The \c changeSize() slot sets the size for the preview area's
|
||||
icon.
|
||||
|
|
@ -427,7 +427,7 @@
|
|||
based on the extent, and use that object to set the size of the
|
||||
preview area's icon.
|
||||
|
||||
\snippet widgets/widgets/icons/mainwindow.cpp 12
|
||||
\snippet widgets/icons/mainwindow.cpp 12
|
||||
|
||||
The first thing we do when the \c addImage() slot is called, is to
|
||||
show a file dialog to the user. The easiest way to create a file
|
||||
|
|
@ -439,8 +439,8 @@
|
|||
table widget. The table widget is listing the images the user has
|
||||
loaded into the application.
|
||||
|
||||
\snippet widgets/widgets/icons/mainwindow.cpp 13
|
||||
\snippet widgets/widgets/icons/mainwindow.cpp 14
|
||||
\snippet widgets/icons/mainwindow.cpp 13
|
||||
\snippet widgets/icons/mainwindow.cpp 14
|
||||
|
||||
We retrieve the image name using the QFileInfo::baseName()
|
||||
function that returns the base name of the file without the path,
|
||||
|
|
@ -453,9 +453,9 @@
|
|||
We also make sure that the item is not editable by removing the
|
||||
Qt::ItemIsEditable flag. Table items are editable by default.
|
||||
|
||||
\snippet widgets/widgets/icons/mainwindow.cpp 15
|
||||
\snippet widgets/widgets/icons/mainwindow.cpp 16
|
||||
\snippet widgets/widgets/icons/mainwindow.cpp 17
|
||||
\snippet widgets/icons/mainwindow.cpp 15
|
||||
\snippet widgets/icons/mainwindow.cpp 16
|
||||
\snippet widgets/icons/mainwindow.cpp 17
|
||||
|
||||
Then we create the second and third items in the row making the
|
||||
default mode Normal and the default state Off. But if the \uicontrol
|
||||
|
|
@ -465,8 +465,8 @@
|
|||
"_on", the state is changed to On. The sample files in the
|
||||
example's \c images subdirectory respect this naming convension.
|
||||
|
||||
\snippet widgets/widgets/icons/mainwindow.cpp 18
|
||||
\snippet widgets/widgets/icons/mainwindow.cpp 19
|
||||
\snippet widgets/icons/mainwindow.cpp 18
|
||||
\snippet widgets/icons/mainwindow.cpp 19
|
||||
|
||||
In the end we add the items to the associated row, and use the
|
||||
QTableWidget::openPersistentEditor() function to create
|
||||
|
|
@ -479,8 +479,8 @@
|
|||
in the preview area. So, corresponding to this fact, we need to
|
||||
make sure that the new image's check box is enabled.
|
||||
|
||||
\snippet widgets/widgets/icons/mainwindow.cpp 6
|
||||
\snippet widgets/widgets/icons/mainwindow.cpp 7
|
||||
\snippet widgets/icons/mainwindow.cpp 6
|
||||
\snippet widgets/icons/mainwindow.cpp 7
|
||||
|
||||
The \c changeIcon() slot is called when the user alters the set
|
||||
of images listed in the QTableWidget, to update the QIcon object
|
||||
|
|
@ -490,9 +490,9 @@
|
|||
QTableWidget, which lists the images the user has loaded into the
|
||||
application.
|
||||
|
||||
\snippet widgets/widgets/icons/mainwindow.cpp 8
|
||||
\snippet widgets/widgets/icons/mainwindow.cpp 9
|
||||
\snippet widgets/widgets/icons/mainwindow.cpp 10
|
||||
\snippet widgets/icons/mainwindow.cpp 8
|
||||
\snippet widgets/icons/mainwindow.cpp 9
|
||||
\snippet widgets/icons/mainwindow.cpp 10
|
||||
|
||||
We also extract the image file's name using the
|
||||
QTableWidgetItem::data() function. This function takes a
|
||||
|
|
@ -507,12 +507,12 @@
|
|||
with its associated mode and state, to the QIcon's set of
|
||||
available pixmaps.
|
||||
|
||||
\snippet widgets/widgets/icons/mainwindow.cpp 11
|
||||
\snippet widgets/icons/mainwindow.cpp 11
|
||||
|
||||
After running through the entire list of images, we change the
|
||||
icon of the preview area to the one we just created.
|
||||
|
||||
\snippet widgets/widgets/icons/mainwindow.cpp 20
|
||||
\snippet widgets/icons/mainwindow.cpp 20
|
||||
|
||||
In the \c removeAllImages() slot, we simply set the table widget's
|
||||
row count to zero, automatically removing all the images the user
|
||||
|
|
@ -527,7 +527,7 @@
|
|||
QTableWidget that will keep track of the images the user has
|
||||
loaded into the application.
|
||||
|
||||
\snippet widgets/widgets/icons/mainwindow.cpp 21
|
||||
\snippet widgets/icons/mainwindow.cpp 21
|
||||
|
||||
First we create a group box that will contain the table widget.
|
||||
Then we create a QTableWidget and customize it to suit our
|
||||
|
|
@ -550,14 +550,14 @@
|
|||
\c ImageDelegate, provides comboboxes for the mode and state
|
||||
fields.
|
||||
|
||||
\snippet widgets/widgets/icons/mainwindow.cpp 22
|
||||
\snippet widgets/widgets/icons/mainwindow.cpp 23
|
||||
\snippet widgets/icons/mainwindow.cpp 22
|
||||
\snippet widgets/icons/mainwindow.cpp 23
|
||||
|
||||
Then we customize the QTableWidget's horizontal header, and hide
|
||||
the vertical header.
|
||||
|
||||
\snippet widgets/widgets/icons/mainwindow.cpp 24
|
||||
\snippet widgets/widgets/icons/mainwindow.cpp 25
|
||||
\snippet widgets/icons/mainwindow.cpp 24
|
||||
\snippet widgets/icons/mainwindow.cpp 25
|
||||
|
||||
At the end, we connect the QTableWidget::itemChanged() signal to
|
||||
the \c changeIcon() slot to ensuret that the preview area is in
|
||||
|
|
@ -569,7 +569,7 @@
|
|||
constructor. It creates the widgets controlling the size of the
|
||||
preview area's icon.
|
||||
|
||||
\snippet widgets/widgets/icons/mainwindow.cpp 26
|
||||
\snippet widgets/icons/mainwindow.cpp 26
|
||||
|
||||
First we create a group box that will contain all the widgets;
|
||||
then we create the radio buttons and the spin box.
|
||||
|
|
@ -581,7 +581,7 @@
|
|||
handle icon sizes, e.g., "32 x 32", instead of plain integer
|
||||
values.
|
||||
|
||||
\snippet widgets/widgets/icons/mainwindow.cpp 27
|
||||
\snippet widgets/icons/mainwindow.cpp 27
|
||||
|
||||
Then we connect all of the radio buttons
|
||||
\l{QRadioButton::toggled()}{toggled()} signals and the spin box's
|
||||
|
|
@ -591,7 +591,7 @@
|
|||
In the end we put the widgets in a layout that we install on the
|
||||
group box.
|
||||
|
||||
\snippet widgets/widgets/icons/mainwindow.cpp 28
|
||||
\snippet widgets/icons/mainwindow.cpp 28
|
||||
|
||||
In the \c createActions() function we create and customize all the
|
||||
actions needed to implement the functionality associated with the
|
||||
|
|
@ -609,7 +609,7 @@
|
|||
with the style name. We will retrieve it later using
|
||||
QAction::data().
|
||||
|
||||
\snippet widgets/widgets/icons/mainwindow.cpp 29
|
||||
\snippet widgets/icons/mainwindow.cpp 29
|
||||
|
||||
In the \c createMenu() function, we add the previously created
|
||||
actions to the \uicontrol File, \uicontrol View and \uicontrol Help menus.
|
||||
|
|
@ -619,7 +619,7 @@
|
|||
application's menu bar, which we retrieve using
|
||||
QMainWindow::menuBar().
|
||||
|
||||
\snippet widgets/widgets/icons/mainwindow.cpp 30
|
||||
\snippet widgets/icons/mainwindow.cpp 30
|
||||
|
||||
QWidgets have a \l{QWidget::contextMenuPolicy}{contextMenuPolicy}
|
||||
property that controls how the widget should behave when the user
|
||||
|
|
@ -632,7 +632,7 @@
|
|||
actions to the table widget. They will then appear in the table
|
||||
widget's context menu.
|
||||
|
||||
\snippet widgets/widgets/icons/mainwindow.cpp 31
|
||||
\snippet widgets/icons/mainwindow.cpp 31
|
||||
|
||||
In the \c checkCurrentStyle() function we go through the group of
|
||||
style actions, looking for the current GUI style.
|
||||
|
|
@ -656,7 +656,7 @@
|
|||
|
||||
\section2 IconSizeSpinBox Class Definition
|
||||
|
||||
\snippet widgets/widgets/icons/iconsizespinbox.h 0
|
||||
\snippet widgets/icons/iconsizespinbox.h 0
|
||||
|
||||
The \c IconSizeSpinBox class is a subclass of QSpinBox. A plain
|
||||
QSpinBox can only handle integers. But since we want to display
|
||||
|
|
@ -668,11 +668,11 @@
|
|||
|
||||
\section2 IconSizeSpinBox Class Implementation
|
||||
|
||||
\snippet widgets/widgets/icons/iconsizespinbox.cpp 0
|
||||
\snippet widgets/icons/iconsizespinbox.cpp 0
|
||||
|
||||
The constructor is trivial.
|
||||
|
||||
\snippet widgets/widgets/icons/iconsizespinbox.cpp 2
|
||||
\snippet widgets/icons/iconsizespinbox.cpp 2
|
||||
|
||||
QSpinBox::textFromValue() is used by the spin box whenever it
|
||||
needs to display a value. The default implementation returns a
|
||||
|
|
@ -680,7 +680,7 @@
|
|||
|
||||
Our reimplementation returns a QString of the form "32 x 32".
|
||||
|
||||
\snippet widgets/widgets/icons/iconsizespinbox.cpp 1
|
||||
\snippet widgets/icons/iconsizespinbox.cpp 1
|
||||
|
||||
The QSpinBox::valueFromText() function is used by the spin box
|
||||
whenever it needs to interpret text typed in by the user. Since
|
||||
|
|
@ -706,7 +706,7 @@
|
|||
|
||||
\section2 ImageDelegate Class Definition
|
||||
|
||||
\snippet widgets/widgets/icons/imagedelegate.h 0
|
||||
\snippet widgets/icons/imagedelegate.h 0
|
||||
|
||||
The \c ImageDelegate class is a subclass of QItemDelegate. The
|
||||
QItemDelegate class provides display and editing facilities for
|
||||
|
|
@ -719,7 +719,7 @@
|
|||
for this purpose allows the editing mechanism to be customized and
|
||||
developed independently from the model and view.
|
||||
|
||||
\snippet widgets/widgets/icons/imagedelegate.h 1
|
||||
\snippet widgets/icons/imagedelegate.h 1
|
||||
|
||||
The default implementation of QItemDelegate creates a QLineEdit.
|
||||
Since we want the editor to be a QComboBox, we need to subclass
|
||||
|
|
@ -727,7 +727,7 @@
|
|||
QItemDelegate::setEditorData() and QItemDelegate::setModelData()
|
||||
functions.
|
||||
|
||||
\snippet widgets/widgets/icons/imagedelegate.h 2
|
||||
\snippet widgets/icons/imagedelegate.h 2
|
||||
|
||||
The \c emitCommitData() slot is used to emit the
|
||||
QImageDelegate::commitData() signal with the appropriate
|
||||
|
|
@ -735,11 +735,11 @@
|
|||
|
||||
\section2 ImageDelegate Class Implementation
|
||||
|
||||
\snippet widgets/widgets/icons/imagedelegate.cpp 0
|
||||
\snippet widgets/icons/imagedelegate.cpp 0
|
||||
|
||||
The constructor is trivial.
|
||||
|
||||
\snippet widgets/widgets/icons/imagedelegate.cpp 1
|
||||
\snippet widgets/icons/imagedelegate.cpp 1
|
||||
|
||||
The default QItemDelegate::createEditor() implementation returns
|
||||
the widget used to edit the item specified by the model and item
|
||||
|
|
@ -759,7 +759,7 @@
|
|||
chooses an item using the combobox. This ensures that the rest of
|
||||
the application notices the change and updates itself.
|
||||
|
||||
\snippet widgets/widgets/icons/imagedelegate.cpp 2
|
||||
\snippet widgets/icons/imagedelegate.cpp 2
|
||||
|
||||
The QItemDelegate::setEditorData() function is used by
|
||||
QTableWidget to transfer data from a QTableWidgetItem to the
|
||||
|
|
@ -772,12 +772,12 @@
|
|||
items is done implicitly by QTableWidget; we don't need to worry
|
||||
about it.
|
||||
|
||||
\snippet widgets/widgets/icons/imagedelegate.cpp 3
|
||||
\snippet widgets/icons/imagedelegate.cpp 3
|
||||
|
||||
The QItemDelegate::setEditorData() function is used by QTableWidget
|
||||
to transfer data back from the editor to the \l{QTableWidgetItem}.
|
||||
|
||||
\snippet widgets/widgets/icons/imagedelegate.cpp 4
|
||||
\snippet widgets/icons/imagedelegate.cpp 4
|
||||
|
||||
The \c emitCommitData() slot simply emit the
|
||||
QAbstractItemDelegate::commitData() signal for the editor that
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@
|
|||
****************************************************************************/
|
||||
|
||||
/*!
|
||||
\example widgets/widgets/imageviewer
|
||||
\example widgets/imageviewer
|
||||
\title Image Viewer Example
|
||||
|
||||
The example shows how to combine QLabel and QScrollArea to
|
||||
|
|
@ -69,7 +69,7 @@
|
|||
|
||||
\section1 ImageViewer Class Definition
|
||||
|
||||
\snippet widgets/widgets/imageviewer/imageviewer.h 0
|
||||
\snippet widgets/imageviewer/imageviewer.h 0
|
||||
|
||||
The \c ImageViewer class inherits from QMainWindow. We reimplement
|
||||
the constructor, and create several private slots to facilitate
|
||||
|
|
@ -85,7 +85,7 @@
|
|||
|
||||
\section1 ImageViewer Class Implementation
|
||||
|
||||
\snippet widgets/widgets/imageviewer/imageviewer.cpp 0
|
||||
\snippet widgets/imageviewer/imageviewer.cpp 0
|
||||
|
||||
In the constructor we first create the label and the scroll area.
|
||||
|
||||
|
|
@ -109,8 +109,8 @@
|
|||
we create the associated actions and menus, and customize the \c
|
||||
{ImageViewer}'s appearance.
|
||||
|
||||
\snippet widgets/widgets/imageviewer/imageviewer.cpp 1
|
||||
\snippet widgets/widgets/imageviewer/imageviewer.cpp 2
|
||||
\snippet widgets/imageviewer/imageviewer.cpp 1
|
||||
\snippet widgets/imageviewer/imageviewer.cpp 2
|
||||
|
||||
In the \c open() slot, we show a file dialog to the user. The
|
||||
easiest way to create a QFileDialog is to use the static
|
||||
|
|
@ -133,8 +133,8 @@
|
|||
information message with an \uicontrol OK button (the default) is
|
||||
sufficient, since the message is part of a normal operation.
|
||||
|
||||
\snippet widgets/widgets/imageviewer/imageviewer.cpp 3
|
||||
\snippet widgets/widgets/imageviewer/imageviewer.cpp 4
|
||||
\snippet widgets/imageviewer/imageviewer.cpp 3
|
||||
\snippet widgets/imageviewer/imageviewer.cpp 4
|
||||
|
||||
If the format is supported, we display the image in \c imageLabel
|
||||
by setting the label's \l {QLabel::pixmap}{pixmap}. Then we enable
|
||||
|
|
@ -156,8 +156,8 @@
|
|||
In the \c print() slot, we first make sure that an image has been
|
||||
loaded into the application:
|
||||
|
||||
\snippet widgets/widgets/imageviewer/imageviewer.cpp 5
|
||||
\snippet widgets/widgets/imageviewer/imageviewer.cpp 6
|
||||
\snippet widgets/imageviewer/imageviewer.cpp 5
|
||||
\snippet widgets/imageviewer/imageviewer.cpp 6
|
||||
|
||||
If the application is built in debug mode, the \c Q_ASSERT() macro
|
||||
will expand to
|
||||
|
|
@ -184,8 +184,8 @@
|
|||
Another approach is to add this line directly to the \c .pro
|
||||
file.
|
||||
|
||||
\snippet widgets/widgets/imageviewer/imageviewer.cpp 7
|
||||
\snippet widgets/widgets/imageviewer/imageviewer.cpp 8
|
||||
\snippet widgets/imageviewer/imageviewer.cpp 7
|
||||
\snippet widgets/imageviewer/imageviewer.cpp 8
|
||||
|
||||
Then we present a print dialog allowing the user to choose a
|
||||
printer and to set a few options. We construct a painter with a
|
||||
|
|
@ -196,8 +196,8 @@
|
|||
|
||||
In the end we draw the pixmap at position (0, 0).
|
||||
|
||||
\snippet widgets/widgets/imageviewer/imageviewer.cpp 9
|
||||
\snippet widgets/widgets/imageviewer/imageviewer.cpp 10
|
||||
\snippet widgets/imageviewer/imageviewer.cpp 9
|
||||
\snippet widgets/imageviewer/imageviewer.cpp 10
|
||||
|
||||
We implement the zooming slots using the private \c scaleImage()
|
||||
function. We set the scaling factors to 1.25 and 0.8,
|
||||
|
|
@ -216,8 +216,8 @@
|
|||
\li \inlineimage imageviewer-zoom_in_2.png
|
||||
\endtable
|
||||
|
||||
\snippet widgets/widgets/imageviewer/imageviewer.cpp 11
|
||||
\snippet widgets/widgets/imageviewer/imageviewer.cpp 12
|
||||
\snippet widgets/imageviewer/imageviewer.cpp 11
|
||||
\snippet widgets/imageviewer/imageviewer.cpp 12
|
||||
|
||||
When zooming, we use the QLabel's ability to scale its contents.
|
||||
Such scaling doesn't change the actual size hint of the contents.
|
||||
|
|
@ -226,8 +226,8 @@
|
|||
normal size of the currently displayed image is to call \c
|
||||
adjustSize() and reset the scale factor to 1.0.
|
||||
|
||||
\snippet widgets/widgets/imageviewer/imageviewer.cpp 13
|
||||
\snippet widgets/widgets/imageviewer/imageviewer.cpp 14
|
||||
\snippet widgets/imageviewer/imageviewer.cpp 13
|
||||
\snippet widgets/imageviewer/imageviewer.cpp 14
|
||||
|
||||
The \c fitToWindow() slot is called each time the user toggled
|
||||
the \uicontrol {Fit to Window} option. If the slot is called to turn on
|
||||
|
|
@ -266,14 +266,14 @@
|
|||
label's size to its content. And in the end we update the view
|
||||
menu entries.
|
||||
|
||||
\snippet widgets/widgets/imageviewer/imageviewer.cpp 15
|
||||
\snippet widgets/widgets/imageviewer/imageviewer.cpp 16
|
||||
\snippet widgets/imageviewer/imageviewer.cpp 15
|
||||
\snippet widgets/imageviewer/imageviewer.cpp 16
|
||||
|
||||
We implement the \c about() slot to create a message box
|
||||
describing what the example is designed to show.
|
||||
|
||||
\snippet widgets/widgets/imageviewer/imageviewer.cpp 17
|
||||
\snippet widgets/widgets/imageviewer/imageviewer.cpp 18
|
||||
\snippet widgets/imageviewer/imageviewer.cpp 17
|
||||
\snippet widgets/imageviewer/imageviewer.cpp 18
|
||||
|
||||
In the private \c createAction() function, we create the
|
||||
actions providing the application features.
|
||||
|
|
@ -284,8 +284,8 @@
|
|||
been loaded into the application. In addition we make the \c
|
||||
fitToWindowAct \l {QAction::checkable}{checkable}.
|
||||
|
||||
\snippet widgets/widgets/imageviewer/imageviewer.cpp 19
|
||||
\snippet widgets/widgets/imageviewer/imageviewer.cpp 20
|
||||
\snippet widgets/imageviewer/imageviewer.cpp 19
|
||||
\snippet widgets/imageviewer/imageviewer.cpp 20
|
||||
|
||||
In the private \c createMenu() function, we add the previously
|
||||
created actions to the \uicontrol File, \uicontrol View and \uicontrol Help menus.
|
||||
|
|
@ -297,16 +297,16 @@
|
|||
menu bar which we retrieve with the QMainWindow::menuBar()
|
||||
function.
|
||||
|
||||
\snippet widgets/widgets/imageviewer/imageviewer.cpp 21
|
||||
\snippet widgets/widgets/imageviewer/imageviewer.cpp 22
|
||||
\snippet widgets/imageviewer/imageviewer.cpp 21
|
||||
\snippet widgets/imageviewer/imageviewer.cpp 22
|
||||
|
||||
The private \c updateActions() function enables or disables the
|
||||
\uicontrol {Zoom In}, \uicontrol {Zoom Out} and \uicontrol {Normal Size} menu
|
||||
entries depending on whether the \uicontrol {Fit to Window} option is
|
||||
turned on or off.
|
||||
|
||||
\snippet widgets/widgets/imageviewer/imageviewer.cpp 23
|
||||
\snippet widgets/widgets/imageviewer/imageviewer.cpp 24
|
||||
\snippet widgets/imageviewer/imageviewer.cpp 23
|
||||
\snippet widgets/imageviewer/imageviewer.cpp 24
|
||||
|
||||
In \c scaleImage(), we use the \c factor parameter to calculate
|
||||
the new scaling factor for the displayed image, and resize \c
|
||||
|
|
@ -321,8 +321,8 @@
|
|||
image pixmap from becoming too large, consuming too much
|
||||
resources in the window system.
|
||||
|
||||
\snippet widgets/widgets/imageviewer/imageviewer.cpp 25
|
||||
\snippet widgets/widgets/imageviewer/imageviewer.cpp 26
|
||||
\snippet widgets/imageviewer/imageviewer.cpp 25
|
||||
\snippet widgets/imageviewer/imageviewer.cpp 26
|
||||
|
||||
Whenever we zoom in or out, we need to adjust the scroll bars in
|
||||
consequence. It would have been tempting to simply call
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@
|
|||
****************************************************************************/
|
||||
|
||||
/*!
|
||||
\example widgets/widgets/lineedits
|
||||
\example widgets/lineedits
|
||||
\title Line Edits Example
|
||||
|
||||
The Line Edits example demonstrates the many ways that QLineEdit can be used, and
|
||||
|
|
@ -46,7 +46,7 @@
|
|||
The \c Window class inherits QWidget and contains a constructor and several
|
||||
slots:
|
||||
|
||||
\snippet widgets/widgets/lineedits/window.h 0
|
||||
\snippet widgets/lineedits/window.h 0
|
||||
|
||||
The slots are used to update the type of validator used for a given line edit when
|
||||
a new validator has been selected in the associated combobox. The line edits
|
||||
|
|
@ -61,7 +61,7 @@
|
|||
We begin by constructing a \l{QGroupBox}{group box} to hold a label, combobox,
|
||||
and line edit so that we can demonstrate the QLineEdit::echoMode property:
|
||||
|
||||
\snippet widgets/widgets/lineedits/window.cpp 0
|
||||
\snippet widgets/lineedits/window.cpp 0
|
||||
|
||||
At this point, none of these widgets have been arranged in layouts. Eventually,
|
||||
the \c echoLabel, \c echoComboBox, and \c echoLineEdit will be placed in a
|
||||
|
|
@ -70,29 +70,29 @@
|
|||
Similarly, we construct group boxes and collections of widgets to show the
|
||||
effects of QIntValidator and QDoubleValidator on a line edit's contents:
|
||||
|
||||
\snippet widgets/widgets/lineedits/window.cpp 1
|
||||
\snippet widgets/lineedits/window.cpp 1
|
||||
|
||||
Text alignment is demonstrated by another group of widgets:
|
||||
|
||||
\snippet widgets/widgets/lineedits/window.cpp 2
|
||||
\snippet widgets/lineedits/window.cpp 2
|
||||
|
||||
QLineEdit supports the use of \l{QLineEdit::inputMask}{input masks}.
|
||||
These only allow the user to type characters into the line edit that
|
||||
follow a simple specification. We construct a group of widgets to
|
||||
demonstrate a selection of predefined masks:
|
||||
|
||||
\snippet widgets/widgets/lineedits/window.cpp 3
|
||||
\snippet widgets/lineedits/window.cpp 3
|
||||
|
||||
Another useful feature of QLineEdit is its ability to make its contents
|
||||
read-only. This property is used to control access to a line edit in the
|
||||
following group of widgets:
|
||||
|
||||
\snippet widgets/widgets/lineedits/window.cpp 4
|
||||
\snippet widgets/lineedits/window.cpp 4
|
||||
|
||||
Now that all the child widgets have been constructed, we connect signals
|
||||
from the comboboxes to slots in the \c Window object:
|
||||
|
||||
\snippet widgets/widgets/lineedits/window.cpp 5
|
||||
\snippet widgets/lineedits/window.cpp 5
|
||||
|
||||
Each of these connections use the QComboBox::activated() signal that
|
||||
supplies an integer to the slot. This will be used to efficiently
|
||||
|
|
@ -101,16 +101,16 @@
|
|||
We place each combobox, line edit, and label in a layout for each group
|
||||
box, beginning with the layout for the \c echoGroup group box:
|
||||
|
||||
\snippet widgets/widgets/lineedits/window.cpp 6
|
||||
\snippet widgets/lineedits/window.cpp 6
|
||||
|
||||
The other layouts are constructed in the same way:
|
||||
|
||||
\snippet widgets/widgets/lineedits/window.cpp 7
|
||||
\snippet widgets/lineedits/window.cpp 7
|
||||
|
||||
Finally, we place each group box in a grid layout for the \c Window object
|
||||
and set the window title:
|
||||
|
||||
\snippet widgets/widgets/lineedits/window.cpp 8
|
||||
\snippet widgets/lineedits/window.cpp 8
|
||||
|
||||
The slots respond to signals emitted when the comboboxes are changed by the
|
||||
user.
|
||||
|
|
@ -118,7 +118,7 @@
|
|||
When the combobox for the \uicontrol{Echo} group box is changed, the \c echoChanged()
|
||||
slot is called:
|
||||
|
||||
\snippet widgets/widgets/lineedits/window.cpp 9
|
||||
\snippet widgets/lineedits/window.cpp 9
|
||||
|
||||
The slot updates the line edit in the same group box to use an echo mode that
|
||||
corresponds to the entry described in the combobox.
|
||||
|
|
@ -126,7 +126,7 @@
|
|||
When the combobox for the \uicontrol{Validator} group box is changed, the
|
||||
\c validatorChanged() slot is called:
|
||||
|
||||
\snippet widgets/widgets/lineedits/window.cpp 10
|
||||
\snippet widgets/lineedits/window.cpp 10
|
||||
|
||||
The slot either creates a new validator for the line edit to use, or it removes
|
||||
the validator in use by calling QLineEdit::setValidator() with a zero pointer.
|
||||
|
|
@ -136,7 +136,7 @@
|
|||
When the combobox for the \uicontrol{Alignment} group box is changed, the
|
||||
\c alignmentChanged() slot is called:
|
||||
|
||||
\snippet widgets/widgets/lineedits/window.cpp 11
|
||||
\snippet widgets/lineedits/window.cpp 11
|
||||
|
||||
This changes the way that text is displayed in the line edit to correspond with
|
||||
the description selected in the combobox.
|
||||
|
|
@ -144,7 +144,7 @@
|
|||
The \c inputMaskChanged() slot handles changes to the combobox in the
|
||||
\uicontrol{Input Mask} group box:
|
||||
|
||||
\snippet widgets/widgets/lineedits/window.cpp 12
|
||||
\snippet widgets/lineedits/window.cpp 12
|
||||
|
||||
Each entry in the relevant combobox is associated with an input mask. We set
|
||||
a new mask by calling the QLineEdit::setMask() function with a suitable string;
|
||||
|
|
@ -153,7 +153,7 @@
|
|||
The \c accessChanged() slot handles changes to the combobox in the
|
||||
\uicontrol{Access} group box:
|
||||
|
||||
\snippet widgets/widgets/lineedits/window.cpp 13
|
||||
\snippet widgets/lineedits/window.cpp 13
|
||||
|
||||
Here, we simply associate the \uicontrol{False} and \uicontrol{True} entries in the combobox
|
||||
with \c false and \c true values to be passed to QLineEdit::setReadOnly(). This
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@
|
|||
****************************************************************************/
|
||||
|
||||
/*!
|
||||
\example widgets/widgets/movie
|
||||
\example widgets/movie
|
||||
\title Movie Example
|
||||
|
||||
The Movie example demonstrates how to use QMovie and QLabel to
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@
|
|||
****************************************************************************/
|
||||
|
||||
/*!
|
||||
\example widgets/widgets/scribble
|
||||
\example widgets/scribble
|
||||
\title Scribble Example
|
||||
|
||||
The Scribble example shows how to reimplement some of QWidget's
|
||||
|
|
@ -65,7 +65,7 @@
|
|||
|
||||
\section1 ScribbleArea Class Definition
|
||||
|
||||
\snippet widgets/widgets/scribble/scribblearea.h 0
|
||||
\snippet widgets/scribble/scribblearea.h 0
|
||||
|
||||
The \c ScribbleArea class inherits from QWidget. We reimplement
|
||||
the \c mousePressEvent(), \c mouseMoveEvent() and \c
|
||||
|
|
@ -98,7 +98,7 @@
|
|||
|
||||
\section1 ScribbleArea Class Implementation
|
||||
|
||||
\snippet widgets/widgets/scribble/scribblearea.cpp 0
|
||||
\snippet widgets/scribble/scribblearea.cpp 0
|
||||
|
||||
In the constructor, we set the Qt::WA_StaticContents
|
||||
attribute for the widget, indicating that the widget contents are
|
||||
|
|
@ -108,8 +108,8 @@
|
|||
for widgets whose contents are static and rooted to the top-left
|
||||
corner.
|
||||
|
||||
\snippet widgets/widgets/scribble/scribblearea.cpp 1
|
||||
\snippet widgets/widgets/scribble/scribblearea.cpp 2
|
||||
\snippet widgets/scribble/scribblearea.cpp 1
|
||||
\snippet widgets/scribble/scribblearea.cpp 2
|
||||
|
||||
In the \c openImage() function, we load the given image. Then we
|
||||
resize the loaded QImage to be at least as large as the widget in
|
||||
|
|
@ -117,8 +117,8 @@
|
|||
we set the \c image member variable to be the loaded image. At
|
||||
the end, we call QWidget::update() to schedule a repaint.
|
||||
|
||||
\snippet widgets/widgets/scribble/scribblearea.cpp 3
|
||||
\snippet widgets/widgets/scribble/scribblearea.cpp 4
|
||||
\snippet widgets/scribble/scribblearea.cpp 3
|
||||
\snippet widgets/scribble/scribblearea.cpp 4
|
||||
|
||||
The \c saveImage() function creates a QImage object that covers
|
||||
only the visible section of the actual \c image and saves it using
|
||||
|
|
@ -126,26 +126,26 @@
|
|||
scribble area's \c modified variable to \c false, because there is
|
||||
no unsaved data.
|
||||
|
||||
\snippet widgets/widgets/scribble/scribblearea.cpp 5
|
||||
\snippet widgets/widgets/scribble/scribblearea.cpp 6
|
||||
\snippet widgets/scribble/scribblearea.cpp 5
|
||||
\snippet widgets/scribble/scribblearea.cpp 6
|
||||
\codeline
|
||||
\snippet widgets/widgets/scribble/scribblearea.cpp 7
|
||||
\snippet widgets/widgets/scribble/scribblearea.cpp 8
|
||||
\snippet widgets/scribble/scribblearea.cpp 7
|
||||
\snippet widgets/scribble/scribblearea.cpp 8
|
||||
|
||||
The \c setPenColor() and \c setPenWidth() functions set the
|
||||
current pen color and width. These values will be used for future
|
||||
drawing operations.
|
||||
|
||||
\snippet widgets/widgets/scribble/scribblearea.cpp 9
|
||||
\snippet widgets/widgets/scribble/scribblearea.cpp 10
|
||||
\snippet widgets/scribble/scribblearea.cpp 9
|
||||
\snippet widgets/scribble/scribblearea.cpp 10
|
||||
|
||||
The public \c clearImage() slot clears the image displayed in the
|
||||
scribble area. We simply fill the entire image with white, which
|
||||
corresponds to RGB value (255, 255, 255). As usual when we modify
|
||||
the image, we set \c modified to \c true and schedule a repaint.
|
||||
|
||||
\snippet widgets/widgets/scribble/scribblearea.cpp 11
|
||||
\snippet widgets/widgets/scribble/scribblearea.cpp 12
|
||||
\snippet widgets/scribble/scribblearea.cpp 11
|
||||
\snippet widgets/scribble/scribblearea.cpp 12
|
||||
|
||||
For mouse press and mouse release events, we use the
|
||||
QMouseEvent::button() function to find out which button caused
|
||||
|
|
@ -163,8 +163,8 @@
|
|||
releases the button, we call the private \c drawLineTo() function
|
||||
to draw.
|
||||
|
||||
\snippet widgets/widgets/scribble/scribblearea.cpp 13
|
||||
\snippet widgets/widgets/scribble/scribblearea.cpp 14
|
||||
\snippet widgets/scribble/scribblearea.cpp 13
|
||||
\snippet widgets/scribble/scribblearea.cpp 14
|
||||
|
||||
In the reimplementation of the \l
|
||||
{QWidget::paintEvent()}{paintEvent()} function, we simply create
|
||||
|
|
@ -195,8 +195,8 @@
|
|||
QWidget into a QImage again, we might lose some information.
|
||||
\endlist
|
||||
|
||||
\snippet widgets/widgets/scribble/scribblearea.cpp 15
|
||||
\snippet widgets/widgets/scribble/scribblearea.cpp 16
|
||||
\snippet widgets/scribble/scribblearea.cpp 15
|
||||
\snippet widgets/scribble/scribblearea.cpp 16
|
||||
|
||||
When the user starts the Scribble application, a resize event is
|
||||
generated and an image is created and displayed in the scribble
|
||||
|
|
@ -206,8 +206,8 @@
|
|||
would be very inefficient). But when the main window becomes
|
||||
larger than this initial size, the image needs to be resized.
|
||||
|
||||
\snippet widgets/widgets/scribble/scribblearea.cpp 17
|
||||
\snippet widgets/widgets/scribble/scribblearea.cpp 18
|
||||
\snippet widgets/scribble/scribblearea.cpp 17
|
||||
\snippet widgets/scribble/scribblearea.cpp 18
|
||||
|
||||
In \c drawLineTo(), we draw a line from the point where the mouse
|
||||
was located when the last mouse press or mouse move occurred, we
|
||||
|
|
@ -220,8 +220,8 @@
|
|||
inside the scribble are needs updating, to avoid a complete
|
||||
repaint of the widget.
|
||||
|
||||
\snippet widgets/widgets/scribble/scribblearea.cpp 19
|
||||
\snippet widgets/widgets/scribble/scribblearea.cpp 20
|
||||
\snippet widgets/scribble/scribblearea.cpp 19
|
||||
\snippet widgets/scribble/scribblearea.cpp 20
|
||||
|
||||
QImage has no nice API for resizing an image. There's a
|
||||
QImage::copy() function that could do the trick, but when used to
|
||||
|
|
@ -237,7 +237,7 @@
|
|||
|
||||
Printing is handled by the \c print() slot:
|
||||
|
||||
\snippet widgets/widgets/scribble/scribblearea.cpp 21
|
||||
\snippet widgets/scribble/scribblearea.cpp 21
|
||||
|
||||
We construct a high resolution QPrinter object for the required
|
||||
output format, using a QPrintDialog to ask the user to specify a
|
||||
|
|
@ -246,7 +246,7 @@
|
|||
If the dialog is accepted, we perform the task of printing to the paint
|
||||
device:
|
||||
|
||||
\snippet widgets/widgets/scribble/scribblearea.cpp 22
|
||||
\snippet widgets/scribble/scribblearea.cpp 22
|
||||
|
||||
Printing an image to a file in this way is simply a matter of
|
||||
painting onto the QPrinter. We scale the image to fit within the
|
||||
|
|
@ -255,7 +255,7 @@
|
|||
|
||||
\section1 MainWindow Class Definition
|
||||
|
||||
\snippet widgets/widgets/scribble/mainwindow.h 0
|
||||
\snippet widgets/scribble/mainwindow.h 0
|
||||
|
||||
The \c MainWindow class inherits from QMainWindow. We reimplement
|
||||
the \l{QWidget::closeEvent()}{closeEvent()} handler from QWidget.
|
||||
|
|
@ -272,14 +272,14 @@
|
|||
|
||||
\section1 MainWindow Class Implementation
|
||||
|
||||
\snippet widgets/widgets/scribble/mainwindow.cpp 0
|
||||
\snippet widgets/scribble/mainwindow.cpp 0
|
||||
|
||||
In the constructor, we create a scribble area which we make the
|
||||
central widget of the \c MainWindow widget. Then we create the
|
||||
associated actions and menus.
|
||||
|
||||
\snippet widgets/widgets/scribble/mainwindow.cpp 1
|
||||
\snippet widgets/widgets/scribble/mainwindow.cpp 2
|
||||
\snippet widgets/scribble/mainwindow.cpp 1
|
||||
\snippet widgets/scribble/mainwindow.cpp 2
|
||||
|
||||
Close events are sent to widgets that the users want to close,
|
||||
usually by clicking \uicontrol{File|Exit} or by clicking the \uicontrol X
|
||||
|
|
@ -294,16 +294,16 @@
|
|||
\c maybeSave() returns false, the user clicked \uicontrol Cancel, so we
|
||||
"ignore" the event, leaving the application unaffected by it.
|
||||
|
||||
\snippet widgets/widgets/scribble/mainwindow.cpp 3
|
||||
\snippet widgets/widgets/scribble/mainwindow.cpp 4
|
||||
\snippet widgets/scribble/mainwindow.cpp 3
|
||||
\snippet widgets/scribble/mainwindow.cpp 4
|
||||
|
||||
In the \c open() slot we first give the user the opportunity to
|
||||
save any modifications to the currently displayed image, before a
|
||||
new image is loaded into the scribble area. Then we ask the user
|
||||
to choose a file and we load the file in the \c ScribbleArea.
|
||||
|
||||
\snippet widgets/widgets/scribble/mainwindow.cpp 5
|
||||
\snippet widgets/widgets/scribble/mainwindow.cpp 6
|
||||
\snippet widgets/scribble/mainwindow.cpp 5
|
||||
\snippet widgets/scribble/mainwindow.cpp 6
|
||||
|
||||
The \c save() slot is called when the users choose the \uicontrol {Save
|
||||
As} menu entry, and then choose an entry from the format menu. The
|
||||
|
|
@ -326,15 +326,15 @@
|
|||
Now that we know the format, we call the private \c saveFile()
|
||||
function to save the currently displayed image.
|
||||
|
||||
\snippet widgets/widgets/scribble/mainwindow.cpp 7
|
||||
\snippet widgets/widgets/scribble/mainwindow.cpp 8
|
||||
\snippet widgets/scribble/mainwindow.cpp 7
|
||||
\snippet widgets/scribble/mainwindow.cpp 8
|
||||
|
||||
We use the \c penColor() slot to retrieve a new color from the
|
||||
user with a QColorDialog. If the user chooses a new color, we
|
||||
make it the scribble area's color.
|
||||
|
||||
\snippet widgets/widgets/scribble/mainwindow.cpp 9
|
||||
\snippet widgets/widgets/scribble/mainwindow.cpp 10
|
||||
\snippet widgets/scribble/mainwindow.cpp 9
|
||||
\snippet widgets/scribble/mainwindow.cpp 10
|
||||
|
||||
To retrieve a new pen width in the \c penWidth() slot, we use
|
||||
QInputDialog. The QInputDialog class provides a simple
|
||||
|
|
@ -348,14 +348,14 @@
|
|||
The boolean \c ok variable will be set to \c true if the user
|
||||
clicked \uicontrol OK and to \c false if the user pressed \uicontrol Cancel.
|
||||
|
||||
\snippet widgets/widgets/scribble/mainwindow.cpp 11
|
||||
\snippet widgets/widgets/scribble/mainwindow.cpp 12
|
||||
\snippet widgets/scribble/mainwindow.cpp 11
|
||||
\snippet widgets/scribble/mainwindow.cpp 12
|
||||
|
||||
We implement the \c about() slot to create a message box
|
||||
describing what the example is designed to show.
|
||||
|
||||
\snippet widgets/widgets/scribble/mainwindow.cpp 13
|
||||
\snippet widgets/widgets/scribble/mainwindow.cpp 14
|
||||
\snippet widgets/scribble/mainwindow.cpp 13
|
||||
\snippet widgets/scribble/mainwindow.cpp 14
|
||||
|
||||
In the \c createAction() function we create the actions
|
||||
representing the menu entries and connect them to the appropriate
|
||||
|
|
@ -369,8 +369,8 @@
|
|||
deduced the file format from the action's text, by truncating the
|
||||
"...", but that would have been inelegant.
|
||||
|
||||
\snippet widgets/widgets/scribble/mainwindow.cpp 15
|
||||
\snippet widgets/widgets/scribble/mainwindow.cpp 16
|
||||
\snippet widgets/scribble/mainwindow.cpp 15
|
||||
\snippet widgets/scribble/mainwindow.cpp 16
|
||||
|
||||
In the \c createMenu() function, we add the previously created
|
||||
format actions to the \c saveAsMenu. Then we add the rest of the
|
||||
|
|
@ -384,8 +384,8 @@
|
|||
{MainWindow}'s menu bar, which we retrieve using the
|
||||
QMainWindow::menuBar() function.
|
||||
|
||||
\snippet widgets/widgets/scribble/mainwindow.cpp 17
|
||||
\snippet widgets/widgets/scribble/mainwindow.cpp 18
|
||||
\snippet widgets/scribble/mainwindow.cpp 17
|
||||
\snippet widgets/scribble/mainwindow.cpp 18
|
||||
|
||||
In \c mayBeSave(), we check if there are any unsaved changes. If
|
||||
there are any, we use QMessageBox to give the user a warning that
|
||||
|
|
@ -407,8 +407,8 @@
|
|||
The \c maybeSave() function returns \c false if the user clicks
|
||||
\uicontrol Cancel; otherwise it returns \c true.
|
||||
|
||||
\snippet widgets/widgets/scribble/mainwindow.cpp 19
|
||||
\snippet widgets/widgets/scribble/mainwindow.cpp 20
|
||||
\snippet widgets/scribble/mainwindow.cpp 19
|
||||
\snippet widgets/scribble/mainwindow.cpp 20
|
||||
|
||||
In \c saveFile(), we pop up a file dialog with a file name
|
||||
suggestion. The static QFileDialog::getSaveFileName() function
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@
|
|||
****************************************************************************/
|
||||
|
||||
/*!
|
||||
\example widgets/widgets/shapedclock
|
||||
\example widgets/shapedclock
|
||||
\title Shaped Clock Example
|
||||
|
||||
The Shaped Clock example shows how to apply a widget mask to a top-level
|
||||
|
|
@ -50,7 +50,7 @@
|
|||
\l{Analog Clock Example}{Analog Clock} example. The whole class definition is
|
||||
presented below:
|
||||
|
||||
\snippet widgets/widgets/shapedclock/shapedclock.h 0
|
||||
\snippet widgets/shapedclock/shapedclock.h 0
|
||||
|
||||
The \l{QWidget::paintEvent()}{paintEvent()} implementation is the same as that found
|
||||
in the \c AnalogClock class. We implement \l{QWidget::sizeHint()}{sizeHint()}
|
||||
|
|
@ -68,7 +68,7 @@
|
|||
The \c ShapedClock constructor performs many of the same tasks as the \c AnalogClock
|
||||
constructor. We set up a timer and connect it to the widget's update() slot:
|
||||
|
||||
\snippet widgets/widgets/shapedclock/shapedclock.cpp 0
|
||||
\snippet widgets/shapedclock/shapedclock.cpp 0
|
||||
|
||||
We inform the window manager that the widget is not to be decorated with a window
|
||||
frame by setting the Qt::FramelessWindowHint flag on the widget. As a result, we need
|
||||
|
|
@ -76,7 +76,7 @@
|
|||
|
||||
Mouse button events are delivered to the \c mousePressEvent() handler:
|
||||
|
||||
\snippet widgets/widgets/shapedclock/shapedclock.cpp 1
|
||||
\snippet widgets/shapedclock/shapedclock.cpp 1
|
||||
|
||||
If the left mouse button is pressed over the widget, we record the displacement in
|
||||
global (screen) coordinates between the top-left position of the widget's frame (even
|
||||
|
|
@ -88,7 +88,7 @@
|
|||
|
||||
The \c mouseMoveEvent() handler is called if the mouse is moved over the widget.
|
||||
|
||||
\snippet widgets/widgets/shapedclock/shapedclock.cpp 2
|
||||
\snippet widgets/shapedclock/shapedclock.cpp 2
|
||||
|
||||
If the left button is held down while the mouse is moved, the top-left corner of the
|
||||
widget is moved to the point given by subtracting the \c dragPosition from the current
|
||||
|
|
@ -98,12 +98,12 @@
|
|||
\l{Analog Clock Example}{Analog Clock} example for a description of the process used
|
||||
to render the clock.
|
||||
|
||||
\snippet widgets/widgets/shapedclock/shapedclock.cpp 3
|
||||
\snippet widgets/shapedclock/shapedclock.cpp 3
|
||||
|
||||
In the \c resizeEvent() handler, we re-use some of the code from the \c paintEvent()
|
||||
to determine the region of the widget that is visible to the user:
|
||||
|
||||
\snippet widgets/widgets/shapedclock/shapedclock.cpp 4
|
||||
\snippet widgets/shapedclock/shapedclock.cpp 4
|
||||
|
||||
Since the clock face is a circle drawn in the center of the widget, this is the region
|
||||
we use as the mask.
|
||||
|
|
@ -117,7 +117,7 @@
|
|||
Finally, we implement the \c sizeHint() for the widget so that it is given a reasonable
|
||||
default size when it is first shown:
|
||||
|
||||
\snippet widgets/widgets/shapedclock/shapedclock.cpp 5
|
||||
\snippet widgets/shapedclock/shapedclock.cpp 5
|
||||
|
||||
\section1 Notes on Widget Masks
|
||||
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@
|
|||
****************************************************************************/
|
||||
|
||||
/*!
|
||||
\example widgets/widgets/sliders
|
||||
\example widgets/sliders
|
||||
\title Sliders Example
|
||||
|
||||
Qt provides three types of slider-like widgets: QSlider,
|
||||
|
|
@ -62,7 +62,7 @@
|
|||
|
||||
\section1 Window Class Definition
|
||||
|
||||
\snippet widgets/widgets/sliders/window.h 0
|
||||
\snippet widgets/sliders/window.h 0
|
||||
|
||||
The \c Window class inherits from QWidget. It displays the slider
|
||||
widgets and allows the user to set their minimum, maximum and
|
||||
|
|
@ -73,7 +73,7 @@
|
|||
|
||||
\section1 Window Class Implementation
|
||||
|
||||
\snippet widgets/widgets/sliders/window.cpp 0
|
||||
\snippet widgets/sliders/window.cpp 0
|
||||
|
||||
In the constructor we first create the two \c SlidersGroup
|
||||
widgets that display the slider widgets horizontally and
|
||||
|
|
@ -85,8 +85,8 @@
|
|||
widgets. The rest of the controlling mechanisms is implemented by
|
||||
the same function call.
|
||||
|
||||
\snippet widgets/widgets/sliders/window.cpp 1
|
||||
\snippet widgets/widgets/sliders/window.cpp 2
|
||||
\snippet widgets/sliders/window.cpp 1
|
||||
\snippet widgets/sliders/window.cpp 2
|
||||
|
||||
Then we connect the \c horizontalSliders, \c verticalSliders and
|
||||
\c valueSpinBox to each other, so that the slider widgets and the
|
||||
|
|
@ -104,8 +104,8 @@
|
|||
minimum and maximum values propagate through the connections we
|
||||
created with \c createControls().
|
||||
|
||||
\snippet widgets/widgets/sliders/window.cpp 3
|
||||
\snippet widgets/widgets/sliders/window.cpp 4
|
||||
\snippet widgets/sliders/window.cpp 3
|
||||
\snippet widgets/sliders/window.cpp 4
|
||||
|
||||
In the private \c createControls() function, we let a QGroupBox
|
||||
(\c controlsGroup) display the control widgets. A group box can
|
||||
|
|
@ -150,8 +150,8 @@
|
|||
bindings are inverted by default: \uicontrol PageDown increases the
|
||||
current value, and \uicontrol PageUp decreases it.
|
||||
|
||||
\snippet widgets/widgets/sliders/window.cpp 5
|
||||
\snippet widgets/widgets/sliders/window.cpp 6
|
||||
\snippet widgets/sliders/window.cpp 5
|
||||
\snippet widgets/sliders/window.cpp 6
|
||||
|
||||
Then we create the spin boxes. QSpinBox allows the user to choose
|
||||
a value by clicking the up and down buttons or pressing the \uicontrol
|
||||
|
|
@ -166,8 +166,8 @@
|
|||
a list of options to the user in a way that takes up the minimum
|
||||
amount of screen space.
|
||||
|
||||
\snippet widgets/widgets/sliders/window.cpp 7
|
||||
\snippet widgets/widgets/sliders/window.cpp 8
|
||||
\snippet widgets/sliders/window.cpp 7
|
||||
\snippet widgets/sliders/window.cpp 8
|
||||
|
||||
We synchronize the behavior of the control widgets and the slider
|
||||
widgets through their signals and slots. We connect each control
|
||||
|
|
@ -179,7 +179,7 @@
|
|||
|
||||
\section1 SlidersGroup Class Definition
|
||||
|
||||
\snippet widgets/widgets/sliders/slidersgroup.h 0
|
||||
\snippet widgets/sliders/slidersgroup.h 0
|
||||
|
||||
The \c SlidersGroup class inherits from QGroupBox. It provides a
|
||||
frame and a title, and contains a QSlider, a QScrollBar and a
|
||||
|
|
@ -193,7 +193,7 @@
|
|||
|
||||
\section1 SlidersGroup Class Implementation
|
||||
|
||||
\snippet widgets/widgets/sliders/slidersgroup.cpp 0
|
||||
\snippet widgets/sliders/slidersgroup.cpp 0
|
||||
|
||||
First we create the slider-like widgets with the appropriate
|
||||
properties. In particular we set the focus policy for each
|
||||
|
|
@ -205,24 +205,24 @@
|
|||
Then we connect the widgets with each other, so that they will
|
||||
stay synchronized when the current value of one of them changes.
|
||||
|
||||
\snippet widgets/widgets/sliders/slidersgroup.cpp 1
|
||||
\snippet widgets/widgets/sliders/slidersgroup.cpp 2
|
||||
\snippet widgets/sliders/slidersgroup.cpp 1
|
||||
\snippet widgets/sliders/slidersgroup.cpp 2
|
||||
|
||||
We connect \c {dial}'s \c valueChanged() signal to the
|
||||
\c{SlidersGroup}'s \c valueChanged() signal, to notify the other
|
||||
widgets in the application (i.e., the control widgets) of the
|
||||
changed value.
|
||||
|
||||
\snippet widgets/widgets/sliders/slidersgroup.cpp 3
|
||||
\snippet widgets/sliders/slidersgroup.cpp 3
|
||||
\codeline
|
||||
\snippet widgets/widgets/sliders/slidersgroup.cpp 4
|
||||
\snippet widgets/sliders/slidersgroup.cpp 4
|
||||
|
||||
Finally, depending on the \l {Qt::Orientation}{orientation} given
|
||||
at the time of construction, we choose and create the layout for
|
||||
the slider widgets within the group box.
|
||||
|
||||
\snippet widgets/widgets/sliders/slidersgroup.cpp 5
|
||||
\snippet widgets/widgets/sliders/slidersgroup.cpp 6
|
||||
\snippet widgets/sliders/slidersgroup.cpp 5
|
||||
\snippet widgets/sliders/slidersgroup.cpp 6
|
||||
|
||||
The \c setValue() slot sets the value of the QSlider. We don't
|
||||
need to explicitly call
|
||||
|
|
@ -231,21 +231,21 @@
|
|||
\l{QAbstractSlider::valueChanged()}{valueChanged()} signal when
|
||||
its value changes, triggering a domino effect.
|
||||
|
||||
\snippet widgets/widgets/sliders/slidersgroup.cpp 7
|
||||
\snippet widgets/widgets/sliders/slidersgroup.cpp 8
|
||||
\snippet widgets/sliders/slidersgroup.cpp 7
|
||||
\snippet widgets/sliders/slidersgroup.cpp 8
|
||||
\codeline
|
||||
\snippet widgets/widgets/sliders/slidersgroup.cpp 9
|
||||
\snippet widgets/widgets/sliders/slidersgroup.cpp 10
|
||||
\snippet widgets/sliders/slidersgroup.cpp 9
|
||||
\snippet widgets/sliders/slidersgroup.cpp 10
|
||||
|
||||
The \c setMinimum() and \c setMaximum() slots are used by the \c
|
||||
Window class to set the range of the QSlider, QScrollBar, and
|
||||
QDial widgets.
|
||||
|
||||
\snippet widgets/widgets/sliders/slidersgroup.cpp 11
|
||||
\snippet widgets/widgets/sliders/slidersgroup.cpp 12
|
||||
\snippet widgets/sliders/slidersgroup.cpp 11
|
||||
\snippet widgets/sliders/slidersgroup.cpp 12
|
||||
\codeline
|
||||
\snippet widgets/widgets/sliders/slidersgroup.cpp 13
|
||||
\snippet widgets/widgets/sliders/slidersgroup.cpp 14
|
||||
\snippet widgets/sliders/slidersgroup.cpp 13
|
||||
\snippet widgets/sliders/slidersgroup.cpp 14
|
||||
|
||||
The \c invertAppearance() and \c invertKeyBindings() slots
|
||||
control the child widgets'
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@
|
|||
****************************************************************************/
|
||||
|
||||
/*!
|
||||
\example widgets/widgets/spinboxes
|
||||
\example widgets/spinboxes
|
||||
\title Spin Boxes Example
|
||||
|
||||
The Spin Boxes example shows how to use the many different types of spin boxes
|
||||
|
|
@ -43,7 +43,7 @@
|
|||
The \c Window class inherits QWidget and contains two slots that are used
|
||||
to provide interactive features:
|
||||
|
||||
\snippet widgets/widgets/spinboxes/window.h 0
|
||||
\snippet widgets/spinboxes/window.h 0
|
||||
|
||||
The private functions are used to set up each type of spin box in the window.
|
||||
We use member variables to keep track of various widgets so that they can
|
||||
|
|
@ -54,7 +54,7 @@
|
|||
The constructor simply calls private functions to set up the different types
|
||||
of spin box used in the example, and places each group in a layout:
|
||||
|
||||
\snippet widgets/widgets/spinboxes/window.cpp 0
|
||||
\snippet widgets/spinboxes/window.cpp 0
|
||||
|
||||
We use the layout to manage the arrangement of the window's child widgets,
|
||||
and change the window title.
|
||||
|
|
@ -63,7 +63,7 @@
|
|||
QSpinBox widgets inside it with descriptive labels to indicate the types of
|
||||
input they expect.
|
||||
|
||||
\snippet widgets/widgets/spinboxes/window.cpp 1
|
||||
\snippet widgets/spinboxes/window.cpp 1
|
||||
|
||||
The first spin box shows the simplest way to use QSpinBox. It accepts values
|
||||
from -20 to 20, the current value can be increased or decreased by 1 with
|
||||
|
|
@ -73,7 +73,7 @@
|
|||
The second spin box uses a larger step size and displays a suffix to
|
||||
provide more information about the type of data the number represents:
|
||||
|
||||
\snippet widgets/widgets/spinboxes/window.cpp 2
|
||||
\snippet widgets/spinboxes/window.cpp 2
|
||||
|
||||
This spin box also displays a
|
||||
\l{QAbstractSpinBox::specialValueText}{special value} instead of the minimum
|
||||
|
|
@ -82,12 +82,12 @@
|
|||
|
||||
The third spin box shows how a prefix can be used:
|
||||
|
||||
\snippet widgets/widgets/spinboxes/window.cpp 4
|
||||
\snippet widgets/spinboxes/window.cpp 4
|
||||
|
||||
For simplicity, we show a spin box with a prefix and no suffix. It is also
|
||||
possible to use both at the same time.
|
||||
|
||||
\snippet widgets/widgets/spinboxes/window.cpp 5
|
||||
\snippet widgets/spinboxes/window.cpp 5
|
||||
|
||||
The rest of the function sets up a layout for the group box and places each
|
||||
of the widgets inside it.
|
||||
|
|
@ -95,7 +95,7 @@
|
|||
The \c createDateTimeEdits() function constructs another group box with a
|
||||
selection of spin boxes used for editing dates and times.
|
||||
|
||||
\snippet widgets/widgets/spinboxes/window.cpp 6
|
||||
\snippet widgets/spinboxes/window.cpp 6
|
||||
|
||||
The first spin box is a QDateEdit widget that is able to accept dates
|
||||
within a given range specified using QDate values. The arrow buttons and
|
||||
|
|
@ -104,7 +104,7 @@
|
|||
|
||||
The second spin box is a QTimeEdit widget:
|
||||
|
||||
\snippet widgets/widgets/spinboxes/window.cpp 7
|
||||
\snippet widgets/spinboxes/window.cpp 7
|
||||
|
||||
Acceptable values for the time are defined using QTime values.
|
||||
|
||||
|
|
@ -113,19 +113,19 @@
|
|||
times for a meeting. These widgets will be updated when the user changes a
|
||||
format string.
|
||||
|
||||
\snippet widgets/widgets/spinboxes/window.cpp 8
|
||||
\snippet widgets/spinboxes/window.cpp 8
|
||||
|
||||
The format string used for the date time editor, which is also shown in the
|
||||
string displayed by the label, is chosen from a set of strings in a combobox:
|
||||
|
||||
\snippet widgets/widgets/spinboxes/window.cpp 9
|
||||
\snippet widgets/spinboxes/window.cpp 9
|
||||
\codeline
|
||||
\snippet widgets/widgets/spinboxes/window.cpp 10
|
||||
\snippet widgets/spinboxes/window.cpp 10
|
||||
|
||||
A signal from this combobox is connected to a slot in the \c Window class
|
||||
(shown later).
|
||||
|
||||
\snippet widgets/widgets/spinboxes/window.cpp 11
|
||||
\snippet widgets/spinboxes/window.cpp 11
|
||||
|
||||
Each child widget of the group box in placed in a layout.
|
||||
|
||||
|
|
@ -133,13 +133,13 @@
|
|||
format string in the combobox. The display format for the QDateTimeEdit
|
||||
widget is set using the raw string passed by the signal:
|
||||
|
||||
\snippet widgets/widgets/spinboxes/window.cpp 12
|
||||
\snippet widgets/spinboxes/window.cpp 12
|
||||
|
||||
Depending on the visible sections in the widget, we set a new date or time
|
||||
range, and update the associated label to provide relevant information for
|
||||
the user:
|
||||
|
||||
\snippet widgets/widgets/spinboxes/window.cpp 13
|
||||
\snippet widgets/spinboxes/window.cpp 13
|
||||
|
||||
When the format string is changed, there will be an appropriate label and
|
||||
entry widget for dates, times, or both types of input.
|
||||
|
|
@ -147,7 +147,7 @@
|
|||
The \c createDoubleSpinBoxes() function constructs three spin boxes that are
|
||||
used to input double-precision floating point numbers:
|
||||
|
||||
\snippet widgets/widgets/spinboxes/window.cpp 14
|
||||
\snippet widgets/spinboxes/window.cpp 14
|
||||
|
||||
Before the QDoubleSpinBox widgets are constructed, we create a spin box to
|
||||
control how many decimal places they show. By default, only two decimal places
|
||||
|
|
@ -158,23 +158,23 @@
|
|||
same range, step size, and default value as the first spin box in the
|
||||
\c createSpinBoxes() function:
|
||||
|
||||
\snippet widgets/widgets/spinboxes/window.cpp 15
|
||||
\snippet widgets/spinboxes/window.cpp 15
|
||||
|
||||
However, this spin box also allows non-integer values to be entered.
|
||||
|
||||
The second spin box displays a suffix and shows a special value instead
|
||||
of the minimum value:
|
||||
|
||||
\snippet widgets/widgets/spinboxes/window.cpp 16
|
||||
\snippet widgets/spinboxes/window.cpp 16
|
||||
|
||||
The third spin box displays a prefix instead of a suffix:
|
||||
|
||||
\snippet widgets/widgets/spinboxes/window.cpp 17
|
||||
\snippet widgets/spinboxes/window.cpp 17
|
||||
|
||||
We connect the QSpinBox widget that specifies the precision to a slot in
|
||||
the \c Window class.
|
||||
|
||||
\snippet widgets/widgets/spinboxes/window.cpp 18
|
||||
\snippet widgets/spinboxes/window.cpp 18
|
||||
|
||||
The rest of the function places each of the widgets into a layout for the
|
||||
group box.
|
||||
|
|
@ -182,7 +182,7 @@
|
|||
The \c changePrecision() slot is called when the user changes the value in
|
||||
the precision spin box:
|
||||
|
||||
\snippet widgets/widgets/spinboxes/window.cpp 19
|
||||
\snippet widgets/spinboxes/window.cpp 19
|
||||
|
||||
This function simply uses the integer supplied by the signal to specify the
|
||||
number of decimal places in each of the QDoubleSpinBox widgets. Each one
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@
|
|||
****************************************************************************/
|
||||
|
||||
/*!
|
||||
\example widgets/widgets/styles
|
||||
\example widgets/styles
|
||||
\title Styles Example
|
||||
|
||||
The Styles example illustrates how to create custom widget
|
||||
|
|
@ -67,7 +67,7 @@
|
|||
|
||||
Here's the definition of the \c NorwegianWoodStyle class:
|
||||
|
||||
\snippet widgets/widgets/styles/norwegianwoodstyle.h 0
|
||||
\snippet widgets/styles/norwegianwoodstyle.h 0
|
||||
|
||||
The public functions are all declared in QStyle (QMotifStyle's
|
||||
grandparent class) and reimplemented here to override the Motif
|
||||
|
|
@ -78,7 +78,7 @@
|
|||
We will now review the implementation of the \c
|
||||
NorwegianWoodStyle class.
|
||||
|
||||
\snippet widgets/widgets/styles/norwegianwoodstyle.cpp 0
|
||||
\snippet widgets/styles/norwegianwoodstyle.cpp 0
|
||||
|
||||
The \c polish() function is reimplemented from QStyle. It takes a
|
||||
QPalette as a reference and adapts the palette to fit the style.
|
||||
|
|
@ -114,7 +114,7 @@
|
|||
buttonImage. This image will be used for filling buttons that the
|
||||
user is holding down.
|
||||
|
||||
\snippet widgets/widgets/styles/norwegianwoodstyle.cpp 1
|
||||
\snippet widgets/styles/norwegianwoodstyle.cpp 1
|
||||
|
||||
We initialize the palette. Palettes have various
|
||||
\l{QPalette::ColorRole}{color roles}, such as QPalette::Base
|
||||
|
|
@ -156,8 +156,8 @@
|
|||
Let's move on to the other functions reimplemented from
|
||||
QMotifStyle:
|
||||
|
||||
\snippet widgets/widgets/styles/norwegianwoodstyle.cpp 3
|
||||
\snippet widgets/widgets/styles/norwegianwoodstyle.cpp 4
|
||||
\snippet widgets/styles/norwegianwoodstyle.cpp 3
|
||||
\snippet widgets/styles/norwegianwoodstyle.cpp 4
|
||||
|
||||
This QStyle::polish() overload is called once on every widget
|
||||
drawn using the style. We reimplement it to set the Qt::WA_Hover
|
||||
|
|
@ -167,8 +167,8 @@
|
|||
render push buttons and comboboxes differently when the mouse
|
||||
pointer is over them.
|
||||
|
||||
\snippet widgets/widgets/styles/norwegianwoodstyle.cpp 5
|
||||
\snippet widgets/widgets/styles/norwegianwoodstyle.cpp 6
|
||||
\snippet widgets/styles/norwegianwoodstyle.cpp 5
|
||||
\snippet widgets/styles/norwegianwoodstyle.cpp 6
|
||||
|
||||
This QStyle::unpolish() overload is called to undo any
|
||||
modification done to the widget in \c polish(). For simplicity,
|
||||
|
|
@ -177,8 +177,8 @@
|
|||
widgets (e.g., using a QMap<QWidget *, bool>) and restore it in
|
||||
\c unpolish().
|
||||
|
||||
\snippet widgets/widgets/styles/norwegianwoodstyle.cpp 7
|
||||
\snippet widgets/widgets/styles/norwegianwoodstyle.cpp 8
|
||||
\snippet widgets/styles/norwegianwoodstyle.cpp 7
|
||||
\snippet widgets/styles/norwegianwoodstyle.cpp 8
|
||||
|
||||
The \l{QStyle::pixelMetric()}{pixelMetric()} function returns the
|
||||
size in pixels for a certain user interface element. By
|
||||
|
|
@ -197,8 +197,8 @@
|
|||
For all other QStyle::PixelMetric elements, we use the Motif
|
||||
settings.
|
||||
|
||||
\snippet widgets/widgets/styles/norwegianwoodstyle.cpp 9
|
||||
\snippet widgets/widgets/styles/norwegianwoodstyle.cpp 10
|
||||
\snippet widgets/styles/norwegianwoodstyle.cpp 9
|
||||
\snippet widgets/styles/norwegianwoodstyle.cpp 10
|
||||
|
||||
The \l{QStyle::styleHint()}{styleHint()} function returns some
|
||||
hints to widgets or to the base style (in our case QMotifStyle)
|
||||
|
|
@ -209,8 +209,8 @@
|
|||
QStyle::SH_EtchDisabledText hint, meaning that disabled text is
|
||||
rendered with an embossed look (as QWindowsStyle does).
|
||||
|
||||
\snippet widgets/widgets/styles/norwegianwoodstyle.cpp 11
|
||||
\snippet widgets/widgets/styles/norwegianwoodstyle.cpp 12
|
||||
\snippet widgets/styles/norwegianwoodstyle.cpp 11
|
||||
\snippet widgets/styles/norwegianwoodstyle.cpp 12
|
||||
|
||||
The \l{QStyle::drawPrimitive()}{drawPrimitive()} function is
|
||||
called by Qt widgets to draw various fundamental graphical
|
||||
|
|
@ -241,8 +241,8 @@
|
|||
QStyle::State_MouseOver flag to be set when the mouse is over the
|
||||
widget.
|
||||
|
||||
\snippet widgets/widgets/styles/norwegianwoodstyle.cpp 13
|
||||
\snippet widgets/widgets/styles/norwegianwoodstyle.cpp 14
|
||||
\snippet widgets/styles/norwegianwoodstyle.cpp 13
|
||||
\snippet widgets/styles/norwegianwoodstyle.cpp 14
|
||||
|
||||
The \c roundRect variable is a QPainterPath. A QPainterPath is is
|
||||
a vectorial specification of a shape. Any shape (rectangle,
|
||||
|
|
@ -252,10 +252,10 @@
|
|||
\c roundRectPath() function is a private function; we will come
|
||||
back to it later.
|
||||
|
||||
\snippet widgets/widgets/styles/norwegianwoodstyle.cpp 15
|
||||
\snippet widgets/widgets/styles/norwegianwoodstyle.cpp 16
|
||||
\snippet widgets/widgets/styles/norwegianwoodstyle.cpp 17
|
||||
\snippet widgets/widgets/styles/norwegianwoodstyle.cpp 18
|
||||
\snippet widgets/styles/norwegianwoodstyle.cpp 15
|
||||
\snippet widgets/styles/norwegianwoodstyle.cpp 16
|
||||
\snippet widgets/styles/norwegianwoodstyle.cpp 17
|
||||
\snippet widgets/styles/norwegianwoodstyle.cpp 18
|
||||
|
||||
We define two variables, \c brush and \c darker, and initialize
|
||||
them based on the state of the button:
|
||||
|
|
@ -287,11 +287,11 @@
|
|||
performs a dynamic cast; if \c option is not a
|
||||
QStyleOptionButton, qstyleoption_cast() returns a null pointer.
|
||||
|
||||
\snippet widgets/widgets/styles/norwegianwoodstyle.cpp 19
|
||||
\snippet widgets/widgets/styles/norwegianwoodstyle.cpp 20
|
||||
\snippet widgets/widgets/styles/norwegianwoodstyle.cpp 21
|
||||
\snippet widgets/widgets/styles/norwegianwoodstyle.cpp 22
|
||||
\snippet widgets/widgets/styles/norwegianwoodstyle.cpp 23
|
||||
\snippet widgets/styles/norwegianwoodstyle.cpp 19
|
||||
\snippet widgets/styles/norwegianwoodstyle.cpp 20
|
||||
\snippet widgets/styles/norwegianwoodstyle.cpp 21
|
||||
\snippet widgets/styles/norwegianwoodstyle.cpp 22
|
||||
\snippet widgets/styles/norwegianwoodstyle.cpp 23
|
||||
|
||||
We turn on antialiasing on QPainter. Antialiasing is a technique
|
||||
that reduces the visual distortion that occurs when the edges of
|
||||
|
|
@ -306,8 +306,8 @@
|
|||
semi-transparent black color (a black color with an alpha channel
|
||||
of 63) to make the area darker if \c darker is true.
|
||||
|
||||
\snippet widgets/widgets/styles/norwegianwoodstyle.cpp 24
|
||||
\snippet widgets/widgets/styles/norwegianwoodstyle.cpp 25
|
||||
\snippet widgets/styles/norwegianwoodstyle.cpp 24
|
||||
\snippet widgets/styles/norwegianwoodstyle.cpp 25
|
||||
|
||||
Next, we draw the outline. The top-left half of the outline and
|
||||
the bottom-right half of the outline are drawn using different
|
||||
|
|
@ -318,7 +318,7 @@
|
|||
\l{QAbstractButton::checked}{checked}, we invert the two
|
||||
\l{QPen}s to give a sunken look to the button.
|
||||
|
||||
\snippet widgets/widgets/styles/norwegianwoodstyle.cpp 26
|
||||
\snippet widgets/styles/norwegianwoodstyle.cpp 26
|
||||
|
||||
We draw the top-left part of the outline by calling
|
||||
QPainter::drawPath() with an appropriate
|
||||
|
|
@ -340,9 +340,9 @@
|
|||
pass the \c -reverse command-line option to the application. This
|
||||
option is recognized by the QApplication constructor.
|
||||
|
||||
\snippet widgets/widgets/styles/norwegianwoodstyle.cpp 32
|
||||
\snippet widgets/widgets/styles/norwegianwoodstyle.cpp 33
|
||||
\snippet widgets/widgets/styles/norwegianwoodstyle.cpp 34
|
||||
\snippet widgets/styles/norwegianwoodstyle.cpp 32
|
||||
\snippet widgets/styles/norwegianwoodstyle.cpp 33
|
||||
\snippet widgets/styles/norwegianwoodstyle.cpp 34
|
||||
|
||||
The bottom-right part of the outline is drawn in a similar
|
||||
fashion. Then we draw a one-pixel wide outline around the entire
|
||||
|
|
@ -354,8 +354,8 @@
|
|||
base style. Let's now turn to the other \c NorwegianWoodStyle
|
||||
member functions:
|
||||
|
||||
\snippet widgets/widgets/styles/norwegianwoodstyle.cpp 35
|
||||
\snippet widgets/widgets/styles/norwegianwoodstyle.cpp 36
|
||||
\snippet widgets/styles/norwegianwoodstyle.cpp 35
|
||||
\snippet widgets/styles/norwegianwoodstyle.cpp 36
|
||||
|
||||
We reimplement QStyle::drawControl() to draw the text on a
|
||||
QPushButton in a bright color when the button is
|
||||
|
|
@ -368,8 +368,8 @@
|
|||
QPalette::ButtonText be the same as the QPalette::BrightText
|
||||
component (unless the widget is disabled).
|
||||
|
||||
\snippet widgets/widgets/styles/norwegianwoodstyle.cpp 37
|
||||
\snippet widgets/widgets/styles/norwegianwoodstyle.cpp 38
|
||||
\snippet widgets/styles/norwegianwoodstyle.cpp 37
|
||||
\snippet widgets/styles/norwegianwoodstyle.cpp 38
|
||||
|
||||
The \c setTexture() function is a private function that sets the
|
||||
\l{QBrush::texture()}{texture} component of the \l{QBrush}es for
|
||||
|
|
@ -378,8 +378,8 @@
|
|||
inactive). We used it to initialize the Norwegian Wood palette in
|
||||
\c polish(QPalette &).
|
||||
|
||||
\snippet widgets/widgets/styles/norwegianwoodstyle.cpp 39
|
||||
\snippet widgets/widgets/styles/norwegianwoodstyle.cpp 40
|
||||
\snippet widgets/styles/norwegianwoodstyle.cpp 39
|
||||
\snippet widgets/styles/norwegianwoodstyle.cpp 40
|
||||
|
||||
The \c roundRectPath() function is a private function that
|
||||
constructs a QPainterPath object for round buttons. The path
|
||||
|
|
@ -397,13 +397,13 @@
|
|||
class, which contains the most common Qt widgets and allows the
|
||||
user to change style dynamically. Here's the class definition:
|
||||
|
||||
\snippet widgets/widgets/styles/widgetgallery.h 0
|
||||
\snippet widgets/styles/widgetgallery.h 0
|
||||
\dots
|
||||
\snippet widgets/widgets/styles/widgetgallery.h 1
|
||||
\snippet widgets/styles/widgetgallery.h 1
|
||||
|
||||
Here's the \c WidgetGallery constructor:
|
||||
|
||||
\snippet widgets/widgets/styles/widgetgallery.cpp 0
|
||||
\snippet widgets/styles/widgetgallery.cpp 0
|
||||
|
||||
We start by creating child widgets. The \uicontrol Style combobox is
|
||||
initialized with all the styles known to QStyleFactory, in
|
||||
|
|
@ -411,8 +411,8 @@
|
|||
private functions that set up the various parts of the \c
|
||||
WidgetGallery.
|
||||
|
||||
\snippet widgets/widgets/styles/widgetgallery.cpp 1
|
||||
\snippet widgets/widgets/styles/widgetgallery.cpp 2
|
||||
\snippet widgets/styles/widgetgallery.cpp 1
|
||||
\snippet widgets/styles/widgetgallery.cpp 2
|
||||
|
||||
We connect the \uicontrol Style combobox to the \c changeStyle()
|
||||
private slot, the \uicontrol{Use style's standard palette} check box to
|
||||
|
|
@ -420,20 +420,20 @@
|
|||
box to the child widgets'
|
||||
\l{QWidget::setDisabled()}{setDisabled()} slot.
|
||||
|
||||
\snippet widgets/widgets/styles/widgetgallery.cpp 3
|
||||
\snippet widgets/widgets/styles/widgetgallery.cpp 4
|
||||
\snippet widgets/styles/widgetgallery.cpp 3
|
||||
\snippet widgets/styles/widgetgallery.cpp 4
|
||||
|
||||
Finally, we put the child widgets in layouts.
|
||||
|
||||
\snippet widgets/widgets/styles/widgetgallery.cpp 5
|
||||
\snippet widgets/widgets/styles/widgetgallery.cpp 6
|
||||
\snippet widgets/styles/widgetgallery.cpp 5
|
||||
\snippet widgets/styles/widgetgallery.cpp 6
|
||||
|
||||
When the user changes the style in the combobox, we call
|
||||
QApplication::setStyle() to dynamically change the style of the
|
||||
application.
|
||||
|
||||
\snippet widgets/widgets/styles/widgetgallery.cpp 7
|
||||
\snippet widgets/widgets/styles/widgetgallery.cpp 8
|
||||
\snippet widgets/styles/widgetgallery.cpp 7
|
||||
\snippet widgets/styles/widgetgallery.cpp 8
|
||||
|
||||
If the user turns the \uicontrol{Use style's standard palette} on, the
|
||||
current style's \l{QStyle::standardPalette()}{standard palette}
|
||||
|
|
@ -443,8 +443,8 @@
|
|||
always override the palette with our own palette in \c
|
||||
NorwegianWoodStyle::polish().
|
||||
|
||||
\snippet widgets/widgets/styles/widgetgallery.cpp 9
|
||||
\snippet widgets/widgets/styles/widgetgallery.cpp 10
|
||||
\snippet widgets/styles/widgetgallery.cpp 9
|
||||
\snippet widgets/styles/widgetgallery.cpp 10
|
||||
|
||||
The \c advanceProgressBar() slot is called at regular intervals
|
||||
to advance the progress bar. Since we don't know how long the
|
||||
|
|
@ -454,8 +454,8 @@
|
|||
|
||||
We will review \c createProgressBar() in a moment.
|
||||
|
||||
\snippet widgets/widgets/styles/widgetgallery.cpp 11
|
||||
\snippet widgets/widgets/styles/widgetgallery.cpp 12
|
||||
\snippet widgets/styles/widgetgallery.cpp 11
|
||||
\snippet widgets/styles/widgetgallery.cpp 12
|
||||
|
||||
The \c createTopLeftGroupBox() function creates the QGroupBox
|
||||
that occupies the top-left corner of the \c WidgetGallery. We
|
||||
|
|
@ -463,7 +463,7 @@
|
|||
createBottomLeftTabWidget(), and \c createBottomRightGroupBox()
|
||||
functions, which are very similar.
|
||||
|
||||
\snippet widgets/widgets/styles/widgetgallery.cpp 13
|
||||
\snippet widgets/styles/widgetgallery.cpp 13
|
||||
|
||||
In \c createProgressBar(), we create a QProgressBar at the bottom
|
||||
of the \c WidgetGallery and connect its
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@
|
|||
****************************************************************************/
|
||||
|
||||
/*!
|
||||
\example widgets/widgets/stylesheet
|
||||
\example widgets/stylesheet
|
||||
\title Style Sheet Example
|
||||
|
||||
The Style Sheet Example shows how to use style sheets.
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@
|
|||
****************************************************************************/
|
||||
|
||||
/*!
|
||||
\example widgets/widgets/tablet
|
||||
\example widgets/tablet
|
||||
\title Tablet Example
|
||||
|
||||
This example shows how to use a Wacom tablet in Qt applications.
|
||||
|
|
@ -79,7 +79,7 @@
|
|||
The \c MainWindow creates a \c TabletCanvas and sets it as its
|
||||
center widget.
|
||||
|
||||
\snippet widgets/widgets/tablet/mainwindow.h 0
|
||||
\snippet widgets/tablet/mainwindow.h 0
|
||||
|
||||
The QActions let the user select if the tablets pressure and
|
||||
tilt should change the pen width, color alpha component and color
|
||||
|
|
@ -97,7 +97,7 @@
|
|||
|
||||
We start width a look at the constructor \c MainWindow():
|
||||
|
||||
\snippet widgets/widgets/tablet/mainwindow.cpp 0
|
||||
\snippet widgets/tablet/mainwindow.cpp 0
|
||||
|
||||
In the constructor we create the canvas, actions, and menus.
|
||||
We set the canvas as the center widget. We also initialize the
|
||||
|
|
@ -106,14 +106,14 @@
|
|||
|
||||
Here is the implementation of \c brushColorAct():
|
||||
|
||||
\snippet widgets/widgets/tablet/mainwindow.cpp 1
|
||||
\snippet widgets/tablet/mainwindow.cpp 1
|
||||
|
||||
We let the user pick a color with a QColorDialog. If it is valid,
|
||||
we set a new drawing color with \c setColor().
|
||||
|
||||
Here is the implementation of \c alphaActionTriggered():
|
||||
|
||||
\snippet widgets/widgets/tablet/mainwindow.cpp 2
|
||||
\snippet widgets/tablet/mainwindow.cpp 2
|
||||
|
||||
The \c TabletCanvas class supports two ways by which the alpha
|
||||
channel of the drawing color can be changed: tablet pressure and
|
||||
|
|
@ -122,14 +122,14 @@
|
|||
|
||||
Here is the implementation of \c lineWidthActionTriggered():
|
||||
|
||||
\snippet widgets/widgets/tablet/mainwindow.cpp 3
|
||||
\snippet widgets/tablet/mainwindow.cpp 3
|
||||
|
||||
We check which action is selected in \c lineWidthGroup, and set
|
||||
how the canvas should change the drawing line width.
|
||||
|
||||
Here is the implementation of \c saturationActionTriggered():
|
||||
|
||||
\snippet widgets/widgets/tablet/mainwindow.cpp 4
|
||||
\snippet widgets/tablet/mainwindow.cpp 4
|
||||
|
||||
We check which action is selected in \c colorSaturationGroup, and
|
||||
set how the canvas should change the color saturation of the
|
||||
|
|
@ -137,7 +137,7 @@
|
|||
|
||||
Here is the implementation of \c saveAct():
|
||||
|
||||
\snippet widgets/widgets/tablet/mainwindow.cpp 5
|
||||
\snippet widgets/tablet/mainwindow.cpp 5
|
||||
|
||||
We use the QFileDialog to let the user select a file to save the
|
||||
drawing in. It is the \c TabletCanvas that save the drawing, so we
|
||||
|
|
@ -145,7 +145,7 @@
|
|||
|
||||
Here is the implementation of \c loadAct():
|
||||
|
||||
\snippet widgets/widgets/tablet/mainwindow.cpp 6
|
||||
\snippet widgets/tablet/mainwindow.cpp 6
|
||||
|
||||
We let the user select the image file to be opened with
|
||||
a QFileDialog; we then ask the canvas to load the image with \c
|
||||
|
|
@ -153,7 +153,7 @@
|
|||
|
||||
Here is the implementation of \c aboutAct():
|
||||
|
||||
\snippet widgets/widgets/tablet/mainwindow.cpp 7
|
||||
\snippet widgets/tablet/mainwindow.cpp 7
|
||||
|
||||
We show a message box with a short description of the example.
|
||||
|
||||
|
|
@ -164,9 +164,9 @@
|
|||
|
||||
Here is the implementation of \c createActions:
|
||||
|
||||
\snippet widgets/widgets/tablet/mainwindow.cpp 8
|
||||
\snippet widgets/tablet/mainwindow.cpp 8
|
||||
\dots
|
||||
\snippet widgets/widgets/tablet/mainwindow.cpp 9
|
||||
\snippet widgets/tablet/mainwindow.cpp 9
|
||||
|
||||
We want the user to be able to choose if the drawing color's
|
||||
alpha component should be changed by the tablet pressure or tilt.
|
||||
|
|
@ -177,11 +177,11 @@
|
|||
triggered() signal is emitted when an action is checked.
|
||||
|
||||
\dots
|
||||
\snippet widgets/widgets/tablet/mainwindow.cpp 10
|
||||
\snippet widgets/tablet/mainwindow.cpp 10
|
||||
|
||||
Here is the implementation of \c createMenus():
|
||||
|
||||
\snippet widgets/widgets/tablet/mainwindow.cpp 11
|
||||
\snippet widgets/tablet/mainwindow.cpp 11
|
||||
|
||||
We create the menus of the example and add the actions to them.
|
||||
|
||||
|
|
@ -191,7 +191,7 @@
|
|||
The \c TabletCanvas class provides a surface on which the
|
||||
user can draw with a tablet.
|
||||
|
||||
\snippet widgets/widgets/tablet/tabletcanvas.h 0
|
||||
\snippet widgets/tablet/tabletcanvas.h 0
|
||||
|
||||
The canvas can change the alpha channel, color saturation,
|
||||
and line width of the drawing. We have one enum for each of
|
||||
|
|
@ -217,28 +217,28 @@
|
|||
|
||||
We start with a look at the constructor:
|
||||
|
||||
\snippet widgets/widgets/tablet/tabletcanvas.cpp 0
|
||||
\snippet widgets/tablet/tabletcanvas.cpp 0
|
||||
|
||||
In the constructor we initialize our class variables. We need
|
||||
to draw the background of our pixmap, as the default is gray.
|
||||
|
||||
Here is the implementation of \c saveImage():
|
||||
|
||||
\snippet widgets/widgets/tablet/tabletcanvas.cpp 1
|
||||
\snippet widgets/tablet/tabletcanvas.cpp 1
|
||||
|
||||
QPixmap implements functionality to save itself to disk, so we
|
||||
simply call \l{QPixmap::}{save()}.
|
||||
|
||||
Here is the implementation of \c loadImage():
|
||||
|
||||
\snippet widgets/widgets/tablet/tabletcanvas.cpp 2
|
||||
\snippet widgets/tablet/tabletcanvas.cpp 2
|
||||
|
||||
We simply call \l{QPixmap::}{load()}, which loads the image in \a
|
||||
file.
|
||||
|
||||
Here is the implementation of \c tabletEvent():
|
||||
|
||||
\snippet widgets/widgets/tablet/tabletcanvas.cpp 3
|
||||
\snippet widgets/tablet/tabletcanvas.cpp 3
|
||||
|
||||
We get three kind of events to this function: TabletPress,
|
||||
TabletRelease, and TabletMove, which is generated when a device
|
||||
|
|
@ -251,13 +251,13 @@
|
|||
|
||||
Here is the implementation of \c paintEvent():
|
||||
|
||||
\snippet widgets/widgets/tablet/tabletcanvas.cpp 4
|
||||
\snippet widgets/tablet/tabletcanvas.cpp 4
|
||||
|
||||
We simply draw the pixmap to the top left of the widget.
|
||||
|
||||
Here is the implementation of \c paintPixmap():
|
||||
|
||||
\snippet widgets/widgets/tablet/tabletcanvas.cpp 5
|
||||
\snippet widgets/tablet/tabletcanvas.cpp 5
|
||||
|
||||
In this function we draw on the pixmap based on the movement of the
|
||||
device. If the device used on the tablet is a stylus we want to draw a
|
||||
|
|
@ -272,7 +272,7 @@
|
|||
density; we select the style based on the tangential pressure in
|
||||
\c brushPattern().
|
||||
|
||||
\snippet widgets/widgets/tablet/tabletcanvas.cpp 6
|
||||
\snippet widgets/tablet/tabletcanvas.cpp 6
|
||||
|
||||
We return a brush style with a point density that increases with
|
||||
the tangential pressure.
|
||||
|
|
@ -282,7 +282,7 @@
|
|||
colorSaturationType, and \c myColor. We will examine the code to
|
||||
set up \c myBrush and \c myPen for each of these variables:
|
||||
|
||||
\snippet widgets/widgets/tablet/tabletcanvas.cpp 7
|
||||
\snippet widgets/tablet/tabletcanvas.cpp 7
|
||||
|
||||
We fetch the current drawingcolor's hue, saturation, value,
|
||||
and alpha values. \c hValue and \c vValue are set to the
|
||||
|
|
@ -292,7 +292,7 @@
|
|||
is between the device and the perpendicular of the tablet (see
|
||||
QTabletEvent for an illustration).
|
||||
|
||||
\snippet widgets/widgets/tablet/tabletcanvas.cpp 8
|
||||
\snippet widgets/tablet/tabletcanvas.cpp 8
|
||||
|
||||
The alpha channel of QColor is given as a number between 0
|
||||
and 255 where 0 is transparent and 255 is opaque.
|
||||
|
|
@ -303,20 +303,20 @@
|
|||
the tablet. We select the largest of the vertical and horizontal
|
||||
tilt value.
|
||||
|
||||
\snippet widgets/widgets/tablet/tabletcanvas.cpp 9
|
||||
\snippet widgets/tablet/tabletcanvas.cpp 9
|
||||
|
||||
The colorsaturation is given as a number between 0 and 255. It is
|
||||
set with \l{QColor::}{setHsv()}. We can set the tilt values
|
||||
directly, but must multiply the pressure to a number between 0 and
|
||||
255.
|
||||
|
||||
\snippet widgets/widgets/tablet/tabletcanvas.cpp 10
|
||||
\snippet widgets/tablet/tabletcanvas.cpp 10
|
||||
|
||||
The width of the pen increases with the pressure. When the pen
|
||||
width is controlled with the tilt we let the width increse with
|
||||
the angle between the device and the perpendicular of the tablet.
|
||||
|
||||
\snippet widgets/widgets/tablet/tabletcanvas.cpp 11
|
||||
\snippet widgets/tablet/tabletcanvas.cpp 11
|
||||
|
||||
We finally check whether the pointer is the stylus or the eraser.
|
||||
If it is the eraser, we set the color to the background color of
|
||||
|
|
@ -329,7 +329,7 @@
|
|||
We inherit QApplication in this class because we want to
|
||||
reimplement the \l{QApplication::}{event()} function.
|
||||
|
||||
\snippet widgets/widgets/tablet/tabletapplication.h 0
|
||||
\snippet widgets/tablet/tabletapplication.h 0
|
||||
|
||||
We keep a \c TabletCanvas we send the device type of the events we
|
||||
handle in the \c event() function to. The TabletEnterProximity
|
||||
|
|
@ -344,7 +344,7 @@
|
|||
|
||||
Here is the implementation of \c event():
|
||||
|
||||
\snippet widgets/widgets/tablet/tabletapplication.cpp 0
|
||||
\snippet widgets/tablet/tabletapplication.cpp 0
|
||||
|
||||
We use this function to handle the TabletEnterProximity and
|
||||
TabletLeaveProximity events, which is generated when a device
|
||||
|
|
@ -359,7 +359,7 @@
|
|||
|
||||
Here is the examples \c main() function:
|
||||
|
||||
\snippet widgets/widgets/tablet/main.cpp 0
|
||||
\snippet widgets/tablet/main.cpp 0
|
||||
|
||||
In the \c main() function we create a \c MainWinow and display it
|
||||
as a top level window. We use the \c TabletApplication class. We
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@
|
|||
****************************************************************************/
|
||||
|
||||
/*!
|
||||
\example widgets/widgets/tetrix
|
||||
\example widgets/tetrix
|
||||
\title Tetrix Example
|
||||
|
||||
The Tetrix example is a Qt version of the classic Tetrix game.
|
||||
|
|
@ -70,7 +70,7 @@
|
|||
The \c TetrixWindow class is used to display the game information and contains
|
||||
the playing area:
|
||||
|
||||
\snippet widgets/widgets/tetrix/tetrixwindow.h 0
|
||||
\snippet widgets/tetrix/tetrixwindow.h 0
|
||||
|
||||
We use private member variables for the board, various display widgets, and
|
||||
buttons to allow the user to start a new game, pause the current game, and quit.
|
||||
|
|
@ -83,7 +83,7 @@
|
|||
|
||||
The constructor sets up the user interface elements for the game:
|
||||
|
||||
\snippet widgets/widgets/tetrix/tetrixwindow.cpp 0
|
||||
\snippet widgets/tetrix/tetrixwindow.cpp 0
|
||||
|
||||
We begin by constructing a \c TetrixBoard instance for the playing area and a
|
||||
label that shows the next piece to be dropped into the playing area; the label
|
||||
|
|
@ -93,13 +93,13 @@
|
|||
lines removed. These initially show default values, and will be filled in
|
||||
when a game begins:
|
||||
|
||||
\snippet widgets/widgets/tetrix/tetrixwindow.cpp 1
|
||||
\snippet widgets/tetrix/tetrixwindow.cpp 1
|
||||
|
||||
Three buttons with shortcuts are constructed so that the user can start a
|
||||
new game, pause the current game, and quit the application:
|
||||
|
||||
\snippet widgets/widgets/tetrix/tetrixwindow.cpp 2
|
||||
\snippet widgets/widgets/tetrix/tetrixwindow.cpp 3
|
||||
\snippet widgets/tetrix/tetrixwindow.cpp 2
|
||||
\snippet widgets/tetrix/tetrixwindow.cpp 3
|
||||
|
||||
These buttons are configured so that they never receive the keyboard focus;
|
||||
we want the keyboard focus to remain with the \c TetrixBoard instance so that
|
||||
|
|
@ -110,8 +110,8 @@
|
|||
and \uicontrol{Pause} buttons to the board, and from the \uicontrol{Quit} button to the
|
||||
application's \l{QApplication::}{quit()} slot.
|
||||
|
||||
\snippet widgets/widgets/tetrix/tetrixwindow.cpp 4
|
||||
\snippet widgets/widgets/tetrix/tetrixwindow.cpp 5
|
||||
\snippet widgets/tetrix/tetrixwindow.cpp 4
|
||||
\snippet widgets/tetrix/tetrixwindow.cpp 5
|
||||
|
||||
Signals from the board are also connected to the LCD widgets for the purpose of
|
||||
updating the score, number of lives, and lines removed from the playing area.
|
||||
|
|
@ -120,7 +120,7 @@
|
|||
along with some labels that we create with the \c createLabel() convenience
|
||||
function:
|
||||
|
||||
\snippet widgets/widgets/tetrix/tetrixwindow.cpp 6
|
||||
\snippet widgets/tetrix/tetrixwindow.cpp 6
|
||||
|
||||
Finally, we set the grid layout on the widget, give the window a title, and
|
||||
resize it to an appropriate size.
|
||||
|
|
@ -128,7 +128,7 @@
|
|||
The \c createLabel() convenience function simply creates a new label on the
|
||||
heap, gives it an appropriate alignment, and returns it to the caller:
|
||||
|
||||
\snippet widgets/widgets/tetrix/tetrixwindow.cpp 7
|
||||
\snippet widgets/tetrix/tetrixwindow.cpp 7
|
||||
|
||||
Since each label will be used in the widget's layout, it will become a child
|
||||
of the \c TetrixWindow widget and, as a result, it will be deleted when the
|
||||
|
|
@ -140,7 +140,7 @@
|
|||
playing area, including its shape, position, and the range of positions it can
|
||||
occupy on the board:
|
||||
|
||||
\snippet widgets/widgets/tetrix/tetrixpiece.h 0
|
||||
\snippet widgets/tetrix/tetrixpiece.h 0
|
||||
|
||||
Each shape contains four blocks, and these are defined by the \c coords private
|
||||
member variable. Additionally, each piece has a high-level description that is
|
||||
|
|
@ -155,7 +155,7 @@
|
|||
|
||||
The \c setRandomShape() function is used to select a random shape for a piece:
|
||||
|
||||
\snippet widgets/widgets/tetrix/tetrixpiece.cpp 0
|
||||
\snippet widgets/tetrix/tetrixpiece.cpp 0
|
||||
|
||||
For convenience, it simply chooses a random shape from the \c TetrixShape enum
|
||||
and calls the \c setShape() function to perform the task of positioning the
|
||||
|
|
@ -164,8 +164,8 @@
|
|||
The \c setShape() function uses a look-up table of pieces to associate each
|
||||
shape with an array of block positions:
|
||||
|
||||
\snippet widgets/widgets/tetrix/tetrixpiece.cpp 1
|
||||
\snippet widgets/widgets/tetrix/tetrixpiece.cpp 2
|
||||
\snippet widgets/tetrix/tetrixpiece.cpp 1
|
||||
\snippet widgets/tetrix/tetrixpiece.cpp 2
|
||||
|
||||
These positions are read from the table into the piece's own array of positions,
|
||||
and the piece's internal shape information is updated to use the new shape.
|
||||
|
|
@ -179,24 +179,24 @@
|
|||
The \c minX() and \c maxX() functions return the minimum and maximum horizontal
|
||||
coordinates occupied by the blocks that make up the piece:
|
||||
|
||||
\snippet widgets/widgets/tetrix/tetrixpiece.cpp 3
|
||||
\snippet widgets/widgets/tetrix/tetrixpiece.cpp 4
|
||||
\snippet widgets/tetrix/tetrixpiece.cpp 3
|
||||
\snippet widgets/tetrix/tetrixpiece.cpp 4
|
||||
|
||||
Similarly, the \c minY() and \c maxY() functions return the minimum and maximum
|
||||
vertical coordinates occupied by the blocks:
|
||||
|
||||
\snippet widgets/widgets/tetrix/tetrixpiece.cpp 5
|
||||
\snippet widgets/widgets/tetrix/tetrixpiece.cpp 6
|
||||
\snippet widgets/tetrix/tetrixpiece.cpp 5
|
||||
\snippet widgets/tetrix/tetrixpiece.cpp 6
|
||||
|
||||
The \c rotatedLeft() function returns a new piece with the same shape as an
|
||||
existing piece, but rotated counter-clockwise by 90 degrees:
|
||||
|
||||
\snippet widgets/widgets/tetrix/tetrixpiece.cpp 7
|
||||
\snippet widgets/tetrix/tetrixpiece.cpp 7
|
||||
|
||||
Similarly, the \c rotatedRight() function returns a new piece with the same
|
||||
shape as an existing piece, but rotated clockwise by 90 degrees:
|
||||
|
||||
\snippet widgets/widgets/tetrix/tetrixpiece.cpp 9
|
||||
\snippet widgets/tetrix/tetrixpiece.cpp 9
|
||||
|
||||
These last two functions enable each piece to create rotated copies of itself.
|
||||
|
||||
|
|
@ -204,7 +204,7 @@
|
|||
|
||||
The \c TetrixBoard class inherits from QFrame and contains the game logic and display features:
|
||||
|
||||
\snippet widgets/widgets/tetrix/tetrixboard.h 0
|
||||
\snippet widgets/tetrix/tetrixboard.h 0
|
||||
|
||||
Apart from the \c setNextPieceLabel() function and the \c start() and \c pause()
|
||||
public slots, we only provide public functions to reimplement QWidget::sizeHint()
|
||||
|
|
@ -214,7 +214,7 @@
|
|||
The rest of the functionality is provided by reimplementations of protected event
|
||||
handlers and private functions:
|
||||
|
||||
\snippet widgets/widgets/tetrix/tetrixboard.h 1
|
||||
\snippet widgets/tetrix/tetrixboard.h 1
|
||||
|
||||
The board is composed of a fixed-size array whose elements correspond to
|
||||
spaces for individual blocks. Each element in the array contains a \c TetrixShape
|
||||
|
|
@ -233,20 +233,20 @@
|
|||
keyboard input will be received by the widget by using Qt::StrongFocus for the
|
||||
focus policy, and initialize the game state:
|
||||
|
||||
\snippet widgets/widgets/tetrix/tetrixboard.cpp 0
|
||||
\snippet widgets/tetrix/tetrixboard.cpp 0
|
||||
|
||||
The first (next) piece is also set up with a random shape.
|
||||
|
||||
The \c setNextPieceLabel() function is used to pass in an externally-constructed
|
||||
label to the board, so that it can be shown alongside the playing area:
|
||||
|
||||
\snippet widgets/widgets/tetrix/tetrixboard.cpp 1
|
||||
\snippet widgets/tetrix/tetrixboard.cpp 1
|
||||
|
||||
We provide a reasonable size hint and minimum size hint for the board, based on
|
||||
the size of the space for each block in the playing area:
|
||||
|
||||
\snippet widgets/widgets/tetrix/tetrixboard.cpp 2
|
||||
\snippet widgets/widgets/tetrix/tetrixboard.cpp 3
|
||||
\snippet widgets/tetrix/tetrixboard.cpp 2
|
||||
\snippet widgets/tetrix/tetrixboard.cpp 3
|
||||
|
||||
By using a minimum size hint, we indicate to the layout in the parent widget
|
||||
that the board should not shrink below a minimum size.
|
||||
|
|
@ -254,7 +254,7 @@
|
|||
A new game is started when the \c start() slot is called. This resets the
|
||||
game's state, the player's score and level, and the contents of the board:
|
||||
|
||||
\snippet widgets/widgets/tetrix/tetrixboard.cpp 4
|
||||
\snippet widgets/tetrix/tetrixboard.cpp 4
|
||||
|
||||
We also emit signals to inform other components of these changes before creating
|
||||
a new piece that is ready to be dropped into the playing area. We start the
|
||||
|
|
@ -263,8 +263,8 @@
|
|||
The \c pause() slot is used to temporarily stop the current game by stopping the
|
||||
internal timer:
|
||||
|
||||
\snippet widgets/widgets/tetrix/tetrixboard.cpp 5
|
||||
\snippet widgets/widgets/tetrix/tetrixboard.cpp 6
|
||||
\snippet widgets/tetrix/tetrixboard.cpp 5
|
||||
\snippet widgets/tetrix/tetrixboard.cpp 6
|
||||
|
||||
We perform checks to ensure that the game can only be paused if it is already
|
||||
running and not already paused.
|
||||
|
|
@ -273,7 +273,7 @@
|
|||
calling the base class's implementation of \l{QWidget::}{paintEvent()} before
|
||||
constructing a QPainter for use on the board:
|
||||
|
||||
\snippet widgets/widgets/tetrix/tetrixboard.cpp 7
|
||||
\snippet widgets/tetrix/tetrixboard.cpp 7
|
||||
|
||||
Since the board is a subclass of QFrame, we obtain a QRect that covers the area
|
||||
\e inside the frame decoration before drawing our own content.
|
||||
|
|
@ -287,22 +287,22 @@
|
|||
For each space on the board that is occupied by a piece, we call the
|
||||
\c drawSquare() function to draw a block at that position.
|
||||
|
||||
\snippet widgets/widgets/tetrix/tetrixboard.cpp 8
|
||||
\snippet widgets/widgets/tetrix/tetrixboard.cpp 9
|
||||
\snippet widgets/tetrix/tetrixboard.cpp 8
|
||||
\snippet widgets/tetrix/tetrixboard.cpp 9
|
||||
|
||||
Spaces that are not occupied by blocks are left blank.
|
||||
|
||||
Unlike the existing pieces on the board, the current piece is drawn
|
||||
block-by-block at its current position:
|
||||
|
||||
\snippet widgets/widgets/tetrix/tetrixboard.cpp 10
|
||||
\snippet widgets/widgets/tetrix/tetrixboard.cpp 11
|
||||
\snippet widgets/widgets/tetrix/tetrixboard.cpp 12
|
||||
\snippet widgets/tetrix/tetrixboard.cpp 10
|
||||
\snippet widgets/tetrix/tetrixboard.cpp 11
|
||||
\snippet widgets/tetrix/tetrixboard.cpp 12
|
||||
|
||||
The \c keyPressEvent() handler is called whenever the player presses a key while
|
||||
the \c TetrixBoard widget has the keyboard focus.
|
||||
|
||||
\snippet widgets/widgets/tetrix/tetrixboard.cpp 13
|
||||
\snippet widgets/tetrix/tetrixboard.cpp 13
|
||||
|
||||
If there is no current game, the game is running but paused, or if there is no
|
||||
current shape to control, we simply pass on the event to the base class.
|
||||
|
|
@ -311,7 +311,7 @@
|
|||
control the current piece and, if so, we call the relevant function to handle
|
||||
the input:
|
||||
|
||||
\snippet widgets/widgets/tetrix/tetrixboard.cpp 14
|
||||
\snippet widgets/tetrix/tetrixboard.cpp 14
|
||||
|
||||
In the case where the player presses a key that we are not interested in, we
|
||||
again pass on the event to the base class's implementation of
|
||||
|
|
@ -321,9 +321,9 @@
|
|||
instance times out. We need to check that the event we receive corresponds to
|
||||
our timer. If it does, we can update the board:
|
||||
|
||||
\snippet widgets/widgets/tetrix/tetrixboard.cpp 15
|
||||
\snippet widgets/widgets/tetrix/tetrixboard.cpp 16
|
||||
\snippet widgets/widgets/tetrix/tetrixboard.cpp 17
|
||||
\snippet widgets/tetrix/tetrixboard.cpp 15
|
||||
\snippet widgets/tetrix/tetrixboard.cpp 16
|
||||
\snippet widgets/tetrix/tetrixboard.cpp 17
|
||||
|
||||
If a row (or line) has just been filled, we create a new piece and reset the
|
||||
timer; otherwise we move the current piece down by one row. We let the base
|
||||
|
|
@ -332,14 +332,14 @@
|
|||
The \c clearBoard() function simply fills the board with the
|
||||
\c TetrixShape::NoShape value:
|
||||
|
||||
\snippet widgets/widgets/tetrix/tetrixboard.cpp 18
|
||||
\snippet widgets/tetrix/tetrixboard.cpp 18
|
||||
|
||||
The \c dropDown() function moves the current piece down as far as possible on
|
||||
the board, either until it is touching the bottom of the playing area or it is
|
||||
stacked on top of another piece:
|
||||
|
||||
\snippet widgets/widgets/tetrix/tetrixboard.cpp 19
|
||||
\snippet widgets/widgets/tetrix/tetrixboard.cpp 20
|
||||
\snippet widgets/tetrix/tetrixboard.cpp 19
|
||||
\snippet widgets/tetrix/tetrixboard.cpp 20
|
||||
|
||||
The number of rows the piece has dropped is recorded and passed to the
|
||||
\c pieceDropped() function so that the player's score can be updated.
|
||||
|
|
@ -348,7 +348,7 @@
|
|||
(line), either when the user presses the \uicontrol{D} key or when the piece is
|
||||
scheduled to move:
|
||||
|
||||
\snippet widgets/widgets/tetrix/tetrixboard.cpp 21
|
||||
\snippet widgets/tetrix/tetrixboard.cpp 21
|
||||
|
||||
If the piece cannot drop down by one line, we call the \c pieceDropped() function
|
||||
with zero as the argument to indicate that it cannot fall any further, and that
|
||||
|
|
@ -359,23 +359,23 @@
|
|||
and, if no lines have been removed, creating a new piece to replace the current
|
||||
one:
|
||||
|
||||
\snippet widgets/widgets/tetrix/tetrixboard.cpp 22
|
||||
\snippet widgets/widgets/tetrix/tetrixboard.cpp 23
|
||||
\snippet widgets/tetrix/tetrixboard.cpp 22
|
||||
\snippet widgets/tetrix/tetrixboard.cpp 23
|
||||
|
||||
We call \c removeFullLines() each time a piece has been dropped. This scans
|
||||
the board from bottom to top, looking for blank spaces on each row.
|
||||
|
||||
\snippet widgets/widgets/tetrix/tetrixboard.cpp 24
|
||||
\snippet widgets/widgets/tetrix/tetrixboard.cpp 25
|
||||
\snippet widgets/widgets/tetrix/tetrixboard.cpp 26
|
||||
\snippet widgets/widgets/tetrix/tetrixboard.cpp 27
|
||||
\snippet widgets/tetrix/tetrixboard.cpp 24
|
||||
\snippet widgets/tetrix/tetrixboard.cpp 25
|
||||
\snippet widgets/tetrix/tetrixboard.cpp 26
|
||||
\snippet widgets/tetrix/tetrixboard.cpp 27
|
||||
|
||||
If a row contains no blank spaces, the rows above it are copied down by one row
|
||||
to compress the stack of pieces, the top row on the board is cleared, and the
|
||||
number of full lines found is incremented.
|
||||
|
||||
\snippet widgets/widgets/tetrix/tetrixboard.cpp 28
|
||||
\snippet widgets/widgets/tetrix/tetrixboard.cpp 29
|
||||
\snippet widgets/tetrix/tetrixboard.cpp 28
|
||||
\snippet widgets/tetrix/tetrixboard.cpp 29
|
||||
|
||||
If some lines have been removed, the player's score and the total number of lines
|
||||
removed are updated. The \c linesRemoved() and \c scoreChanged() signals are
|
||||
|
|
@ -390,8 +390,8 @@
|
|||
The \c newPiece() function places the next available piece at the top of the
|
||||
board, and creates a new piece with a random shape:
|
||||
|
||||
\snippet widgets/widgets/tetrix/tetrixboard.cpp 30
|
||||
\snippet widgets/widgets/tetrix/tetrixboard.cpp 31
|
||||
\snippet widgets/tetrix/tetrixboard.cpp 30
|
||||
\snippet widgets/tetrix/tetrixboard.cpp 31
|
||||
|
||||
We place a new piece in the middle of the board at the top. The game is over if
|
||||
the piece can't move, so we unset its shape to prevent it from being drawn, stop
|
||||
|
|
@ -400,21 +400,21 @@
|
|||
The \c showNextPiece() function updates the label that shows the next piece to
|
||||
be dropped:
|
||||
|
||||
\snippet widgets/widgets/tetrix/tetrixboard.cpp 32
|
||||
\snippet widgets/widgets/tetrix/tetrixboard.cpp 33
|
||||
\snippet widgets/tetrix/tetrixboard.cpp 32
|
||||
\snippet widgets/tetrix/tetrixboard.cpp 33
|
||||
|
||||
We draw the piece's component blocks onto a pixmap that is then set on the label.
|
||||
|
||||
The \c tryMove() function is used to determine whether a piece can be positioned
|
||||
at the specified coordinates:
|
||||
|
||||
\snippet widgets/widgets/tetrix/tetrixboard.cpp 34
|
||||
\snippet widgets/tetrix/tetrixboard.cpp 34
|
||||
|
||||
We examine the spaces on the board that the piece needs to occupy and, if they
|
||||
are already occupied by other pieces, we return \c false to indicate that the
|
||||
move has failed.
|
||||
|
||||
\snippet widgets/widgets/tetrix/tetrixboard.cpp 35
|
||||
\snippet widgets/tetrix/tetrixboard.cpp 35
|
||||
|
||||
If the piece could be placed on the board at the desired location, we update the
|
||||
current piece and its position, update the widget, and return \c true to indicate
|
||||
|
|
@ -423,7 +423,7 @@
|
|||
The \c drawSquare() function draws the blocks (normally squares) that make up
|
||||
each piece using different colors for pieces with different shapes:
|
||||
|
||||
\snippet widgets/widgets/tetrix/tetrixboard.cpp 36
|
||||
\snippet widgets/tetrix/tetrixboard.cpp 36
|
||||
|
||||
We obtain the color to use from a look-up table that relates each shape to an
|
||||
RGB value, and use the painter provided to draw the block at the specified
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@
|
|||
****************************************************************************/
|
||||
|
||||
/*!
|
||||
\example widgets/widgets/tooltips
|
||||
\example widgets/tooltips
|
||||
\title Tool Tips Example
|
||||
|
||||
The Tool Tips example shows how to provide static and dynamic tool
|
||||
|
|
@ -63,7 +63,7 @@
|
|||
|
||||
\section1 SortingBox Class Definition
|
||||
|
||||
\snippet widgets/widgets/tooltips/sortingbox.h 0
|
||||
\snippet widgets/tooltips/sortingbox.h 0
|
||||
|
||||
The \c SortingBox class inherits QWidget, and it is the Tooltips
|
||||
application's main widget. We reimplement several of the event
|
||||
|
|
@ -79,7 +79,7 @@
|
|||
In addition we need three private slots to make the user able to
|
||||
create new shape items.
|
||||
|
||||
\snippet widgets/widgets/tooltips/sortingbox.h 1
|
||||
\snippet widgets/tooltips/sortingbox.h 1
|
||||
|
||||
We also create several private functions: We use the \c
|
||||
initialItemPosition(), \c initialItemColor() and \c
|
||||
|
|
@ -93,7 +93,7 @@
|
|||
randomItemPosition() and \c randomItemColor() functions to create
|
||||
new shape items.
|
||||
|
||||
\snippet widgets/widgets/tooltips/sortingbox.h 2
|
||||
\snippet widgets/tooltips/sortingbox.h 2
|
||||
|
||||
We keep all the shape items in a QList, and we keep three
|
||||
QPainterPath objects holding the shapes of a circle, a square and
|
||||
|
|
@ -102,7 +102,7 @@
|
|||
|
||||
\section1 SortingBox Class Implementation
|
||||
|
||||
\snippet widgets/widgets/tooltips/sortingbox.cpp 0
|
||||
\snippet widgets/tooltips/sortingbox.cpp 0
|
||||
|
||||
In the constructor, we first set the Qt::WA_StaticContents
|
||||
attribute on the widget. This attribute indicates that the widget
|
||||
|
|
@ -110,7 +110,7 @@
|
|||
widget will receive paint events only for the newly visible part
|
||||
of itself.
|
||||
|
||||
\snippet widgets/widgets/tooltips/sortingbox.cpp 1
|
||||
\snippet widgets/tooltips/sortingbox.cpp 1
|
||||
|
||||
To be able to show the appropriate tooltips while the user is
|
||||
moving the cursor around, we need to enable mouse tracking for the
|
||||
|
|
@ -122,13 +122,13 @@
|
|||
enabled, the widget receives mouse move events even if no buttons
|
||||
are pressed.
|
||||
|
||||
\snippet widgets/widgets/tooltips/sortingbox.cpp 2
|
||||
\snippet widgets/tooltips/sortingbox.cpp 2
|
||||
|
||||
A widget's background role defines the brush from the widget's
|
||||
palette that is used to render the background, and QPalette::Base
|
||||
is typically white.
|
||||
|
||||
\snippet widgets/widgets/tooltips/sortingbox.cpp 3
|
||||
\snippet widgets/tooltips/sortingbox.cpp 3
|
||||
|
||||
After creating the application's tool buttons using the private \c
|
||||
createToolButton() function, we construct the shapes of a circle,
|
||||
|
|
@ -141,14 +141,14 @@
|
|||
but they can be drawn many times using only calls to
|
||||
QPainter::drawPath().
|
||||
|
||||
\snippet widgets/widgets/tooltips/sortingbox.cpp 4
|
||||
\snippet widgets/tooltips/sortingbox.cpp 4
|
||||
|
||||
Then we set the window title, resize the widget to a suitable
|
||||
size, and finally create three initial shape items using the
|
||||
private \c createShapeItem(), \c initialItemPosition() and \c
|
||||
initialItemColor() functions.
|
||||
|
||||
\snippet widgets/widgets/tooltips/sortingbox.cpp 5
|
||||
\snippet widgets/tooltips/sortingbox.cpp 5
|
||||
|
||||
QWidget::event() is the main event handler and receives all the
|
||||
widget's events. Normally, we recommend reimplementing one of the
|
||||
|
|
@ -158,7 +158,7 @@
|
|||
reason we reimplement the main event handler, and the first thing
|
||||
we need to do is to determine the event's type:
|
||||
|
||||
\snippet widgets/widgets/tooltips/sortingbox.cpp 6
|
||||
\snippet widgets/tooltips/sortingbox.cpp 6
|
||||
|
||||
If the type is QEvent::ToolTip, we cast the event to a QHelpEvent,
|
||||
otherwise we propagate the event using the QWidget::event()
|
||||
|
|
@ -178,7 +178,7 @@
|
|||
QToolTip::showText() function needs the event's position in global
|
||||
coordinates provided by QHelpEvent::globalPos().
|
||||
|
||||
\snippet widgets/widgets/tooltips/sortingbox.cpp 7
|
||||
\snippet widgets/tooltips/sortingbox.cpp 7
|
||||
|
||||
The \c resizeEvent() function is reimplemented to receive the
|
||||
resize events dispatched to the widget. It makes sure that the
|
||||
|
|
@ -187,14 +187,14 @@
|
|||
aligned in the application's bottom right corner, so each time the
|
||||
main widget is resized we update the buttons geometry.
|
||||
|
||||
\snippet widgets/widgets/tooltips/sortingbox.cpp 8
|
||||
\snippet widgets/tooltips/sortingbox.cpp 8
|
||||
|
||||
The \c paintEvent() function is reimplemented to receive paint
|
||||
events for the widget. We create a QPainter for the \c SortingBox
|
||||
widget, and run through the list of created shape items, drawing
|
||||
each item at its defined position.
|
||||
|
||||
\snippet widgets/widgets/tooltips/sortingbox.cpp 9
|
||||
\snippet widgets/tooltips/sortingbox.cpp 9
|
||||
|
||||
The painter will by default draw all the shape items at position
|
||||
(0,0) in the \c SortingBox widget. The QPainter::translate()
|
||||
|
|
@ -204,7 +204,7 @@
|
|||
drawn, otherwise the next shape item will appear at a position
|
||||
relative to the item we drawed last.
|
||||
|
||||
\snippet widgets/widgets/tooltips/sortingbox.cpp 10
|
||||
\snippet widgets/tooltips/sortingbox.cpp 10
|
||||
|
||||
The QPainter::setBrush() function sets the current brush used by
|
||||
the painter. When the provided argument is a QColor, the function
|
||||
|
|
@ -213,7 +213,7 @@
|
|||
QPainter::drawPath() function draws the given path using the
|
||||
current pen for outline and the current brush for filling.
|
||||
|
||||
\snippet widgets/widgets/tooltips/sortingbox.cpp 11
|
||||
\snippet widgets/tooltips/sortingbox.cpp 11
|
||||
|
||||
The \c mousePressEvent() function is reimplemented to receive the
|
||||
mouse press events dispatched to the widget. It determines if an
|
||||
|
|
@ -230,7 +230,7 @@
|
|||
repaint; instead it schedules a paint event for processing when Qt
|
||||
returns to the main event loop.
|
||||
|
||||
\snippet widgets/widgets/tooltips/sortingbox.cpp 12
|
||||
\snippet widgets/tooltips/sortingbox.cpp 12
|
||||
|
||||
The \c mouseMoveEvent() function is reimplemented to receive mouse
|
||||
move events for the widget. If the left mouse button is pressed
|
||||
|
|
@ -239,7 +239,7 @@
|
|||
corresponding to the offset between the positions of the current
|
||||
mouse event and the previous one.
|
||||
|
||||
\snippet widgets/widgets/tooltips/sortingbox.cpp 13
|
||||
\snippet widgets/tooltips/sortingbox.cpp 13
|
||||
|
||||
The \c mouseReleaseEvent() function is reimplemented to receive
|
||||
the mouse release events dispatched to the widget. If the left
|
||||
|
|
@ -250,18 +250,18 @@
|
|||
now. To move the item further, the user will need to press the
|
||||
left mouse button again.
|
||||
|
||||
\snippet widgets/widgets/tooltips/sortingbox.cpp 14
|
||||
\snippet widgets/tooltips/sortingbox.cpp 14
|
||||
\codeline
|
||||
\snippet widgets/widgets/tooltips/sortingbox.cpp 15
|
||||
\snippet widgets/tooltips/sortingbox.cpp 15
|
||||
\codeline
|
||||
\snippet widgets/widgets/tooltips/sortingbox.cpp 16
|
||||
\snippet widgets/tooltips/sortingbox.cpp 16
|
||||
|
||||
The \c createNewCircle(), \c createNewSquare() and \c
|
||||
createNewTriangle() slots simply create new shape items, using the
|
||||
private \c createShapeItem(), \c randomItemPosition() and \c
|
||||
randomItemColor() functions.
|
||||
|
||||
\snippet widgets/widgets/tooltips/sortingbox.cpp 17
|
||||
\snippet widgets/tooltips/sortingbox.cpp 17
|
||||
|
||||
In the \c itemAt() function, we run through the list of created
|
||||
shape items to check if the given position is contained within the
|
||||
|
|
@ -273,7 +273,7 @@
|
|||
-1. We run through the list backwards to get the index of the
|
||||
uppermost shape item in case several items cover the position.
|
||||
|
||||
\snippet widgets/widgets/tooltips/sortingbox.cpp 18
|
||||
\snippet widgets/tooltips/sortingbox.cpp 18
|
||||
|
||||
The \c moveItemTo() function moves the shape item in motion, and
|
||||
the parameter \c pos is the position of a mouse event. First we
|
||||
|
|
@ -289,13 +289,13 @@
|
|||
rectangle's top left corner, regardless of the item's previous
|
||||
position.
|
||||
|
||||
\snippet widgets/widgets/tooltips/sortingbox.cpp 19
|
||||
\snippet widgets/tooltips/sortingbox.cpp 19
|
||||
|
||||
Finally, we update the previous mouse event position, and make a
|
||||
call to the QWidget::update() function to make the item appear at
|
||||
its new position.
|
||||
|
||||
\snippet widgets/widgets/tooltips/sortingbox.cpp 20
|
||||
\snippet widgets/tooltips/sortingbox.cpp 20
|
||||
|
||||
In the \c updateButtonGeometry() function we set the geometry for
|
||||
the given button. The parameter coordinates define the bottom
|
||||
|
|
@ -310,7 +310,7 @@
|
|||
QStyle::pixelMetric() to determine the widget's preferred default
|
||||
spacing between its child widgets.
|
||||
|
||||
\snippet widgets/widgets/tooltips/sortingbox.cpp 21
|
||||
\snippet widgets/tooltips/sortingbox.cpp 21
|
||||
|
||||
The \c createShapeItem() function creates a single shape item. It
|
||||
sets the path, tooltip, position and color, using the item's own
|
||||
|
|
@ -319,7 +319,7 @@
|
|||
make it appear with the other items within the \c SortingBox
|
||||
widget.
|
||||
|
||||
\snippet widgets/widgets/tooltips/sortingbox.cpp 22
|
||||
\snippet widgets/tooltips/sortingbox.cpp 22
|
||||
|
||||
The \c createToolButton() function is called from the \c
|
||||
SortingBox constructor. We create a tool button with the given
|
||||
|
|
@ -327,14 +327,14 @@
|
|||
and its size is 32 x 32 pixels. Before we return the button, we
|
||||
connect it to the given slot.
|
||||
|
||||
\snippet widgets/widgets/tooltips/sortingbox.cpp 23
|
||||
\snippet widgets/tooltips/sortingbox.cpp 23
|
||||
|
||||
The \c initialItemPosition() function is also called from the
|
||||
constructor. We want the three first items to initially be
|
||||
centered in the middle of the \c SortingBox widget, and we use
|
||||
this function to calculate their positions.
|
||||
|
||||
\snippet widgets/widgets/tooltips/sortingbox.cpp 24
|
||||
\snippet widgets/tooltips/sortingbox.cpp 24
|
||||
|
||||
Whenever the user creates a new shape item, we want the new item
|
||||
to appear at a random position, and we use the \c
|
||||
|
|
@ -343,21 +343,21 @@
|
|||
\c SortingBox widget, using the widget's current width and height
|
||||
when calculating the random coordinates.
|
||||
|
||||
\snippet widgets/widgets/tooltips/sortingbox.cpp 25
|
||||
\snippet widgets/tooltips/sortingbox.cpp 25
|
||||
|
||||
As with \c initialItemPosition(), the \c initialItemColor()
|
||||
function is called from the constructor. The purposes of both
|
||||
functions are purely cosmetic: We want to control the initial
|
||||
position and color of the three first items.
|
||||
|
||||
\snippet widgets/widgets/tooltips/sortingbox.cpp 26
|
||||
\snippet widgets/tooltips/sortingbox.cpp 26
|
||||
|
||||
Finally the \c randomItemColor() function is implemented to give
|
||||
the shape items the user creates, a random color.
|
||||
|
||||
\section1 ShapeItem Class Definition
|
||||
|
||||
\snippet widgets/widgets/tooltips/shapeitem.h 0
|
||||
\snippet widgets/tooltips/shapeitem.h 0
|
||||
|
||||
The \c ShapeItem class is a custom widget representing one single
|
||||
shape item. The widget has a path, a position, a color and a
|
||||
|
|
@ -369,25 +369,25 @@
|
|||
|
||||
\section1 ShapeItem Class Implementation
|
||||
|
||||
\snippet widgets/widgets/tooltips/shapeitem.cpp 0
|
||||
\snippet widgets/tooltips/shapeitem.cpp 0
|
||||
\codeline
|
||||
\snippet widgets/widgets/tooltips/shapeitem.cpp 1
|
||||
\snippet widgets/tooltips/shapeitem.cpp 1
|
||||
\codeline
|
||||
\snippet widgets/widgets/tooltips/shapeitem.cpp 2
|
||||
\snippet widgets/tooltips/shapeitem.cpp 2
|
||||
\codeline
|
||||
\snippet widgets/widgets/tooltips/shapeitem.cpp 3
|
||||
\snippet widgets/tooltips/shapeitem.cpp 3
|
||||
|
||||
This first group of functions simply return the objects that are
|
||||
requested. The objects are returned as constants, i.e. they cannot
|
||||
be modified.
|
||||
|
||||
\snippet widgets/widgets/tooltips/shapeitem.cpp 4
|
||||
\snippet widgets/tooltips/shapeitem.cpp 4
|
||||
\codeline
|
||||
\snippet widgets/widgets/tooltips/shapeitem.cpp 5
|
||||
\snippet widgets/tooltips/shapeitem.cpp 5
|
||||
\codeline
|
||||
\snippet widgets/widgets/tooltips/shapeitem.cpp 6
|
||||
\snippet widgets/tooltips/shapeitem.cpp 6
|
||||
\codeline
|
||||
\snippet widgets/widgets/tooltips/shapeitem.cpp 7
|
||||
\snippet widgets/tooltips/shapeitem.cpp 7
|
||||
|
||||
The last group of functions set or modify the shape item's path,
|
||||
position, color and tooltip, respectively.
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@
|
|||
****************************************************************************/
|
||||
|
||||
/*!
|
||||
\example widgets/widgets/wiggly
|
||||
\example widgets/wiggly
|
||||
\title Wiggly Example
|
||||
|
||||
The Wiggly example shows how to animate a widget using
|
||||
|
|
@ -60,14 +60,14 @@
|
|||
|
||||
\section1 Dialog Class Definition
|
||||
|
||||
\snippet widgets/widgets/wiggly/dialog.h 0
|
||||
\snippet widgets/wiggly/dialog.h 0
|
||||
|
||||
The \c Dialog class provides a dialog widget that allows the user
|
||||
to enter a text. The text is then rendered by \c WigglyWidget.
|
||||
|
||||
\section1 Dialog Class Implementation
|
||||
|
||||
\snippet widgets/widgets/wiggly/dialog.cpp 0
|
||||
\snippet widgets/wiggly/dialog.cpp 0
|
||||
|
||||
In the constructor we create a wiggly widget along with a
|
||||
\l{QLineEdit}{line edit}, and we put the two widgets in a
|
||||
|
|
@ -79,7 +79,7 @@
|
|||
|
||||
\section1 WigglyWidget Class Definition
|
||||
|
||||
\snippet widgets/widgets/wiggly/wigglywidget.h 0
|
||||
\snippet widgets/wiggly/wigglywidget.h 0
|
||||
|
||||
The \c WigglyWidget class provides the wiggly line displaying the
|
||||
text. We subclass QWidget and reimplement the standard \l
|
||||
|
|
@ -96,7 +96,7 @@
|
|||
|
||||
\section1 WigglyWidget Class Implementation
|
||||
|
||||
\snippet widgets/widgets/wiggly/wigglywidget.cpp 0
|
||||
\snippet widgets/wiggly/wigglywidget.cpp 0
|
||||
|
||||
In the constructor, we make the widget's background slightly
|
||||
lighter than the usual background using the QPalette::Midlight
|
||||
|
|
@ -109,8 +109,8 @@
|
|||
timer events generated when the timer times out (every 60
|
||||
milliseconds).
|
||||
|
||||
\snippet widgets/widgets/wiggly/wigglywidget.cpp 1
|
||||
\snippet widgets/widgets/wiggly/wigglywidget.cpp 2
|
||||
\snippet widgets/wiggly/wigglywidget.cpp 1
|
||||
\snippet widgets/wiggly/wigglywidget.cpp 2
|
||||
|
||||
The \c paintEvent() function is called whenever a QPaintEvent is
|
||||
sent to the widget. Paint events are sent to widgets that need to
|
||||
|
|
@ -133,8 +133,8 @@
|
|||
font below the base line). If the descent equals the ascent, they
|
||||
cancel out each other and the base line is at \c height() / 2.
|
||||
|
||||
\snippet widgets/widgets/wiggly/wigglywidget.cpp 3
|
||||
\snippet widgets/widgets/wiggly/wigglywidget.cpp 4
|
||||
\snippet widgets/wiggly/wigglywidget.cpp 3
|
||||
\snippet widgets/wiggly/wigglywidget.cpp 4
|
||||
|
||||
Each time the \c paintEvent() function is called, we create a
|
||||
QPainter object \c painter to draw the contents of the widget.
|
||||
|
|
@ -150,8 +150,8 @@
|
|||
'V'). The result is that the text isn't perfectly centered. You
|
||||
can verify this by typing "AVAVAVAVAVAV" in the line edit.
|
||||
|
||||
\snippet widgets/widgets/wiggly/wigglywidget.cpp 5
|
||||
\snippet widgets/widgets/wiggly/wigglywidget.cpp 6
|
||||
\snippet widgets/wiggly/wigglywidget.cpp 5
|
||||
\snippet widgets/wiggly/wigglywidget.cpp 6
|
||||
|
||||
The \c timerEvent() function receives all the timer events that
|
||||
are generated for this widget. If a timer event is sent from the
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@
|
|||
****************************************************************************/
|
||||
|
||||
/*!
|
||||
\example widgets/widgets/windowflags
|
||||
\example widgets/windowflags
|
||||
\title Window Flags Example
|
||||
|
||||
The Window Flags example shows how to use the window flags
|
||||
|
|
@ -58,7 +58,7 @@
|
|||
|
||||
\section1 ControllerWindow Class Definition
|
||||
|
||||
\snippet widgets/widgets/windowflags/controllerwindow.h 0
|
||||
\snippet widgets/windowflags/controllerwindow.h 0
|
||||
|
||||
The \c ControllerWindow class inherits QWidget. The widget allows
|
||||
the user to choose among the available window flags, and displays
|
||||
|
|
@ -83,7 +83,7 @@
|
|||
|
||||
\section1 ControllerWindow Class Implementation
|
||||
|
||||
\snippet widgets/widgets/windowflags/controllerwindow.cpp 0
|
||||
\snippet widgets/windowflags/controllerwindow.cpp 0
|
||||
|
||||
In the constructor we first create the preview window. Then we
|
||||
create the group boxes containing the available window flags using
|
||||
|
|
@ -96,21 +96,21 @@
|
|||
QVBoxLayout, set the window title and refresh the preview window
|
||||
using the \c updatePreview() slot.
|
||||
|
||||
\snippet widgets/widgets/windowflags/controllerwindow.cpp 1
|
||||
\snippet widgets/widgets/windowflags/controllerwindow.cpp 2
|
||||
\snippet widgets/windowflags/controllerwindow.cpp 1
|
||||
\snippet widgets/windowflags/controllerwindow.cpp 2
|
||||
|
||||
The \c updatePreview() slot is called whenever the user changes
|
||||
any of the window flags. First we create an empty Qt::WindowFlags
|
||||
\c flags, then we determine which one of the types that is checked
|
||||
and add it to \c flags.
|
||||
|
||||
\snippet widgets/widgets/windowflags/controllerwindow.cpp 3
|
||||
\snippet widgets/windowflags/controllerwindow.cpp 3
|
||||
|
||||
We also determine which of the hints that are checked, and add
|
||||
them to \c flags using an OR operator. We use \c flags to set the
|
||||
window flags for the preview window.
|
||||
|
||||
\snippet widgets/widgets/windowflags/controllerwindow.cpp 4
|
||||
\snippet widgets/windowflags/controllerwindow.cpp 4
|
||||
|
||||
We adjust the position of the preview window. The reason we do
|
||||
that, is that playing around with the window's frame may on some
|
||||
|
|
@ -126,7 +126,7 @@
|
|||
\printuntil /^\}/
|
||||
\endomit
|
||||
|
||||
\snippet widgets/widgets/windowflags/controllerwindow.cpp 5
|
||||
\snippet widgets/windowflags/controllerwindow.cpp 5
|
||||
|
||||
The private \c createTypeGroupBox() function is called from the
|
||||
constructor.
|
||||
|
|
@ -145,7 +145,7 @@
|
|||
hints only affect top-level windows, we abandon the Qt::Widget
|
||||
type.
|
||||
|
||||
\snippet widgets/widgets/windowflags/controllerwindow.cpp 6
|
||||
\snippet widgets/windowflags/controllerwindow.cpp 6
|
||||
|
||||
The private \c createHintsGroupBox() function is also called from
|
||||
the constructor.
|
||||
|
|
@ -156,7 +156,7 @@
|
|||
checkboxes into a QGridLayout and install the layout on the group
|
||||
box.
|
||||
|
||||
\snippet widgets/widgets/windowflags/controllerwindow.cpp 7
|
||||
\snippet widgets/windowflags/controllerwindow.cpp 7
|
||||
|
||||
The private \c createCheckBox() function is called from \c
|
||||
createHintsGroupBox().
|
||||
|
|
@ -165,7 +165,7 @@
|
|||
the private \c updatePreview() slot, and return a pointer to the
|
||||
checkbox.
|
||||
|
||||
\snippet widgets/widgets/windowflags/controllerwindow.cpp 8
|
||||
\snippet widgets/windowflags/controllerwindow.cpp 8
|
||||
|
||||
In the private \c createRadioButton() function it is a
|
||||
QRadioButton we create with the provided text, and connect to the
|
||||
|
|
@ -174,7 +174,7 @@
|
|||
|
||||
\section1 PreviewWindow Class Definition
|
||||
|
||||
\snippet widgets/widgets/windowflags/previewwindow.h 0
|
||||
\snippet widgets/windowflags/previewwindow.h 0
|
||||
|
||||
The \c PreviewWindow class inherits QWidget. It is a custom widget
|
||||
that displays the names of its currently set window flags in a
|
||||
|
|
@ -189,7 +189,7 @@
|
|||
|
||||
\section1 PreviewWindow Class Implementation
|
||||
|
||||
\snippet widgets/widgets/windowflags/previewwindow.cpp 0
|
||||
\snippet widgets/windowflags/previewwindow.cpp 0
|
||||
|
||||
In the constructor, we first create a QTextEdit and make sure that
|
||||
it is read-only.
|
||||
|
|
@ -205,7 +205,7 @@
|
|||
Then we create the \uicontrol Close button, and put both the widgets
|
||||
into a QVBoxLayout before we set the window title.
|
||||
|
||||
\snippet widgets/widgets/windowflags/previewwindow.cpp 1
|
||||
\snippet widgets/windowflags/previewwindow.cpp 1
|
||||
|
||||
In our reimplementation of the \c setWindowFlags() function, we
|
||||
first set the widgets flags using the QWidget::setWindowFlags()
|
||||
|
|
|
|||
|
|
@ -62,9 +62,9 @@ QT_BEGIN_NAMESPACE
|
|||
Example for a one second (1000 millisecond) timer (from the
|
||||
\l{widgets/analogclock}{Analog Clock} example):
|
||||
|
||||
\snippet widgets/widgets/analogclock/analogclock.cpp 4
|
||||
\snippet widgets/widgets/analogclock/analogclock.cpp 5
|
||||
\snippet widgets/widgets/analogclock/analogclock.cpp 6
|
||||
\snippet widgets/analogclock/analogclock.cpp 4
|
||||
\snippet widgets/analogclock/analogclock.cpp 5
|
||||
\snippet widgets/analogclock/analogclock.cpp 6
|
||||
|
||||
From then on, the \c update() slot is called every second.
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue