Showing posts with label PyQt4. Show all posts
Showing posts with label PyQt4. Show all posts

Saturday, May 26, 2007

QCoreApplication::setLibraryPaths

void QCoreApplication::setLibraryPaths ( const QStringList & paths ) [static]

Sets the list of directories to search when loading libraries to paths. All existing paths will be deleted and the path list will consist of the paths given in paths.

See also libraryPaths(), addLibraryPath(), removeLibraryPath(), and QLibrary.

Friday, May 25, 2007

GIf support in Windows

(To configure Qt with GIF support, pass -qt-gif to the configure script or check the appropriate option in the graphical installer.)

Tuesday, May 22, 2007

QThread::Priority

QThread QObject.thread (self)

Returns the thread in which the object lives.

See also moveToThread().


enum QThread::Priority

This enum type indicates how the operating system should schedule newly created threads.

ConstantValueDescription
QThread::IdlePriority0scheduled only when no other threads are running.
QThread::LowestPriority1scheduled less often than LowPriority.
QThread::LowPriority2scheduled less often than NormalPriority.
QThread::NormalPriority3the default priority of the operating system.
QThread::HighPriority4scheduled more often than NormalPriority.
QThread::HighestPriority5scheduled more often than HighPriority.
QThread::TimeCriticalPriority6scheduled as often as possible.
QThread::InheritPriority7use the same priority as the creating thread. This is the default.

单纯的通过线程解决不了假死问题是, 可以试着调整一下优先级.

Monday, May 21, 2007

QRegExp.indexIn

int QRegExp.indexIn (self, QString str, int offset = 0, CaretMode caretMode = QRegExp.CaretAtZero)

Attempts to find a match in str from position offset (0 by default). If offset is -1, the search starts at the last character; if -2, at the next to last character; etc.

Returns the position of the first match, or -1 if there was no match.

The caretMode parameter can be used to instruct whether ^ should match at index 0 or at offset.

You might prefer to use QString.indexOf(), QString.contains(), or even QStringList.filter(). To replace matches use QString.replace().

Example:

 QString str = "offsets: 1.23 .50 71.00 6.00";
QRegExp rx("\\d*\\.\\d+"); // primitive floating point matching
int count = 0;
int pos = 0;
while ((pos = rx.indexIn(str, pos)) != -1) {
++count;
pos += rx.matchedLength();
}
// pos will be 9, 14, 18 and finally 24; count will end up as 4

Thursday, May 17, 2007

QEvent::Type

Member Type Documentation

enum QEvent::Type

This enum type defines the valid event types in Qt. The event types and the specialized classes for each type are as follows:

