QTableView: Get/Change cursor position

675 views
Skip to first unread message

CarozoDeQuilmes

unread,
Jul 20, 2010, 9:51:51 PM7/20/10
to harbou...@googlegroups.com
Hi Bacco, a little question about sample TestBrow.prg: How get/change current row and/or current column ????

Thanks in advance

--
CdQ

Bacco

unread,
Jul 20, 2010, 10:21:09 PM7/20/10
to harbou...@googlegroups.com
Hi, CdQ

I sent recently an example to the list, entitled "Qt - saving into
dbf" that has a better sample than testbrow. It has edition
capability, and looking into the code, you can see how I get the
current cell with the signal
"currentChanged(QModelIndex,QModelIndex)", as a starting point.

CarozoDeQuilmes

unread,
Jul 21, 2010, 12:21:45 PM7/21/10
to harbou...@googlegroups.com
Hi Bacco, the testedit sample is very good and I have studied it before ask to forum, but I need get (and change) the selected row from a botton or another widget.

e.g: I have added the following slot after button bt1 definition:

QT_SLOTS_CONNECT(qslots,bt1:pPtr,"clicked()",{|| msginfo( myShowRow() )})

and I have added the following functions:

STATIC FUNCTION myShowRow()
   LOCAL i := QModelIndex():from( ????????????? )
RETURN AllTrim( Str( i:row() ) )

STATIC FUNCTION MsgInfo( cMsg )
   LOCAL oMB
   oMB := QMessageBox():new()
   oMB:setInformativeText( cMsg )
   oMB:setWindowTitle( "Harbour-QT" )
   oMB:exec()
   oMB := NIL
   HB_GCALL( .T.)
RETURN nil


but I don't know what put into from() method of QModelIndex

You can help me?

note: If you send also a little sample for Change current row from a buttom, those information will be appreciate

Thanks in advance
CdQ
--
CdQ

Bacco

unread,
Jul 24, 2010, 11:11:50 AM7/24/10
to harbou...@googlegroups.com
Hi, CdQ

I am getting the current row by the selection change events, called by
this line:
QT_SLOTS_CONNECT(qslots,tb1:SelectionModel(),'currentChanged(QModelIndex,QModelIndex)',{|n|my_select(n,
@nCX1, @nCY1 )})
Whenever the selection changes, (even in the first draw of the grid)
the my_select function is called, and the function stores the current
col and row into @nCX and @nCY. I am doing this, because the selection
in Qt allow one to have multiple cells selected, not only rows and
colums, so you can't simple want to use QModelIndex the way you are
trying below:

> STATIC FUNCTION myShowRow()
>    LOCAL i := QModelIndex():from( ????????????? )
> RETURN AllTrim( Str( i:row() ) )

About the sample you asked, using a button to change row is indeed
simple. Change the last two buttons in the sample to this:
( bt2 := QPushButton():new() ):SetText( "Top" )
( bt3 := QPushButton():new() ):SetText( "Bottom" )
And add this below:
QT_SLOTS_CONNECT(qslots,bt2,'clicked()',{||tb1:selectRow( 0 )})
QT_SLOTS_CONNECT(qslots,bt3,'clicked()',{||tb1:selectRow( LastRec()-1 )})

As you want to select the full row, you don't need to use selection
models, the QTableView:selectRow() is enough, as above.


Regards,
Bacco

CarozoDeQuilmes

unread,
Jul 26, 2010, 7:04:30 PM7/26/10
to harbou...@googlegroups.com
Hi Bacco, it works ok

Many thanks
CdQ
--
CdQ
Reply all
Reply to author
Forward
0 new messages