Added some missing code snippets to PySide documentation.
This commit is contained in:
parent
97a16f10ab
commit
b94f5359b0
12 changed files with 596 additions and 73 deletions
55
doc/codesnippets/doc/src/snippets/audio/main.cpp
Normal file
55
doc/codesnippets/doc/src/snippets/audio/main.cpp
Normal file
|
|
@ -0,0 +1,55 @@
|
||||||
|
|
||||||
|
class Window2 (QWidget):
|
||||||
|
//![0]
|
||||||
|
@Slot(QAudio.State)
|
||||||
|
def stateChanged(self, newState):
|
||||||
|
if newState == QAudio.StopState:
|
||||||
|
if self.input.error() != QAudio.NoError:
|
||||||
|
# Error handling
|
||||||
|
//![0]
|
||||||
|
|
||||||
|
class Window (QWidget):
|
||||||
|
def __init__(self):
|
||||||
|
QWidget.__init__(self)
|
||||||
|
self.output = QAudioOutput()
|
||||||
|
self.output.stateChanged[QAudio.State].connect(self.stateChanged)
|
||||||
|
|
||||||
|
def setupFormat(self):
|
||||||
|
//![1]
|
||||||
|
format = QAudioFormat()
|
||||||
|
format.setFrequency(44100)
|
||||||
|
//![1]
|
||||||
|
format.setChannels(2)
|
||||||
|
format.setSampleSize(16)
|
||||||
|
format.setCodec("audio/pcm")
|
||||||
|
format.setByteOrder(QAudioFormat.LittleEndian)
|
||||||
|
//![2]
|
||||||
|
format.setSampleType(QAudioFormat.SignedInt)
|
||||||
|
|
||||||
|
info = QAudioDeviceInfo(QAudioDeviceInfo.defaultOutputDevice())
|
||||||
|
|
||||||
|
if not info.isFormatSupported(format):
|
||||||
|
format = info.nearestFormat(format)
|
||||||
|
//![2]
|
||||||
|
|
||||||
|
//![3]
|
||||||
|
@Slot(QAudio.State)
|
||||||
|
def stateChanged(self, newState):
|
||||||
|
if newState == QAudio.StopState:
|
||||||
|
if self.output.error() != QAudio.NoError:
|
||||||
|
# Perform error handling
|
||||||
|
else:
|
||||||
|
# Normal stop
|
||||||
|
//![3]
|
||||||
|
|
||||||
|
# Handle
|
||||||
|
elif newState == QAudio.ActiveState:
|
||||||
|
# Handle active state...
|
||||||
|
|
||||||
|
app = QApplication(sys.argv)
|
||||||
|
|
||||||
|
window = Window()
|
||||||
|
window.show()
|
||||||
|
sys.exit(app.exec_())
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -0,0 +1,18 @@
|
||||||
|
|
||||||
|
//! [0]
|
||||||
|
QObject::connect: Cannot queue arguments of type 'MyType'
|
||||||
|
//! [0]
|
||||||
|
|
||||||
|
|
||||||
|
//! [1]
|
||||||
|
# An important event
|
||||||
|
ImportantEventPriority = Qt.HighEventPriority
|
||||||
|
# A more important event
|
||||||
|
MoreImportantEventPriority = ImportantEventPriority + 1
|
||||||
|
# A critical event
|
||||||
|
CriticalEventPriority = 100 * MoreImportantEventPriority
|
||||||
|
# Not that important
|
||||||
|
StatusEventPriority = Qt.LowEventPriority
|
||||||
|
# These are less important than Status events
|
||||||
|
IdleProcessingDoneEventPriority = StatusEventPriority - 1
|
||||||
|
//! [1]
|
||||||
|
|
@ -145,7 +145,7 @@ def dragEnterEvent(self, event):
|
||||||
def itemChange(self, change, value):
|
def itemChange(self, change, value):
|
||||||
if change == ItemPositionChange && scene():
|
if change == ItemPositionChange && scene():
|
||||||
# value is the new position.
|
# value is the new position.
|
||||||
rect = scene()->sceneRect()
|
rect = scene().sceneRect()
|
||||||
if !rect.contains(value):
|
if !rect.contains(value):
|
||||||
# Keep the item inside the scene rect.
|
# Keep the item inside the scene rect.
|
||||||
value.setX(qMin(rect.right(), qMax(value.x(), rect.left())))
|
value.setX(qMin(rect.right(), qMax(value.x(), rect.left())))
|
||||||
|
|
@ -182,3 +182,18 @@ class CustomItem(QGraphicsItem):
|
||||||
return self.Type
|
return self.Type
|
||||||
...
|
...
|
||||||
//! [QGraphicsItem type]
|
//! [QGraphicsItem type]
|
||||||
|
|
||||||
|
//! [18]
|
||||||
|
class QGraphicsPathItem (QAbstractGraphicsShapeItem):
|
||||||
|
Type = 2
|
||||||
|
|
||||||
|
def type(self):
|
||||||
|
return QGraphicsPathItem.Type
|
||||||
|
# ...
|
||||||
|
//! [18]
|
||||||
|
|
||||||
|
//! [19]
|
||||||
|
xform = item.deviceTransform(view.viewportTransform())
|
||||||
|
deviceRect = xform.mapRect(rect).toAlignedRect()
|
||||||
|
view.viewport().scroll(dx, dy, deviceRect)
|
||||||
|
//! [19]
|
||||||
|
|
|
||||||
|
|
@ -12,15 +12,21 @@ button.setIcon(QIcon())
|
||||||
//! [2]
|
//! [2]
|
||||||
def drawIcon(self, painter, pos):
|
def drawIcon(self, painter, pos):
|
||||||
enabledStatus = QIcon.Normal
|
enabledStatus = QIcon.Normal
|
||||||
if !isEnabled():
|
if not isEnabled():
|
||||||
enabledStatus = QIcon::Disabled
|
enabledStatus = QIcon::Disabled
|
||||||
|
|
||||||
onOff = QIcon.On
|
onOff = QIcon.On
|
||||||
if !isOn():
|
if not isOn():
|
||||||
onOff = QIcon.Off
|
onOff = QIcon.Off
|
||||||
|
|
||||||
pixmap = icon.pixmap(QSize(22, 22),
|
pixmap = self.icon.pixmap(QSize(22, 22), enabledStatus, onOff)
|
||||||
enabledStatus,
|
|
||||||
onOff)
|
|
||||||
painter.drawPixmap(pos, pixmap)
|
painter.drawPixmap(pos, pixmap)
|
||||||
//! [2]
|
//! [2]
|
||||||
|
|
||||||
|
//! [3]
|
||||||
|
undoicon = QIcon.fromTheme("edit-undo")
|
||||||
|
//! [3]
|
||||||
|
|
||||||
|
//! [4]
|
||||||
|
undoicon = QIcon.fromTheme("edit-undo", QIcon(":/undo.png"))
|
||||||
|
//! [4]
|
||||||
|
|
|
||||||
|
|
@ -10,3 +10,9 @@ static const char * const start_xpm[]={
|
||||||
myPixmap = QPixmap()
|
myPixmap = QPixmap()
|
||||||
myPixmap.setMask(myPixmap.createHeuristicMask())
|
myPixmap.setMask(myPixmap.createHeuristicMask())
|
||||||
//! [1]
|
//! [1]
|
||||||
|
|
||||||
|
//! [2]
|
||||||
|
pixmap = QPixmap("background.png")
|
||||||
|
exposed = QRegion()
|
||||||
|
pixmap.scroll(10, 10, pixmap.rect(), exposed)
|
||||||
|
//! [2]
|
||||||
|
|
|
||||||
|
|
@ -193,3 +193,19 @@ image = QImage(":/images/myImage.png")
|
||||||
painter = QPainter(self)
|
painter = QPainter(self)
|
||||||
painter.drawImage(target, image, source)
|
painter.drawImage(target, image, source)
|
||||||
//! [20]
|
//! [20]
|
||||||
|
|
||||||
|
//! [21]
|
||||||
|
painter = QPainter(self)
|
||||||
|
painter.fillRect(0, 0, 128, 128, Qt.green)
|
||||||
|
painter.beginNativePainting()
|
||||||
|
|
||||||
|
glEnable(GL_SCISSOR_TEST)
|
||||||
|
glScissor(0, 0, 64, 64)
|
||||||
|
|
||||||
|
glClearColor(1, 0, 0, 1)
|
||||||
|
glClear(GL_COLOR_BUFFER_BIT)
|
||||||
|
|
||||||
|
glDisable(GL_SCISSOR_TEST)
|
||||||
|
|
||||||
|
painter.endNativePainting()
|
||||||
|
//! [21]
|
||||||
|
|
|
||||||
|
|
@ -1,21 +1,36 @@
|
||||||
//! [0]
|
//! [0]
|
||||||
manager = QNetworkAccessManager(self)
|
manager = QNetworkAccessManager(self)
|
||||||
connect(manager, SIGNAL(finished("QNetworkReply*")),
|
manager.finished[QNetworkReply].connect(self.replyFinished)
|
||||||
self, SLOT(replyFinished("QNetworkReply*")))
|
|
||||||
|
|
||||||
manager.get(QNetworkRequest(QUrl("http://qtsoftware.com")))
|
manager.get(QNetworkRequest(QUrl("http://qt.nokia.com")))
|
||||||
//! [0]
|
//! [0]
|
||||||
|
|
||||||
|
|
||||||
//! [1]
|
//! [1]
|
||||||
QNetworkRequest request
|
request = QNetworkRequest()
|
||||||
request.setUrl(QUrl("http://qtsoftware.com"))
|
request.setUrl(QUrl("http://qt.nokia.com"))
|
||||||
request.setRawHeader("User-Agent", "MyOwnBrowser 1.0")
|
request.setRawHeader("User-Agent", "MyOwnBrowser 1.0")
|
||||||
|
|
||||||
reply = manager.get(request)
|
reply = manager.get(request)
|
||||||
connect(reply, SIGNAL("readyRead()"), self, SLOT("slotReadyRead()"))
|
reply.readyRead.connect(self.slotReadyRead)
|
||||||
connect(reply, SIGNAL(error("QNetworkReply.NetworkError")),
|
reply.error[QNetworkReply.NetworkError].connect(self..slotError)
|
||||||
self, SLOT(slotError("QNetworkReply.NetworkError")))
|
reply.sslErrors.connect(self.slotSslErrors)
|
||||||
connect(reply, SIGNAL(sslErrors("QList<QSslError>")),
|
|
||||||
self, SLOT(slotSslErrors("QList<QSslError>")))
|
|
||||||
//! [1]
|
//! [1]
|
||||||
|
|
||||||
|
//! [2]
|
||||||
|
manager = QNetworkConfigurationManager()
|
||||||
|
networkAccessManager.setConfiguration(manager.defaultConfiguration())
|
||||||
|
//! [2]
|
||||||
|
|
||||||
|
//! [3]
|
||||||
|
networkAccessManager.setConfiguration(QNetworkConfiguration())
|
||||||
|
//! [3]
|
||||||
|
|
||||||
|
//! [4]
|
||||||
|
networkAccessManager.setNetworkAccessible(QNetworkAccessManager.NotAccessible)
|
||||||
|
//! [4]
|
||||||
|
|
||||||
|
//! [5]
|
||||||
|
networkAccessManager.setNetworkAccessible(QNetworkAccessManager.Accessible)
|
||||||
|
//! [5]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,84 +1,81 @@
|
||||||
|
|
||||||
void wrapInFunction()
|
|
||||||
{
|
|
||||||
|
|
||||||
//! [0]
|
//! [0]
|
||||||
QVERIFY(1 + 1 == 2);
|
QVERIFY(1 + 1 == 2)
|
||||||
//! [0]
|
//! [0]
|
||||||
|
|
||||||
|
|
||||||
//! [1]
|
//! [1]
|
||||||
QVERIFY2(1 + 1 == 2, "A breach in basic arithmetic occured.");
|
QVERIFY2(1 + 1 == 2, "A breach in basic arithmetic occured.")
|
||||||
//! [1]
|
//! [1]
|
||||||
|
|
||||||
|
|
||||||
//! [2]
|
//! [2]
|
||||||
QCOMPARE(QString("hello").toUpper(), QString("HELLO"));
|
QCOMPARE(QString("hello").toUpper(), QString("HELLO"))
|
||||||
//! [2]
|
//! [2]
|
||||||
|
|
||||||
|
|
||||||
//! [3]
|
//! [3]
|
||||||
void TestQString::toInt_data()
|
void TestQString.toInt_data()
|
||||||
{
|
{
|
||||||
QTest::addColumn<QString>("aString");
|
QTest.addColumn<QString>("aString")
|
||||||
QTest::addColumn<int>("expected");
|
QTest.addColumn<int>("expected")
|
||||||
|
|
||||||
QTest::newRow("positive value") << "42" << 42;
|
QTest.newRow("positive value") << "42" << 42
|
||||||
QTest::newRow("negative value") << "-42" << -42;
|
QTest.newRow("negative value") << "-42" << -42
|
||||||
QTest::newRow("zero") << "0" << 0;
|
QTest.newRow("zero") << "0" << 0
|
||||||
}
|
}
|
||||||
//! [3]
|
//! [3]
|
||||||
|
|
||||||
|
|
||||||
//! [4]
|
//! [4]
|
||||||
void TestQString::toInt()
|
void TestQString.toInt()
|
||||||
{
|
{
|
||||||
QFETCH(QString, aString);
|
QFETCH(QString, aString)
|
||||||
QFETCH(int, expected);
|
QFETCH(int, expected)
|
||||||
|
|
||||||
QCOMPARE(aString.toInt(), expected);
|
QCOMPARE(aString.toInt(), expected)
|
||||||
}
|
}
|
||||||
//! [4]
|
//! [4]
|
||||||
|
|
||||||
|
|
||||||
//! [5]
|
//! [5]
|
||||||
if (sizeof(int) != 4)
|
if (sizeof(int) != 4)
|
||||||
QFAIL("This test has not been ported to this platform yet.");
|
QFAIL("This test has not been ported to this platform yet.")
|
||||||
//! [5]
|
//! [5]
|
||||||
|
|
||||||
|
|
||||||
//! [6]
|
//! [6]
|
||||||
QFETCH(QString, myString);
|
QFETCH(QString, myString)
|
||||||
QCOMPARE(QString("hello").toUpper(), myString);
|
QCOMPARE(QString("hello").toUpper(), myString)
|
||||||
//! [6]
|
//! [6]
|
||||||
|
|
||||||
|
|
||||||
//! [7]
|
//! [7]
|
||||||
QTEST(QString("hello").toUpper(), "myString");
|
QTEST(QString("hello").toUpper(), "myString")
|
||||||
//! [7]
|
//! [7]
|
||||||
|
|
||||||
|
|
||||||
//! [8]
|
//! [8]
|
||||||
if (!QSqlDatabase::drivers().contains("SQLITE"))
|
if (!QSqlDatabase.drivers().contains("SQLITE"))
|
||||||
QSKIP("This test requires the SQLITE database driver", SkipAll);
|
QSKIP("This test requires the SQLITE database driver", SkipAll)
|
||||||
//! [8]
|
//! [8]
|
||||||
|
|
||||||
|
|
||||||
//! [9]
|
//! [9]
|
||||||
QEXPECT_FAIL("", "Will fix in the next release", Continue);
|
QEXPECT_FAIL("", "Will fix in the next release", Continue)
|
||||||
QCOMPARE(i, 42);
|
QCOMPARE(i, 42)
|
||||||
QCOMPARE(j, 43);
|
QCOMPARE(j, 43)
|
||||||
//! [9]
|
//! [9]
|
||||||
|
|
||||||
|
|
||||||
//! [10]
|
//! [10]
|
||||||
QEXPECT_FAIL("data27", "Oh my, this is soooo broken", Abort);
|
QEXPECT_FAIL("data27", "Oh my, this is soooo broken", Abort)
|
||||||
QCOMPARE(i, 42);
|
QCOMPARE(i, 42)
|
||||||
//! [10]
|
//! [10]
|
||||||
|
|
||||||
|
|
||||||
//! [11]
|
//! [11]
|
||||||
class TestQString: public QObject { ... };
|
class TestQString: public QObject { ... }
|
||||||
QTEST_MAIN(TestQString)
|
QTEST_MAIN(TestQString)
|
||||||
//! [11]
|
//! [11]
|
||||||
|
|
||||||
|
|
@ -94,19 +91,19 @@ QTEST_MAIN(TestQString)
|
||||||
|
|
||||||
|
|
||||||
//! [13]
|
//! [13]
|
||||||
QTest::keyClick(myWidget, 'a');
|
QTest.keyClick(myWidget, 'a')
|
||||||
//! [13]
|
//! [13]
|
||||||
|
|
||||||
|
|
||||||
//! [14]
|
//! [14]
|
||||||
QTest::keyClick(myWidget, Qt::Key_Escape);
|
QTest.keyClick(myWidget, Qt.Key_Escape)
|
||||||
|
|
||||||
QTest::keyClick(myWidget, Qt::Key_Escape, Qt::ShiftModifier, 200);
|
QTest.keyClick(myWidget, Qt.Key_Escape, Qt.ShiftModifier, 200)
|
||||||
//! [14]
|
//! [14]
|
||||||
|
|
||||||
|
|
||||||
//! [15]
|
//! [15]
|
||||||
QTest::keyClicks(myWidget, "hello world");
|
QTest.keyClicks(myWidget, "hello world")
|
||||||
//! [15]
|
//! [15]
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -115,74 +112,77 @@ namespace QTest {
|
||||||
template<>
|
template<>
|
||||||
char *toString(const MyPoint &point)
|
char *toString(const MyPoint &point)
|
||||||
{
|
{
|
||||||
QByteArray ba = "MyPoint(";
|
QByteArray ba = "MyPoint("
|
||||||
ba += QByteArray::number(point.x()) + ", " + QByteArray::number(point.y());
|
ba += QByteArray.number(point.x()) + ", " + QByteArray.number(point.y())
|
||||||
ba += ")";
|
ba += ")"
|
||||||
return qstrdup(ba.data());
|
return qstrdup(ba.data())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//! [16]
|
//! [16]
|
||||||
|
|
||||||
|
|
||||||
//! [17]
|
//! [17]
|
||||||
int i = 0;
|
int i = 0
|
||||||
while (myNetworkServerNotResponding() && i++ < 50)
|
while (myNetworkServerNotResponding() && i++ < 50)
|
||||||
QTest::qWait(250);
|
QTest.qWait(250)
|
||||||
//! [17]
|
//! [17]
|
||||||
|
|
||||||
|
|
||||||
//! [18]
|
//! [18]
|
||||||
MyFirstTestObject test1;
|
MyFirstTestObject test1
|
||||||
QTest::qExec(&test1);
|
QTest.qExec(&test1)
|
||||||
|
|
||||||
MySecondTestObject test2;
|
MySecondTestObject test2
|
||||||
QTest::qExec(&test2);
|
QTest.qExec(&test2)
|
||||||
//! [18]
|
//! [18]
|
||||||
|
|
||||||
|
|
||||||
//! [19]
|
//! [19]
|
||||||
QDir dir;
|
QDir dir
|
||||||
|
|
||||||
QTest::ignoreMessage(QtWarningMsg, "QDir::mkdir: Empty or null file name(s)");
|
QTest.ignoreMessage(QtWarningMsg, "QDir.mkdir: Empty or null file name(s)")
|
||||||
dir.mkdir("");
|
dir.mkdir("")
|
||||||
//! [19]
|
//! [19]
|
||||||
|
|
||||||
|
|
||||||
//! [20]
|
//! [20]
|
||||||
void myTestFunction_data()
|
void myTestFunction_data()
|
||||||
{
|
{
|
||||||
QTest::addColumn<QString>("aString");
|
QTest.addColumn<QString>("aString")
|
||||||
QTest::newRow("just hello") << QString("hello");
|
QTest.newRow("just hello") << QString("hello")
|
||||||
QTest::newRow("a null string") << QString();
|
QTest.newRow("a null string") << QString()
|
||||||
}
|
}
|
||||||
//! [20]
|
//! [20]
|
||||||
|
|
||||||
|
|
||||||
//! [21]
|
//! [21]
|
||||||
void myTestFunction_data() {
|
void myTestFunction_data() {
|
||||||
QTest::addColumn<int>("intval");
|
QTest.addColumn<int>("intval")
|
||||||
QTest::addColumn<QString>("str");
|
QTest.addColumn<QString>("str")
|
||||||
QTest::addColumn<double>("dbl");
|
QTest.addColumn<double>("dbl")
|
||||||
|
|
||||||
QTest::newRow("row1") << 1 << "hello" << 1.5;
|
QTest.newRow("row1") << 1 << "hello" << 1.5
|
||||||
}
|
}
|
||||||
//! [21]
|
//! [21]
|
||||||
|
|
||||||
|
|
||||||
//! [22]
|
//! [22]
|
||||||
void MyTestClass::cleanup()
|
void MyTestClass.cleanup()
|
||||||
{
|
{
|
||||||
if (qstrcmp(currentTestFunction(), "myDatabaseTest") == 0) {
|
if (qstrcmp(currentTestFunction(), "myDatabaseTest") == 0) {
|
||||||
// clean up all database connections
|
// clean up all database connections
|
||||||
closeAllDatabases();
|
closeAllDatabases()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//! [22]
|
//! [22]
|
||||||
|
|
||||||
|
|
||||||
//! [23]
|
//! [23]
|
||||||
QTest::qSleep(250);
|
QTest.qSleep(250)
|
||||||
//! [23]
|
//! [23]
|
||||||
|
|
||||||
}
|
//! [24]
|
||||||
|
widget = QWidget()
|
||||||
|
widget.show()
|
||||||
|
QTest.qWaitForWindowShown(widget)
|
||||||
|
//! [24]
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,52 @@
|
||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
||||||
|
** All rights reserved.
|
||||||
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||||
|
**
|
||||||
|
** This file is part of the examples of the Qt Toolkit.
|
||||||
|
**
|
||||||
|
** $QT_BEGIN_LICENSE:BSD$
|
||||||
|
** You may use this file under the terms of the BSD license as follows:
|
||||||
|
**
|
||||||
|
** "Redistribution and use in source and binary forms, with or without
|
||||||
|
** modification, are permitted provided that the following conditions are
|
||||||
|
** met:
|
||||||
|
** * Redistributions of source code must retain the above copyright
|
||||||
|
** notice, this list of conditions and the following disclaimer.
|
||||||
|
** * Redistributions in binary form must reproduce the above copyright
|
||||||
|
** notice, this list of conditions and the following disclaimer in
|
||||||
|
** the documentation and/or other materials provided with the
|
||||||
|
** distribution.
|
||||||
|
** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
|
||||||
|
** the names of its contributors may be used to endorse or promote
|
||||||
|
** products derived from this software without specific prior written
|
||||||
|
** permission.
|
||||||
|
**
|
||||||
|
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
|
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
|
||||||
|
** $QT_END_LICENSE$
|
||||||
|
**
|
||||||
|
****************************************************************************/
|
||||||
|
//![0]
|
||||||
|
import com.nokia.TimeExample 1.0 // import types from the plugin
|
||||||
|
|
||||||
|
Clock { // this class is defined in QML (com/nokia/TimeExample/Clock.qml)
|
||||||
|
|
||||||
|
Time { // this class is defined in C++ (plugin.cpp)
|
||||||
|
id: time
|
||||||
|
}
|
||||||
|
|
||||||
|
hours: time.hour
|
||||||
|
minutes: time.minute
|
||||||
|
}
|
||||||
|
//![0]
|
||||||
144
doc/codesnippets/examples/dialogs/tabdialog/tabdialog.cpp
Normal file
144
doc/codesnippets/examples/dialogs/tabdialog/tabdialog.cpp
Normal file
|
|
@ -0,0 +1,144 @@
|
||||||
|
|
||||||
|
//! [0]
|
||||||
|
class TabDialog (QDialog):
|
||||||
|
def __init__(self, fileName, parent = None):
|
||||||
|
QDialog.__init__(self, parent)
|
||||||
|
fileInfo = QFileInfo(fileName)
|
||||||
|
|
||||||
|
self.tabWidget = QTabWidget()
|
||||||
|
self.tabWidget.addTab(GeneralTab(fileInfo), "General")
|
||||||
|
self.tabWidget.addTab(PermissionsTab(fileInfo), "Permissions")
|
||||||
|
self.tabWidget.addTab(ApplicationsTab(fileInfo), "Applications")
|
||||||
|
//! [0]
|
||||||
|
|
||||||
|
//! [1] //! [2]
|
||||||
|
self.buttonBox = QDialogButtonBox(QDialogButtonBox.Ok
|
||||||
|
//! [1] //! [3]
|
||||||
|
| QDialogButtonBox.Cancel)
|
||||||
|
|
||||||
|
self.buttonBox.accepted.connect(self.accept)
|
||||||
|
self.buttonBox.rejected.connect(self.reject)
|
||||||
|
//! [2] //! [3]
|
||||||
|
|
||||||
|
//! [4]
|
||||||
|
mainLayout = QVBoxLayout()
|
||||||
|
mainLayout.addWidget(tabWidget)
|
||||||
|
mainLayout.addWidget(buttonBox)
|
||||||
|
self.setLayout(mainLayout)
|
||||||
|
//! [4]
|
||||||
|
|
||||||
|
//! [5]
|
||||||
|
self.setWindowTitle("Tab Dialog")
|
||||||
|
//! [5]
|
||||||
|
|
||||||
|
//! [6]
|
||||||
|
class GeneralTab (QWidget):
|
||||||
|
def __init__(self, fileInfo, parent = None):
|
||||||
|
QWidget.__init__(self, parent)
|
||||||
|
fileNameLabel = QLabel("File Name:")
|
||||||
|
fileNameEdit = QLineEdit(fileInfo.fileName())
|
||||||
|
|
||||||
|
pathLabel = QLabel("Path:")
|
||||||
|
pathValueLabel = QLabel(fileInfo.absoluteFilePath())
|
||||||
|
pathValueLabel.setFrameStyle(QFrame.Panel | QFrame.Sunken)
|
||||||
|
|
||||||
|
sizeLabel = QLabel("Size:")
|
||||||
|
size = fileInfo.size()/1024
|
||||||
|
sizeValueLabel = QLabel("%d K" % size)
|
||||||
|
sizeValueLabel.setFrameStyle(QFrame.Panel | QFrame.Sunken)
|
||||||
|
|
||||||
|
lastReadLabel = QLabel("Last Read:")
|
||||||
|
lastReadValueLabel = QLabel(fileInfo.lastRead().toString())
|
||||||
|
lastReadValueLabel.setFrameStyle(QFrame.Panel | QFrame.Sunken)
|
||||||
|
|
||||||
|
lastModLabel = QLabel("Last Modified:")
|
||||||
|
lastModValueLabel = QLabel(fileInfo.lastModified().toString())
|
||||||
|
lastModValueLabel.setFrameStyle(QFrame.Panel | QFrame.Sunken)
|
||||||
|
|
||||||
|
mainLayout = QVBoxLayout()
|
||||||
|
mainLayout.addWidget(fileNameLabel)
|
||||||
|
mainLayout.addWidget(fileNameEdit)
|
||||||
|
mainLayout.addWidget(pathLabel)
|
||||||
|
mainLayout.addWidget(pathValueLabel)
|
||||||
|
mainLayout.addWidget(sizeLabel)
|
||||||
|
mainLayout.addWidget(sizeValueLabel)
|
||||||
|
mainLayout.addWidget(lastReadLabel)
|
||||||
|
mainLayout.addWidget(lastReadValueLabel)
|
||||||
|
mainLayout.addWidget(lastModLabel)
|
||||||
|
mainLayout.addWidget(lastModValueLabel)
|
||||||
|
mainLayout.addStretch(1)
|
||||||
|
self.setLayout(mainLayout)
|
||||||
|
//! [6]
|
||||||
|
|
||||||
|
//! [7]
|
||||||
|
class PermissionsTab (QWidget):
|
||||||
|
def __init__(self, fileInfo, parent = None):
|
||||||
|
QWidget.__init__(self, parent)
|
||||||
|
permissionsGroup = QGroupBox("Permissions")
|
||||||
|
|
||||||
|
readable = QCheckBox("Readable")
|
||||||
|
if fileInfo.isReadable():
|
||||||
|
readable.setChecked(True)
|
||||||
|
|
||||||
|
writable = QCheckBox("Writable")
|
||||||
|
if fileInfo.isWritable():
|
||||||
|
writable.setChecked(True)
|
||||||
|
|
||||||
|
executable = QCheckBox("Executable")
|
||||||
|
if fileInfo.isExecutable():
|
||||||
|
executable.setChecked(True)
|
||||||
|
|
||||||
|
ownerGroup = QGroupBox("Ownership")
|
||||||
|
|
||||||
|
ownerLabel = QLabel("Owner")
|
||||||
|
ownerValueLabel = QLabel(fileInfo.owner())
|
||||||
|
ownerValueLabel.setFrameStyle(QFrame.Panel | QFrame.Sunken)
|
||||||
|
|
||||||
|
groupLabel = QLabel("Group")
|
||||||
|
groupValueLabel = QLabel(fileInfo.group())
|
||||||
|
groupValueLabel.setFrameStyle(QFrame.Panel | QFrame.Sunken)
|
||||||
|
|
||||||
|
permissionsLayout = QVBoxLayout()
|
||||||
|
permissionsLayout.addWidget(readable)
|
||||||
|
permissionsLayout.addWidget(writable)
|
||||||
|
permissionsLayout.addWidget(executable)
|
||||||
|
permissionsGroup.setLayout(permissionsLayout)
|
||||||
|
|
||||||
|
ownerLayout = QVBoxLayout()
|
||||||
|
ownerLayout.addWidget(ownerLabel)
|
||||||
|
ownerLayout.addWidget(ownerValueLabel)
|
||||||
|
ownerLayout.addWidget(groupLabel)
|
||||||
|
ownerLayout.addWidget(groupValueLabel)
|
||||||
|
ownerGroup.setLayout(ownerLayout)
|
||||||
|
|
||||||
|
mainLayout = QVBoxLayout()
|
||||||
|
mainLayout.addWidget(permissionsGroup)
|
||||||
|
mainLayout.addWidget(ownerGroup)
|
||||||
|
mainLayout.addStretch(1)
|
||||||
|
self.setLayout(mainLayout)
|
||||||
|
//! [7]
|
||||||
|
|
||||||
|
//! [8]
|
||||||
|
class ApplicationsTab (QWidget):
|
||||||
|
def __init__(self, fileInfo, parent = None):
|
||||||
|
QWidget.__init__(self, parent)
|
||||||
|
topLabel = QLabel("Open with:")
|
||||||
|
|
||||||
|
applicationsListBox = QListWidget()
|
||||||
|
applications = []
|
||||||
|
|
||||||
|
for i in range(30):
|
||||||
|
applications.append("Application %d" %s i)
|
||||||
|
applicationsListBox.insertItems(0, applications)
|
||||||
|
|
||||||
|
if fileInfo.suffix().isEmpty():
|
||||||
|
alwaysCheckBox = QCheckBox("Always use this application to open this type of file")
|
||||||
|
else:
|
||||||
|
alwaysCheckBox = QCheckBox("Always use this application to open files with the extension '%s'" % fileInfo.suffix())
|
||||||
|
|
||||||
|
layout = QVBoxLayout()
|
||||||
|
layout.addWidget(topLabel)
|
||||||
|
layout.addWidget(applicationsListBox)
|
||||||
|
layout.addWidget(alwaysCheckBox)
|
||||||
|
self.setLayout(layout)
|
||||||
|
//! [8]
|
||||||
131
doc/codesnippets/examples/uitools/textfinder/textfinder.cpp
Normal file
131
doc/codesnippets/examples/uitools/textfinder/textfinder.cpp
Normal file
|
|
@ -0,0 +1,131 @@
|
||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
||||||
|
** All rights reserved.
|
||||||
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||||
|
**
|
||||||
|
** This file is part of the examples of the Qt Toolkit.
|
||||||
|
**
|
||||||
|
** $QT_BEGIN_LICENSE:BSD$
|
||||||
|
** You may use this file under the terms of the BSD license as follows:
|
||||||
|
**
|
||||||
|
** "Redistribution and use in source and binary forms, with or without
|
||||||
|
** modification, are permitted provided that the following conditions are
|
||||||
|
** met:
|
||||||
|
** * Redistributions of source code must retain the above copyright
|
||||||
|
** notice, this list of conditions and the following disclaimer.
|
||||||
|
** * Redistributions in binary form must reproduce the above copyright
|
||||||
|
** notice, this list of conditions and the following disclaimer in
|
||||||
|
** the documentation and/or other materials provided with the
|
||||||
|
** distribution.
|
||||||
|
** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
|
||||||
|
** the names of its contributors may be used to endorse or promote
|
||||||
|
** products derived from this software without specific prior written
|
||||||
|
** permission.
|
||||||
|
**
|
||||||
|
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
|
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
|
||||||
|
** $QT_END_LICENSE$
|
||||||
|
**
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include <QtUiTools>
|
||||||
|
#include <QtGui>
|
||||||
|
#include "textfinder.h"
|
||||||
|
|
||||||
|
//! [0]
|
||||||
|
def __init__(self, parent = None):
|
||||||
|
QWidget.__init__(self. parent)
|
||||||
|
formWidget = self.loadUiFile()
|
||||||
|
|
||||||
|
//! [1]
|
||||||
|
self.ui_findButton = qFindChild(QPushButton, self, "findButton")
|
||||||
|
self.ui_textEdit = qFindChild(QTextEdit, self, "textEdit")
|
||||||
|
self.ui_lineEdit = qFindChild(QLineEdit, self, "lineEdit")
|
||||||
|
//! [0] //! [1]
|
||||||
|
|
||||||
|
//! [2]
|
||||||
|
QMetaObject.connectSlotsByName(self)
|
||||||
|
//! [2]
|
||||||
|
|
||||||
|
//! [3a]
|
||||||
|
self.loadTextFile()
|
||||||
|
//! [3a]
|
||||||
|
|
||||||
|
//! [3b]
|
||||||
|
layout = QVBoxLayout()
|
||||||
|
layout.addWidget(formWidget)
|
||||||
|
self.setLayout(layout)
|
||||||
|
//! [3b]
|
||||||
|
|
||||||
|
//! [3c]
|
||||||
|
self.setWindowTitle("Text Finder")
|
||||||
|
self.isFirstTime = True
|
||||||
|
//! [3c]
|
||||||
|
|
||||||
|
//! [4]
|
||||||
|
def loadUiFile(self):
|
||||||
|
loader = QUiLoader()
|
||||||
|
return loader.load(":/forms/textfinder.ui", self)
|
||||||
|
//! [4]
|
||||||
|
|
||||||
|
//! [5]
|
||||||
|
def loadTextFile(self):
|
||||||
|
inputFile = QFile(":/forms/input.txt")
|
||||||
|
inputFile.open(QIODevice.ReadOnly)
|
||||||
|
in = QTextStream(inputFile)
|
||||||
|
line = in.readAll()
|
||||||
|
inputFile.close()
|
||||||
|
|
||||||
|
self.ui_textEdit.append(line)
|
||||||
|
self.ui_textEdit.setUndoRedoEnabled(False)
|
||||||
|
self.ui_textEdit.setUndoRedoEnabled(True)
|
||||||
|
//! [5]
|
||||||
|
|
||||||
|
//! [6] //! [7]
|
||||||
|
@Slot()
|
||||||
|
def on_findButton_clicked(self):
|
||||||
|
searchString = self.ui_lineEdit.text()
|
||||||
|
document = self.ui_textEdit.document()
|
||||||
|
|
||||||
|
found = False
|
||||||
|
|
||||||
|
if not self.isFirstTime:
|
||||||
|
document.undo()
|
||||||
|
|
||||||
|
if not searchString:
|
||||||
|
QMessageBox.information(self, "Empty Search Field",
|
||||||
|
"The search field is empty. Please enter a word and click Find.")
|
||||||
|
else:
|
||||||
|
highlightCursor = QTextCursor(document)
|
||||||
|
cursor = QTextCursor(document)
|
||||||
|
cursor.beginEditBlock()
|
||||||
|
//! [6]
|
||||||
|
plainFormat = QTextCharFormat(highlightCursor.charFormat())
|
||||||
|
colorFormat = QTextCharFormat(plainFormat)
|
||||||
|
colorFormat.setForeground(Qt.red)
|
||||||
|
|
||||||
|
while not highlightCursor.isNull() and not highlightCursor.atEnd():
|
||||||
|
highlightCursor = document.find(searchString, highlightCursor, QTextDocument.FindWholeWords)
|
||||||
|
|
||||||
|
if not highlightCursor.isNull():
|
||||||
|
found = True
|
||||||
|
highlightCursor.movePosition(QTextCursor.WordRight, QTextCursor.KeepAnchor)
|
||||||
|
highlightCursor.mergeCharFormat(colorFormat)
|
||||||
|
//! [8]
|
||||||
|
cursor.endEditBlock()
|
||||||
|
//! [7] //! [9]
|
||||||
|
self.isFirstTime = False
|
||||||
|
|
||||||
|
if not found:
|
||||||
|
QMessageBox.information(self, "Word Not Found", "Sorry, the word cannot be found.");
|
||||||
|
//! [8] //! [9]
|
||||||
65
doc/codesnippets/webkitsnippets/webelement/main.cpp
Normal file
65
doc/codesnippets/webkitsnippets/webelement/main.cpp
Normal file
|
|
@ -0,0 +1,65 @@
|
||||||
|
|
||||||
|
def traverse():
|
||||||
|
//! [Traversing with QWebElement]
|
||||||
|
frame.setHtml("<html><body><p>First Paragraph</p><p>Second Paragraph</p></body></html>")
|
||||||
|
doc = frame.documentElement()
|
||||||
|
body = doc.firstChild()
|
||||||
|
firstParagraph = body.firstChild()
|
||||||
|
secondParagraph = firstParagraph.nextSibling()
|
||||||
|
//! [Traversing with QWebElement]
|
||||||
|
|
||||||
|
def findButtonAndClick():
|
||||||
|
frame.setHtml("<form name=\"myform\" action=\"submit_form.asp\" method=\"get\">" \
|
||||||
|
"<input type=\"text\" name=\"myfield\">" \
|
||||||
|
"<input type=\"submit\" value=\"Submit\">" \
|
||||||
|
"</form>")
|
||||||
|
|
||||||
|
//! [Calling a DOM element method]
|
||||||
|
|
||||||
|
document = frame.documentElement()
|
||||||
|
# Assume that the document has the following structure:
|
||||||
|
#
|
||||||
|
# <form name="myform" action="submit_form.asp" method="get">
|
||||||
|
# <input type="text" name="myfield">
|
||||||
|
# <input type="submit" value="Submit">
|
||||||
|
# </form>
|
||||||
|
|
||||||
|
button = document.findFirst("input[type=submit]")
|
||||||
|
button.evaluateJavaScript("click()")
|
||||||
|
|
||||||
|
//! [Calling a DOM element method]
|
||||||
|
|
||||||
|
def autocomplete1():
|
||||||
|
document = frame.documentElement()
|
||||||
|
//! [autocomplete1]
|
||||||
|
firstTextInput = document.findFirst("input[type=text]")
|
||||||
|
storedText = firstTextInput.attribute("value")
|
||||||
|
//! [autocomplete1]
|
||||||
|
|
||||||
|
def autocomplete2():
|
||||||
|
document = frame.documentElement()
|
||||||
|
storedText = "text"
|
||||||
|
|
||||||
|
//! [autocomplete2]
|
||||||
|
firstTextInput = document.findFirst("input[type=text]")
|
||||||
|
textInput.setAttribute("value", storedText)
|
||||||
|
//! [autocomplete2]
|
||||||
|
|
||||||
|
def findAll():
|
||||||
|
//! [FindAll]
|
||||||
|
document = frame.documentElement()
|
||||||
|
# Assume the document has the following structure:
|
||||||
|
#
|
||||||
|
# <p class=intro>
|
||||||
|
# <span>Intro</span>
|
||||||
|
# <span>Snippets</span>
|
||||||
|
# </p>
|
||||||
|
# <p>
|
||||||
|
# <span>Content</span>
|
||||||
|
# <span>Here</span>
|
||||||
|
# </p>
|
||||||
|
|
||||||
|
//! [FindAll intro]
|
||||||
|
allSpans = document.findAll("span")
|
||||||
|
introSpans = document.findAll("p.intro span")
|
||||||
|
//! [FindAll intro] //! [FindAll]
|
||||||
Loading…
Add table
Add a link
Reference in a new issue