ConstantValueDescription
QEvent::None0Not an event.
QEvent::AccessibilityDescription130Used to query accessibility description texts (QAccessibleEvent).
QEvent::AccessibilityHelp119Used to query accessibility help texts (QAccessibleEvent).
QEvent::AccessibilityPrepare86Accessibility information is requested.
QEvent::ActionAdded114A new action has been added (QActionEvent).
QEvent::ActionChanged113An action has been changed (QActionEvent).
QEvent::ActionRemoved115An action has been removed (QActionEvent).
QEvent::ActivationChange99A widget's top-level window activation state has changed.
QEvent::ApplicationActivated121The application has been made available to the user.
QEvent::ApplicationDeactivated122The application has been suspended, and is unavailable to the user.
QEvent::ApplicationFontChange36The default application font has changed.
QEvent::ApplicationLayoutDirectionChange37The default application layout direction has changed.
QEvent::ApplicationPaletteChange38The default application palette has changed.
QEvent::ApplicationWindowIconChange35The application's icon has changed.
QEvent::ChildAdded68An object gets a child (QChildEvent).
QEvent::ChildPolished69A widget child gets polished (QChildEvent).
QEvent::ChildRemoved71An object loses a child (QChildEvent).
QEvent::Clipboard40The clipboard contents have changed (QClipboardEvent).
QEvent::Close19Widget was closed (QCloseEvent).
QEvent::ContextMenu82Context popup menu (QContextMenuEvent).
QEvent::DeferredDelete52The object will be deleted after it has cleaned up.
QEvent::DragEnter60The cursor enters a widget during a drag and drop operation (QDragEnterEvent).
QEvent::DragLeave62The cursor leaves a widget during a drag and drop operation (QDragLeaveEvent).
QEvent::DragMove61A drag and drop operation is in progress (QDragMoveEvent).
QEvent::Drop63A drag and drop operation is completed (QDropEvent).
QEvent::EnabledChange98Widget's enabled state has changed.
QEvent::Enter10Mouse enters widget's boundaries.
QEvent::EnterEditFocus150An editor widget gains focus for editing.
QEvent::EnterWhatsThisMode124Send to toplevel widgets when the application enters "What's This?" mode.
QEvent::FileOpen116File open request (QFileOpenEvent).
QEvent::FocusIn8Widget gains keyboard focus (QFocusEvent).
QEvent::FocusOut9Widget loses keyboard focus (QFocusEvent).
QEvent::FontChange97Widget's font has changed.
QEvent::GraphicsSceneContextMenu159Context popup menu over a graphics scene (QGraphicsSceneContextMenuEvent).
QEvent::GraphicsSceneDragEnter164The cursor enters a graphics scene during a drag and drop operation.
QEvent::GraphicsSceneDragLeave166The cursor leaves a graphics scene during a drag and drop operation.
QEvent::GraphicsSceneDragMove165A drag and drop operation is in progress over a scene.
QEvent::GraphicsSceneDrop167A drag and drop operation is completed over a scene.
QEvent::GraphicsSceneHelp163The user requests help for a graphics scene (QHelpEvent).
QEvent::GraphicsSceneHoverEnter160The mouse cursor enters a hover item in a graphics scene (QGraphicsSceneHoverEvent).
QEvent::GraphicsSceneHoverLeave162The mouse cursor leaves a hover item in a graphics scene (QGraphicsSceneHoverEvent).
QEvent::GraphicsSceneHoverMove161The mouse cursor moves inside a hover item in a graphics scene (QGraphicsSceneHoverEvent).
QEvent::GraphicsSceneMouseDoubleClick158Mouse press again (double click) in a graphics scene (QGraphicsSceneMouseEvent).
QEvent::GraphicsSceneMouseMove155Move mouse in a graphics scene (QGraphicsSceneMouseEvent).
QEvent::GraphicsSceneMousePress156Mouse press in a graphics scene (QGraphicsSceneMouseEvent).
QEvent::GraphicsSceneMouseRelease157Mouse release in a graphics scene (QGraphicsSceneMouseEvent).
QEvent::GraphicsSceneWheel168Mouse wheel rolled in a graphics scene (QGraphicsSceneWheelEvent).
QEvent::Hide18Widget was hidden (QHideEvent).
QEvent::HideToParent27A child widget has been hidden.
QEvent::HoverEnter127The mouse cursor enters a hover widget (QHoverEvent).
QEvent::HoverLeave128The mouse cursor leaves a hover widget (QHoverEvent).
QEvent::HoverMove129The mouse cursor moves inside a hover widget (QHoverEvent).
QEvent::IconDrag96The main icon of a window has been dragged away (QIconDragEvent).
QEvent::IconTextChange101Widget's icon text has been changed.
QEvent::InputMethod83An input method is being used (QInputMethodEvent).
QEvent::KeyPress6Key press (QKeyEvent).
QEvent::KeyRelease7Key release (QKeyEvent).
QEvent::LanguageChange89The application translation changed.
QEvent::LayoutDirectionChange90The direction of layouts changed.
QEvent::LayoutRequest76Widget layout needs to be redone.
QEvent::Leave11Mouse leaves widget's boundaries.
QEvent::LeaveEditFocus151An editor widget loses focus for editing.
QEvent::LeaveWhatsThisMode125Send to toplevel widgets when the application leaves "What's This?" mode.
QEvent::LocaleChange88The system locale has changed.
QEvent::MenubarUpdated153The window's menu bar has been updated.
QEvent::MetaCall43An asynchronous method invocation via QMetaObject::invokeMethod().
QEvent::ModifiedChange102Widgets modification state has been changed.
QEvent::MouseButtonDblClick4Mouse press again (QMouseEvent).
QEvent::MouseButtonPress2Mouse press (QMouseEvent).
QEvent::MouseButtonRelease3Mouse release (QMouseEvent).
QEvent::MouseMove5Mouse move (QMouseEvent).
QEvent::MouseTrackingChange109The mouse tracking state has changed.
QEvent::Move13Widget's position changed (QMoveEvent).
QEvent::Paint12Screen update necessary (QPaintEvent).
QEvent::PaletteChange39Palette of the widget changed.
QEvent::ParentAboutToChange131The widget parent is about to change.
QEvent::ParentChange21The widget parent has changed.
QEvent::Polish75The widget is polished.
QEvent::PolishRequest74The widget should be polished.
QEvent::QueryWhatsThis123The widget should accept the event if it has "What's This?" help.
QEvent::Resize14Widget's size changed (QResizeEvent).
QEvent::Shortcut117Key press in child for shortcut key handling (QShortcutEvent).
QEvent::ShortcutOverride51Key press in child, for overriding shortcut key handling (QKeyEvent).
QEvent::Show17Widget was shown on screen (QShowEvent).
QEvent::ShowToParent26A child widget has been shown.
QEvent::SockAct50Socket activated, used to implement QSocketNotifier.
QEvent::StatusTip112A status tip is requested (QStatusTipEvent).
QEvent::StyleChange100Widget's style has been changed.
QEvent::TabletMove87Wacom tablet move (QTabletEvent).
QEvent::TabletPress92Wacom tablet press (QTabletEvent).
QEvent::TabletRelease93Wacom tablet release (QTabletEvent).
QEvent::TabletEnterProximity171Wacom tablet enter proximity event (QTabletEvent), sent to QApplication.
QEvent::TabletLeaveProximity172Wacom tablet leave proximity event (QTabletEvent), sent to QApplication.
QEvent::Timer1Regular timer events (QTimerEvent).
QEvent::ToolBarChange120The toolbar button is toggled on Mac OS X.
QEvent::ToolTip110A tooltip was requested (QHelpEvent).
QEvent::UpdateLater78The widget should be queued to be repainted at a later time.
QEvent::UpdateRequest77The widget should be repainted.
QEvent::WhatsThis111The widget should reveal "What's This?" help (QHelpEvent).
QEvent::WhatsThisClicked118A link in a widget's "What's This?" help was clicked.
QEvent::Wheel31Mouse wheel rolled (QWheelEvent).
QEvent::WinEventAct132A Windows-specific activation event has occurred.
QEvent::WindowActivate24Window was activated.
QEvent::WindowBlocked103The window is blocked by a modal dialog.
QEvent::WindowDeactivate25Window was deactivated.
QEvent::WindowIconChange34The window's icon has changed.
QEvent::WindowStateChange105The window's state (minimized, maximized or full-screen) has changed (QWindowStateChangeEvent).
QEvent::WindowTitleChange33The window title has changed.
QEvent::WindowUnblocked104The window is unblocked after a modal dialog exited.
QEvent::ZOrderChange126The widget's z-order has changed. This event is never sent to top level windows.
QEvent::KeyboardLayoutChange169The keyboard layout has changed.
QEvent::DynamicPropertyChange170A dynamic property was added, changed or removed from the object.

