Help about QTreeView

42 views
Skip to first unread message

Giovanni Di Maria

unread,
Jun 4, 2012, 2:45:20 PM6/4/12
to Harbour Developers
Hi
I have create the QTreeView object to get the list of the tree of
directories of Hard Disk.
It works very fine.
But, how can GET the name of directory ON WICH i click? What is the
property that contains the string of ITEM clicked?
Thank you
Giovanni
Please don't give me the link of QT classes, i have read them :-))

Here is my code.


#include "hbqtgui.ch"
STATIC oWnd,oModello,oAlbero,oText
PROCEDURE main()
LOCAL oButton1

oWnd:=QMainWindow()
oWnd:resize(800,600)

oModello:=QFileSystemModel()
oModello:setRootPath("")

oAlbero:=QTreeView(oWnd)
oAlbero:resize(780,400)
oAlbero:move(10,10)
oAlbero:setIndentation(20)
oAlbero:setModel(oModello)
oAlbero:setSortingEnabled(.T.)
oAlbero:sortByColumn(0,0)
oAlbero:setColumnWidth(0,300)
oAlbero:setColumnWidth(1,100)
oAlbero:setColumnWidth(2,100)
oAlbero:setColumnWidth(3,100)

oButton1:=QPushButton(oWnd)
oButton1:setText("Inizia Conteggio")
oButton1:move(10,420)
oButton1:resize(150,30)
oButton1:Connect("clicked()",{ || inizio() } )

oText:=Qlabel(oWnd)
oText:setStyleSheet("background-color: yellow; color: red;" )
oText:setText("Hello World")
oText:move(170,420)
oText:resize(620,30)

oWnd:show()

QApplication():exec()
RETURN


PROCEDURE inizio()
oText:setText( "ciao" )
RETURN

Bacco

unread,
Jun 4, 2012, 3:26:01 PM6/4/12
to harbou...@googlegroups.com
Hi, Giovanni

oAlbero:connect( "activated(QModelIndex)", {|i| oText:setText(
oModello:filePath( i ) ) } )

This changes the textbox with the path when you press enter or double
click with the mouse. If you want to detect change items just walking
with up and down keys, it will require some kludge, as currently we
can't override the selectionChange method (don't know if there's such
a thing done in HBQt currently).

By the way, I suggest you to learn to use layouts, because your
hard-coded measures can cause problem depending on the visual
preferences of the machine running your software.

Regards
Bacco

Giovanni Di Maria

unread,
Jun 4, 2012, 4:04:39 PM6/4/12
to Harbour Developers
Ciao Bacco
thank you.
Your suggest VERY FINE!!!!

I have replace your:
oAlbero:connect( "activated(QModelIndex)", {|i|
oText:setText(oModello:filePath( i ) ) } )

with my:
oAlbero:connect( "clicked(QModelIndex)", {|i|
oText:setText(oModello:filePath( i ) ) } )

to detect a single click.

THANK YOU !!!!!

Bacco

unread,
Jun 4, 2012, 4:13:48 PM6/4/12
to harbou...@googlegroups.com
Remember that one can't use the keyboard to select the way you did.
I suggest you use both signals then.

Bacco

unread,
Jun 4, 2012, 4:15:31 PM6/4/12
to harbou...@googlegroups.com
...
oText:move(170,420)
oText:resize(620,30)

oAlbero:connect( "activated(QModelIndex)", {|i| oText:setText(
oModello:filePath( i ) ) } )
oAlbero:connect( "clicked(QModelIndex)", {|i| oText:setText(
oModello:filePath( i ) ) } )

oWnd:show()
...

So one can click to select, or use KB arrows and enter/return key too.

Bacco

unread,
Jun 4, 2012, 8:44:09 PM6/4/12
to harbou...@googlegroups.com
Hi, Giovanni.

Please take a look in the sample below.
It needs the current SVN, as Pritpal uncommented the function used.

#include "hbqtgui.ch"

PROCEDURE main()
oWnd:=QMainWindow()

cTitle := "Open the magic file"
cPath := "."
cFilter := "Image files (*.png *.jpg *.bmp);;Source files (*.prg
*.ch);;All files (*.*)"

cFile := QFileDialog():getOpenFileName( oWnd, cTitle, cPath, cFilter )
Reply all
Reply to author
Forward
0 new messages