[Qt] QT binding anomalies
zeljko
zeljko at holobit.net
Fri Mar 5 09:59:53 CET 2010
On Friday 05 March 2010 09:35, Juha Manninen wrote:
> > Cursor problem wasn't visible to me since my XOrg is 6.8.2 and I have
> > pretty fast machine.
>
> Fast machine didn't help there because the cursor stayed invisible until I
> moved it. Did you finally reproduce it or could you fix it without seeing
> the problem? I am still wondering...
I've fixed it without seeing the problem :)
> > Just try to create pure qt pascal app (without LCL) , using qt45.pas
> > only, so you'll see imediatelly does it flicks or not. Maybe I don't see
> > flickering because my machine is too fast.
>
> Where do I put the QT combobox if there is no LCL form? There must be some
> container, right?
Here is example how to create non LCL app (I don't know if it works, I've used
it to test some things some time ago, probably you have to change hooks
because this is pretty old example).
program testforjuha;
{$mode objfpc}{$H+}
uses
{$IFDEF UNIX}
cthreads,
clocale,
cwstring,
{$ENDIF}
Classes,
SysUtils,
{ you can add units after this }
qt4;
type TApp = class (TObject)
public
qApp: QApplicationH;
qWin: QMainWindowH;
qPro: QProgressBarH;
qEdit: QLineEditH;
qEdit2: QLineEditH;
qCombo: QComboBoxH;
FDropList: QListWidgetH;
qStatus: QStatusBarH;
qLabel1: QLabelH;
qLabel2: QLabelH;
qLabel3: QLabelH;
qPrn: QPrinterH;
FAppEvenFilterHook: QObject_hookH;
FProgresEvenFilterHook: QObject_hookH;
FComboEventFilterHook: QObject_hookH;
FEditEventFilterHook: QObject_hookH;
FSelectHook: QComboBox_hookH;
FSelectionChangeHook: QListWidget_hookH;
FItemPressedHook: QListWidget_hookH;
constructor Create;
destructor Destroy; override;
function EventFilter(Sender: QObjectH; Event: QEventH): Boolean; cdecl;
function ProgresEventFilter(Sender: QObjectH; Event: QEventH): Boolean;
cdecl;
procedure SlotSelect(index: Integer); cdecl;
procedure signalSelectionChanged(); cdecl;
procedure signalItemActivated(Item: QListWidgetItemH); cdecl;
function Execute: Integer;
end;
procedure TApp.SlotSelect(index: Integer); cdecl;
begin
writeln('Slot select from comboBox ....');
end;
procedure TApp.signalSelectionChanged(); cdecl;
var
Item: QListWidgetItemH;
List: QListWidgetH;
i: Integer;
begin
WriteLn('QComboBox ListWidget signalSelectionChange');
List := QListWidgetH(QComboBox_view(qCombo));
Item := QListWidget_currentItem(List);
if Item <> nil then
begin
writeln('ITEM SELECTED ? ',QListWidgetItem_isSelected(Item));
i := QListWidget_row(List, Item);
if QListWidgetItem_isSelected(Item) then
begin
QComboBox_setCurrentIndex(qCombo, i);
end;
writeln('CHANGED ROW=',i);
end;
end;
procedure TApp.signalItemActivated(Item: QListWidgetItemH); cdecl;
var
i: Integer;
List: QListWidgetH;
begin
writeln('QListWidget signalItemActivated() ');
if Item = nil then
begin
writeln('******** ITEM IS NIL *********');
exit;
end;
List := QListWidgetH(QComboBox_view(qCombo));
i := QListWidget_row(List, Item);
writeln('SignalItemActivated i=',i,'
Selected? ',QListWidgetItem_isSelected(Item));
end;
constructor TApp.Create;
var
WStr: WideString;
begin
inherited Create;
qPrn := nil;
qApp := QApplication_create(@argc, argv);
FAppEvenFilterHook := QObject_hook_create(qApp);
QObject_hook_hook_events(FAppEvenFilterHook, @EventFilter);
qWin := QMainWindow_create();
qStatus := QStatusBar_create();
WStr := 'Label 1';
qLabel1 := QLabel_create(@WStr);
WStr := 'Label 2';
qLabel2 := QLabel_create(@WStr);
WStr := 'Label 3';
qLabel3 := QLabel_create(@WStr);
QStatusBar_addWidget(qStatus, qLabel1, 0);
QStatusBar_addWidget(qStatus, qLabel2, 0);
QStatusBar_addWidget(qStatus, qLabel3, 1);
QMainWindow_setStatusBar(qWin, qStatus);
QWidget_resize(qWin, 800, 600);
qPro := QProgressBar_create(qWin);
qEdit := QLineEdit_create(qWin);
qEdit2 := QLineEdit_create(qWin);
qCombo := QComboBox_create(qWin);
// QWidget_setMouseTracking(qCombo, True);
// QWidget_setFocusPolicy(qCombo, QtStrongFocus);
// QWidget_setAttribute(qCombo, QtWA_MacShowFocusRect, True);
// QWidget_setAttribute(qCombo, QtWA_KeyboardFocusChange, True);
FSelectHook := QComboBox_hook_create(qCombo);
QComboBox_hook_hook_currentIndexChanged(FSelectHook, @SlotSelect);
FDropList := QListWidget_create();
QAbstractItemView_setAutoScroll(FDropList, True);
QComboBox_setModel(qCombo, QAbstractItemView_model(FDropList));
QComboBox_setView(qCombo, FDropList);
FSelectionChangeHook := QListWidget_hook_create(FDropList);
QListWidget_hook_hook_itemSelectionChanged(FSelectionChangeHook,
@signalSelectionChanged);
FItemPressedHook := QListWidget_hook_create(FDropList);
QListWidget_hook_hook_itemActivated(FItemPressedHook, @signalItemActivated);
FProgresEvenFilterHook := QObject_hook_create(qPro);
QObject_hook_hook_events(FProgresEvenFilterHook, @ProgresEventFilter);
FComboEventFilterHook := QObject_hook_create(qCombo);
QObject_hook_hook_events(FComboEventFilterHook, @ProgresEventFilter);
FEditEventFilterHook := QObject_hook_create(qEdit2);
QObject_hook_hook_events(FEditEventFilterHook, @ProgresEventFilter);
// QComboBox_setEditable(qCombo, True);
WStr := 'One';
QComboBox_addItem(qCombo, @WStr, QVariant_create());
WStr := 'Two';
QComboBox_addItem(qCombo, @WStr, QVariant_create());
WStr := 'Three';
QComboBox_addItem(qCombo, @WStr, QVariant_create());
WStr := 'Four';
QComboBox_addItem(qCombo, @WStr, QVariant_create());
WStr := 'Five';
QComboBox_addItem(qCombo, @WStr, QVariant_create());
WStr := 'Six';
QComboBox_addItem(qCombo, @WStr, QVariant_create());
WStr := 'Seven';
QComboBox_addItem(qCombo, @WStr, QVariant_create());
WStr := 'Eight';
QComboBox_addItem(qCombo, @WStr, QVariant_create());
WStr := 'Nine';
QComboBox_addItem(qCombo, @WStr, QVariant_create());
WStr := 'Eleven';
QComboBox_addItem(qCombo, @WStr, QVariant_create());
WStr := 'Twelve';
QComboBox_addItem(qCombo, @WStr, QVariant_create());
WStr := 'Thirteen';
QComboBox_addItem(qCombo, @WStr, QVariant_create());
WStr := 'Fourteen';
QComboBox_addItem(qCombo, @WStr, QVariant_create());
WStr := 'Fifteen';
QComboBox_addItem(qCombo, @WStr, QVariant_create());
WStr := 'Sixteen';
QComboBox_addItem(qCombo, @WStr, QVariant_create());
WStr := 'Seventeen';
QComboBox_addItem(qCombo, @WStr, QVariant_create());
WStr := 'Eighteen';
QComboBox_addItem(qCombo, @WStr, QVariant_create());
WStr := 'Nineteen';
QComboBox_addItem(qCombo, @WStr, QVariant_create());
WStr := 'Twenty';
QComboBox_addItem(qCombo, @WStr, QVariant_create());
WStr := 'Twenty one';
QComboBox_addItem(qCombo, @WStr, QVariant_create());
WStr := 'Twenty two';
QComboBox_addItem(qCombo, @WStr, QVariant_create());
// QWidget_setFocusPolicy(qCombo, QtStrongFocus);
// QWidget_setFocusPolicy(qCombo, QtClickFocus);
QWidget_setFocusPolicy(qPro, QtNoFocus);
QWidget_setMouseTracking(qPro, True);
QWidget_resize(qPro, 500, 30);
QWidget_move(qPro, 20, 100);
QProgressBar_setValue(qPro, 40);
QLineEdit_setFrame(qEdit, False);
QLineEdit_setFrame(qEdit2, False);
QWidget_move(qEdit, 20, 160);
QWidget_move(qEdit2, 200, 160);
QWidget_setEnabled(qEdit, False);
//QComboBox_setEditable(qCombo , True);
QWidget_move(qCombo, 320, 160);
QWIdget_show(qWin);
// QWidget_showMaximized(qWin);
end;
destructor TApp.Destroy;
begin
QListWidget_hook_destroy(FItemPressedHook);
QListWidget_hook_destroy(FSelectionChangeHook);
QComboBox_hook_destroy(FSelectHook);
QObject_hook_destroy(FEditEventFilterHook);
QObject_hook_destroy(FComboEventFilterHook);
QObject_hook_destroy(FProgresEvenFilterHook);
if qPrn <> nil then
QPrinter_destroy(qPrn);
inherited Destroy;
end;
function TApp.Execute: Integer;
begin
Result := QApplication_exec();
end;
function TApp.EventFilter(Sender: QObjectH; Event: QEventH): Boolean; cdecl;
begin
Result := False;
QEvent_accept(Event);
(*
case QEvent_type(Event) of
QEventMouseButtonPress: writeln('Mouse press ....');
QEventMouseButtonRelease: writeln('Mouse release ....');
QEventMouseButtonDblClick: writeln('Mouse dbl click ....');
end;
*)
end;
function TApp.ProgresEventFilter(Sender: QObjectH; Event: QEventH): Boolean;
cdecl;
var
Ev: QKeyEventH;
Modifiers: QtKeyboardModifiers;
Text: WideString;
Key: Integer;
NKey: Integer;
KScan: LongWord;
i: Integer;
AKey: Char;
Opt: QStyleOptionComboBoxH;
AState: QStyleState;
WTitle: WideString;
WStr: WideString;
s: String;
begin
Result := False;
QEvent_accept(Event);
case QEvent_type(Event) of
QEventFocusIn:
begin
writeln('COMBO IS FOCUSED !');
end;
QEventMouseButtonPress:
begin
// QWidget_setEnabled(qEdit, true);
// QWidget_update(qEdit);
writeln('Progres Mouse press ....');
end;
QEventMouseButtonRelease: writeln('Progres Mouse release ....');
QEventMouseButtonDblClick: writeln('Progres Mouse dbl click ....');
QEventKeyPress:
begin
Ev := QKeyEventH(Event);
Modifiers := QKeyEvent_modifiers(Ev);
Key := QKeyEvent_key(Ev);
QKeyEvent_text(Ev, @Text);
NKey := QKeyEvent_nativeVirtualKey(Ev);
KScan := QKeyEvent_nativeScanCode(Ev);
end;
QEventKeyRelease:
begin
end;
end;
end;
var
FApp: TApp;
begin
FApp := TApp.Create;
FApp.Execute;
FApp.Free;
end.
More information about the Qt
mailing list