User events should have values between User and MaxUser:

ConstantValueDescription
QEvent::User1000User-defined event.
QEvent::MaxUser65535Last user event ID.

Qt::Key

enum Qt::Key

The key names used by Qt.

ConstantValueDescription
Qt::Key_Escape0x01000000
Qt::Key_Tab0x01000001
Qt::Key_Backtab0x01000002
Qt::Key_Backspace0x01000003
Qt::Key_Return0x01000004
Qt::Key_Enter0x01000005
Qt::Key_Insert0x01000006
Qt::Key_Delete0x01000007
Qt::Key_Pause0x01000008
Qt::Key_Print0x01000009
Qt::Key_SysReq0x0100000a
Qt::Key_Clear0x0100000b
Qt::Key_Home0x01000010
Qt::Key_End0x01000011
Qt::Key_Left0x01000012
Qt::Key_Up0x01000013
Qt::Key_Right0x01000014
Qt::Key_Down0x01000015
Qt::Key_PageUp0x01000016
Qt::Key_PageDown0x01000017
Qt::Key_Shift0x01000020
Qt::Key_Control0x01000021On Mac OS X, this corresponds to the Command keys.
Qt::Key_Meta0x01000022On Mac OS X, this corresponds to the Control keys.
Qt::Key_Alt0x01000023
Qt::Key_AltGr0x01001103
Qt::Key_CapsLock0x01000024
Qt::Key_NumLock0x01000025
Qt::Key_ScrollLock0x01000026
Qt::Key_F10x01000030
Qt::Key_F20x01000031
Qt::Key_F30x01000032
Qt::Key_F40x01000033
Qt::Key_F50x01000034
Qt::Key_F60x01000035
Qt::Key_F70x01000036
Qt::Key_F80x01000037
Qt::Key_F90x01000038
Qt::Key_F100x01000039
Qt::Key_F110x0100003a
Qt::Key_F120x0100003b
Qt::Key_F130x0100003c
Qt::Key_F140x0100003d
Qt::Key_F150x0100003e
Qt::Key_F160x0100003f
Qt::Key_F170x01000040
Qt::Key_F180x01000041
Qt::Key_F190x01000042
Qt::Key_F200x01000043
Qt::Key_F210x01000044
Qt::Key_F220x01000045
Qt::Key_F230x01000046
Qt::Key_F240x01000047
Qt::Key_F250x01000048
Qt::Key_F260x01000049
Qt::Key_F270x0100004a
Qt::Key_F280x0100004b
Qt::Key_F290x0100004c
Qt::Key_F300x0100004d
Qt::Key_F310x0100004e
Qt::Key_F320x0100004f
Qt::Key_F330x01000050
Qt::Key_F340x01000051
Qt::Key_F350x01000052
Qt::Key_Super_L0x01000053
Qt::Key_Super_R0x01000054
Qt::Key_Menu0x01000055
Qt::Key_Hyper_L0x01000056
Qt::Key_Hyper_R0x01000057
Qt::Key_Help0x01000058
Qt::Key_Direction_L0x01000059
Qt::Key_Direction_R0x01000060
Qt::Key_Space0x20
Qt::Key_AnyKey_Space
Qt::Key_Exclam0x21
Qt::Key_QuoteDbl0x22
Qt::Key_NumberSign0x23
Qt::Key_Dollar0x24
Qt::Key_Percent0x25
Qt::Key_Ampersand0x26
Qt::Key_Apostrophe0x27
Qt::Key_ParenLeft0x28
Qt::Key_ParenRight0x29
Qt::Key_Asterisk0x2a
Qt::Key_Plus0x2b
Qt::Key_Comma0x2c
Qt::Key_Minus0x2d
Qt::Key_Period0x2e
Qt::Key_Slash0x2f
Qt::Key_00x30
Qt::Key_10x31
Qt::Key_20x32
Qt::Key_30x33
Qt::Key_40x34
Qt::Key_50x35
Qt::Key_60x36
Qt::Key_70x37
Qt::Key_80x38
Qt::Key_90x39
Qt::Key_Colon0x3a
Qt::Key_Semicolon0x3b
Qt::Key_Less0x3c
Qt::Key_Equal0x3d
Qt::Key_Greater0x3e
Qt::Key_Question0x3f
Qt::Key_At0x40
Qt::Key_A0x41
Qt::Key_B0x42
Qt::Key_C0x43
Qt::Key_D0x44
Qt::Key_E0x45
Qt::Key_F0x46
Qt::Key_G0x47
Qt::Key_H0x48
Qt::Key_I0x49
Qt::Key_J0x4a
Qt::Key_K0x4b
Qt::Key_L0x4c
Qt::Key_M0x4d
Qt::Key_N0x4e
Qt::Key_O0x4f
Qt::Key_P0x50
Qt::Key_Q0x51
Qt::Key_R0x52
Qt::Key_S0x53
Qt::Key_T0x54
Qt::Key_U0x55
Qt::Key_V0x56
Qt::Key_W0x57
Qt::Key_X0x58
Qt::Key_Y0x59
Qt::Key_Z0x5a
Qt::Key_BracketLeft0x5b
Qt::Key_Backslash0x5c
Qt::Key_BracketRight0x5d
Qt::Key_AsciiCircum0x5e
Qt::Key_Underscore0x5f
Qt::Key_QuoteLeft0x60
Qt::Key_BraceLeft0x7b
Qt::Key_Bar0x7c
Qt::Key_BraceRight0x7d
Qt::Key_AsciiTilde0x7e
Qt::Key_nobreakspace0x0a0
Qt::Key_exclamdown0x0a1
Qt::Key_cent0x0a2
Qt::Key_sterling0x0a3
Qt::Key_currency0x0a4
Qt::Key_yen0x0a5
Qt::Key_brokenbar0x0a6
Qt::Key_section0x0a7
Qt::Key_diaeresis0x0a8
Qt::Key_copyright0x0a9
Qt::Key_ordfeminine0x0aa
Qt::Key_guillemotleft0x0ab
Qt::Key_notsign0x0ac
Qt::Key_hyphen0x0ad
Qt::Key_registered0x0ae
Qt::Key_macron0x0af
Qt::Key_degree0x0b0
Qt::Key_plusminus0x0b1
Qt::Key_twosuperior0x0b2
Qt::Key_threesuperior0x0b3
Qt::Key_acute0x0b4
Qt::Key_mu0x0b5
Qt::Key_paragraph0x0b6
Qt::Key_periodcentered0x0b7
Qt::Key_cedilla0x0b8
Qt::Key_onesuperior0x0b9
Qt::Key_masculine0x0ba
Qt::Key_guillemotright0x0bb
Qt::Key_onequarter0x0bc
Qt::Key_onehalf0x0bd
Qt::Key_threequarters0x0be
Qt::Key_questiondown0x0bf
Qt::Key_Agrave0x0c0
Qt::Key_Aacute0x0c1
Qt::Key_Acircumflex0x0c2
Qt::Key_Atilde0x0c3
Qt::Key_Adiaeresis0x0c4
Qt::Key_Aring0x0c5
Qt::Key_AE0x0c6
Qt::Key_Ccedilla0x0c7
Qt::Key_Egrave0x0c8
Qt::Key_Eacute0x0c9
Qt::Key_Ecircumflex0x0ca
Qt::Key_Ediaeresis0x0cb
Qt::Key_Igrave0x0cc
Qt::Key_Iacute0x0cd
Qt::Key_Icircumflex0x0ce
Qt::Key_Idiaeresis0x0cf
Qt::Key_ETH0x0d0
Qt::Key_Ntilde0x0d1
Qt::Key_Ograve0x0d2
Qt::Key_Oacute0x0d3
Qt::Key_Ocircumflex0x0d4
Qt::Key_Otilde0x0d5
Qt::Key_Odiaeresis0x0d6
Qt::Key_multiply0x0d7
Qt::Key_Ooblique0x0d8
Qt::Key_Ugrave0x0d9
Qt::Key_Uacute0x0da
Qt::Key_Ucircumflex0x0db
Qt::Key_Udiaeresis0x0dc
Qt::Key_Yacute0x0dd
Qt::Key_THORN0x0de
Qt::Key_ssharp0x0df
Qt::Key_division0x0f7
Qt::Key_ydiaeresis0x0ff
Qt::Key_Multi_key0x01001120
Qt::Key_Codeinput0x01001137
Qt::Key_SingleCandidate0x0100113c
Qt::Key_MultipleCandidate0x0100113d
Qt::Key_PreviousCandidate0x0100113e
Qt::Key_Mode_switch0x0100117e
Qt::Key_Kanji0x01001121
Qt::Key_Muhenkan0x01001122
Qt::Key_Henkan0x01001123
Qt::Key_Romaji0x01001124
Qt::Key_Hiragana0x01001125
Qt::Key_Katakana0x01001126
Qt::Key_Hiragana_Katakana0x01001127
Qt::Key_Zenkaku0x01001128
Qt::Key_Hankaku0x01001129
Qt::Key_Zenkaku_Hankaku0x0100112a
Qt::Key_Touroku0x0100112b
Qt::Key_Massyo0x0100112c
Qt::Key_Kana_Lock0x0100112d
Qt::Key_Kana_Shift0x0100112e
Qt::Key_Eisu_Shift0x0100112f
Qt::Key_Eisu_toggle0x01001130
Qt::Key_Hangul0x01001131
Qt::Key_Hangul_Start0x01001132
Qt::Key_Hangul_End0x01001133
Qt::Key_Hangul_Hanja0x01001134
Qt::Key_Hangul_Jamo0x01001135
Qt::Key_Hangul_Romaja0x01001136
Qt::Key_Hangul_Jeonja0x01001138
Qt::Key_Hangul_Banja0x01001139
Qt::Key_Hangul_PreHanja0x0100113a
Qt::Key_Hangul_PostHanja0x0100113b
Qt::Key_Hangul_Special0x0100113f
Qt::Key_Dead_Grave0x01001250
Qt::Key_Dead_Acute0x01001251
Qt::Key_Dead_Circumflex0x01001252
Qt::Key_Dead_Tilde0x01001253
Qt::Key_Dead_Macron0x01001254
Qt::Key_Dead_Breve0x01001255
Qt::Key_Dead_Abovedot0x01001256
Qt::Key_Dead_Diaeresis0x01001257
Qt::Key_Dead_Abovering0x01001258
Qt::Key_Dead_Doubleacute0x01001259
Qt::Key_Dead_Caron0x0100125a
Qt::Key_Dead_Cedilla0x0100125b
Qt::Key_Dead_Ogonek0x0100125c
Qt::Key_Dead_Iota0x0100125d
Qt::Key_Dead_Voiced_Sound0x0100125e
Qt::Key_Dead_Semivoiced_Sound0x0100125f
Qt::Key_Dead_Belowdot0x01001260
Qt::Key_Dead_Hook0x01001261
Qt::Key_Dead_Horn0x01001262
Qt::Key_Back0x01000061
Qt::Key_Forward0x01000062
Qt::Key_Stop0x01000063
Qt::Key_Refresh0x01000064
Qt::Key_VolumeDown0x01000070
Qt::Key_VolumeMute0x01000071
Qt::Key_VolumeUp0x01000072
Qt::Key_BassBoost0x01000073
Qt::Key_BassUp0x01000074
Qt::Key_BassDown0x01000075
Qt::Key_TrebleUp0x01000076
Qt::Key_TrebleDown0x01000077
Qt::Key_MediaPlay0x01000080
Qt::Key_MediaStop0x01000081
Qt::Key_MediaPrevious0x01000082
Qt::Key_MediaNext0x01000083
Qt::Key_MediaRecord0x01000084
Qt::Key_HomePage0x01000090
Qt::Key_Favorites0x01000091
Qt::Key_Search0x01000092
Qt::Key_Standby0x01000093
Qt::Key_OpenUrl0x01000094
Qt::Key_LaunchMail0x010000a0
Qt::Key_LaunchMedia0x010000a1
Qt::Key_Launch00x010000a2
Qt::Key_Launch10x010000a3
Qt::Key_Launch20x010000a4
Qt::Key_Launch30x010000a5
Qt::Key_Launch40x010000a6
Qt::Key_Launch50x010000a7
Qt::Key_Launch60x010000a8
Qt::Key_Launch70x010000a9
Qt::Key_Launch80x010000aa
Qt::Key_Launch90x010000ab
Qt::Key_LaunchA0x010000ac
Qt::Key_LaunchB0x010000ad
Qt::Key_LaunchC0x010000ae
Qt::Key_LaunchD0x010000af
Qt::Key_LaunchE0x010000b0
Qt::Key_LaunchF0x010000b1
Qt::Key_MediaLast0x0100ffff
Qt::Key_unknown0x01ffffff
Qt::Key_Call0x01100004
Qt::Key_Context10x01100000
Qt::Key_Context20x01100001
Qt::Key_Context30x01100002
Qt::Key_Context40x01100003
Qt::Key_Flip0x01100006
Qt::Key_Hangup0x01100005
Qt::Key_No0x01010002
Qt::Key_Select0x01010000
Qt::Key_Yes0x01010001
Qt::Key_Execute0x01020003
Qt::Key_Printer0x01020002
Qt::Key_Play0x01020005
Qt::Key_Sleep0x01020004
Qt::Key_Zoom0x01020006
Qt::Key_Cancel0x01020001

See also QKeyEvent::key

QObject.eventFilter

bool QObject.eventFilter (self, QObject, QEvent)

Filters events if this object has been installed as an event filter for the watched object.

In your reimplementation of this function, if you want to filter the event out, i.e. stop it being handled further, return true; otherwise return false.

Example:

 class MainWindow : public QMainWindow
{
public:
MainWindow();

protected:
bool eventFilter(QObject *obj, QEvent *ev);

private:
QTextEdit *textEdit;
};

MainWindow.MainWindow()
{
textEdit = new QTextEdit;
setCentralWidget(textEdit);

textEdit->installEventFilter(this);
}

bool MainWindow.eventFilter(QObject *obj, QEvent *event)
{
if (obj == textEdit) {
if (event->type() == QEvent.KeyPress) {
QKeyEvent *keyEvent = static_cast(event);
qDebug() << "Ate key press" <<>key();
return true;
} else {
return false;
}
} else {
// pass the event on to the parent class
return QMainWindow.eventFilter(obj, event);
}
}

Notice in the example above that unhandled events are passed to the base class's eventFilter() function, since the base class might have reimplemented eventFilter() for its own internal purposes.

Warning: If you delete the receiver object in this function, be sure to return true. Otherwise, Qt will forward the event to the deleted object and the program might crash.

See also installEventFilter().

Wednesday, May 16, 2007

QThread

QThread: Destroyed while thread is still running

Restoring a Window's Geometry

Since version 4.2, Qt provides functions that saves and restores a window's geometry and state for you. QWidget::saveGeometry() saves the window geometry and maximized/fullscreen state, while QWidget::restoreGeometry() restores it. The restore function also checks if the restored geometry is outside the available screen geometry, and modifies it as appropriate if it is.

The rest of this document describes how to save and restore the geometry using the geometry properties. On Windows, this is basically storing the result of QWidget::geometry() and calling QWidget::setGeometry() in the next session before calling show(). On X11, this won't work because an invisible window doesn't have a frame yet. The window manager will decorate the window later. When this happens, the window shifts towards the bottom/right corner of the screen depending on the size of the decoration frame. Although X provides a way to avoid this shift, most window managers fail to implement this feature.

A workaround is to call setGeometry() after show(). This has the two disadvantages that the widget appears at a wrong place for a millisecond (results in flashing) and that currently only every second window manager gets it right. A safer solution is to store both pos() and size() and to restore the geometry using QWidget::resize() and move() before calling show(), as demonstrated in the following code snippets (from the Application example):

 void MainWindow::readSettings()
{
QSettings settings("Trolltech", "Application Example");
QPoint pos = settings.value("pos", QPoint(200, 200)).toPoint();
QSize size = settings.value("size", QSize(400, 400)).toSize();
resize(size);
move(pos);
}

void MainWindow::writeSettings()
{
QSettings settings("Trolltech", "Application Example");
settings.setValue("pos", pos());
settings.setValue("size", size());
}

This method works on Windows, Mac OS X, and most X11 window managers.

Saturday, May 12, 2007

PyQt4 Richtext Supported HTML Subset

Supported HTML Subset

The following table lists the HTML tags supported by Qt's rich text engine:

TagDescriptionComment
aAnchor or linkSupports the href and name attributes.
addressAddress
bBold
bigLarger font
blockquoteIndented paragraph
bodyDocument bodySupports the bgcolor attribute, which can be a Qt color name or a #RRGGBB color specification.
brLine break
centerCentered paragraph
citeInline citationSame as i.
codeCodeSame as tt.
ddDefinition data
dfnDefinitionSame as i.
divDocument divisionSupports the standard block attributes.
dlDefinition listSupports the standard block attributes.
dtDefinition termSupports the standard block attributes.
emEmphasizedSame as i.
fontFont size, family, and/or colorSupports the following attributes: size, face, and color (Qt color names or #RRGGBB).
h1Level 1 headingSupports the standard block attributes.
h2Level 2 headingSupports the standard block attributes.
h3Level 3 headingSupports the standard block attributes.
h4Level 4 headingSupports the standard block attributes.
h5Level 5 headingSupports the standard block attributes.
h6Level 6 headingSupports the standard block attributes.
headDocument header
hrHorizontal lineSupports the width attribute, which can be specified as an absolute or relative (%) value.
htmlHTML document
iItalic
imgImageSupports the src, source (for Qt 3 compatibility), width, and height attributes.
kbdUser-entered text
metaMeta-informationIf a text encoding is specified using the meta tag, it is picked up by Qt::codecForHtml(). Likewise, if an encoding is specified to QTextDocument::toHtml(), the encoding is stored using a meta tag, for example:
 
liList item
nobrNon-breakable text
olOrdered listSupports the standard list attributes.
pParagraphLeft-aligned by default. Supports the standard block attributes.
prePreformated text
qtQt rich-text documentSynonym for html. Provided for compatibility with earlier versions of Qt.
sStrikethrough
sampSample codeSame as tt.
smallSmall font
spanGrouped elements
strongStrongSame as b.
subSubscript
supSuperscript
tableTableSupports the following attributes: border, bgcolor (Qt color names or #RRGGBB), cellspacing, cellpadding, width (absolute or relative), and height.
tbodyTable bodyDoes nothing.
tdTable data cellSupports the standard table cell attributes.
tfootTable footerDoes nothing.
thTable header cellSupports the standard table cell attributes.
theadTable headerIf the thead tag is specified, it is used when printing tables that span multiple pages.
titleDocument titleThe value specified using the title tag is available through QTextDocument::metaInformation().
trTable rowSupports the bgcolor attribute, which can be a Qt color name or a #RRGGBB color specification.
ttTypewrite font
uUnderlined
ulUnordered listSupports the standard list attributes.
varVariableSame as i.

Block Attributes

The following attributes are supported by the div, dl, dt, h1, h2, h3, h4, h5, h6, p tags:

  • align (left, right, center, justify)
  • dir (ltr, rtl)

List Attributes

The following attribute is supported by the ol and ul tags:

  • type (1, a, A, square, disc, circle)

Table Cell Attributes

The following attributes are supported by the td and th tags:

  • width (absolute, relative, or no-value)
  • bgcolor (Qt color names or #RRGGBB)
  • colspan
  • rowspan

CSS Properties

The following table lists the CSS properties supported by Qt's rich text engine:

PropertyValuesDescription
background-color
Background color for elements
background-image
Background image for elements
color
Text foreground color
font-family
Font family name
font-size[ small | medium | large | x-large | xx-large ] | pt | pxFont size relative to the document font, or specified in points or pixels
font-style[ normal | italic | oblique ]
font-weight[ normal | bold | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900 ]Specifies the font weight used for text, where normal and bold are mapped to the corresponding QFont weights. Numeric values are 8 times the equivalent QFont weight values.
text-decorationnone | [ underline || overline || line-through ]Additional text effects
font[ [ <'font-style'> || <'font-weight'> ]? <'font-size'> <'font-family'> ]Font shorthand property
text-indentpxFirst line text indentation in pixels
white-spacenormal | pre | nowrap | pre-wrapDeclares how whitespace in HTML is handled.
margin-toppxTop paragraph margin in pixels
margin-bottompxBottom paragraph margin in pixels
margin-leftpxLeft paragraph margin in pixels
margin-rightpxRight paragraph margin in pixels
vertical-alignbaseline | sub | superVertical text alignment
background[ <'background-color'> || <'background-image'> ]Background shorthand property
page-break-before[ auto | always ]Make it possible to enforce a page break before the paragraph/table
page-break-after[ auto | always ]Make it possible to enforce a page break after the paragraph/table

Supported CSS Selectors

All CSS 2.1 selector classes are supported except pseudo-class selectors such as :first-child, :visited and :hover.

Friday, May 11, 2007

QTextBrowser

One possible aproach that I can see (but have not tested) is to create
a new class inherrited from QTextBrowser and overload the loadResource function in a way where you check for the names you are interested in and resolve them.

For example like this (again not tested)

Qt Code:
  1. QVariant MyBrowser::loadResource(int type, const QUrl &name)
  2. {
  3. if (type == QTextDocument::ImageResource
  4. && name.scheme() == QLatin1String("mypics")) {
  5. QImage correctImage;
  6. //lookup the correct QImage from a cache
  7. return QVariant::fromValue(correctImage);
  8. } else {
  9. return QTextBrowser::loadResource(type, name);
  10. }
  11. }
Then you should be able to show images when you call
Qt Code:
  1. myTextBrowser.append(QLatin1String("\"mypics://theCurrentPicture.png\" />"));

Disclaimer: Shot from the Hip, not tested...might be completely the wrong track


------------------------------------------------------------------------
from PyQt4 import QtCore,QtGui
import urllib, os, md5

class PBrowser(QtGui.QTextBrowser):
def loadResource(self, type, name):
url=unicode(name.toString())
ret=QtCore.QVariant()
if url.startswith('http://'):
dn=os.path.expanduser('~/.bartleblog/cache/')
if not os.path.isdir(dn):
os.mkdir(dn)
m=md5.new()
m.update(url)
fn=os.path.join(dn,m.hexdigest())
if not os.path.isfile(fn):
urllib.urlretrieve(url, fn)
ret=QtGui.QTextBrowser.loadResource(self, type, QtCore.QUrl(fn))
else:
ret=QtGui.QTextBrowser.loadResource(self, type, name)
return ret