Looking for a Class like QFolderDialog or how i can select folder using QT classes?

228 views
Skip to first unread message

Muhammad Goni

unread,
Jan 13, 2018, 11:25:54 AM1/13/18
to The Ring Programming Language
Hello Group member, i am Looking for a Class like QFolderDialog or how i can select folder using QT classes? And how to get selected path

CalmoSoft

unread,
Jan 13, 2018, 12:30:06 PM1/13/18
to ring...@googlegroups.com
Hello Muhammad,

To select a folder use QFileDialog class.
To get the selected path use the CurrentDir() function.

Code:

see CurrentDir() + nl

Output:

C:\Ring\calmosoft


Greetings,
Gal Zsolt
(~ CalmoSoft ~)

Muhammad Goni

unread,
Jan 13, 2018, 1:36:38 PM1/13/18
to The Ring Programming Language
But the qfiledialog is for files what if the selected item is file?

Mahmoud Fayed

unread,
Jan 13, 2018, 6:43:23 PM1/13/18
to The Ring Programming Language
Hello Muhammad

In the stdlib.ring, You have

(1) JustFilePath()  : http://ring-lang.sourceforge.net/doc1.6/stdlib.html#justfilepath-function
(2) JustFileName() : http://ring-lang.sourceforge.net/doc1.6/stdlib.html#justfilename-function

Using these two functions, You can process the string to get the path or the file name only

Greetings,
Mahmoud

Muhammad Goni

unread,
Jan 13, 2018, 11:59:42 PM1/13/18
to The Ring Programming Language
You didnt understand me, i said i only want to select folder instead of file, for e.g in C# winform we've class for Folder FolderBrowserDialog and for file is FileBrowserDialog
so, in ring qt what is equivalent to folderbrowserdialog?

Mahmoud Fayed

unread,
Jan 14, 2018, 5:17:41 AM1/14/18
to The Ring Programming Language
Hello Muhammad

We have the next method in the QFileDialog class

QString getExistingDirectory(QWidget *,QString,QString, QFileDialog::Option)

Example:

load "guilib.ring"

new qApp {
    w
= new qWidget() {
        oFile
= new qFileDialog(w)
        cFolder
= oFile.getExistingDirectory(w,"Open Directory","c:\",0)
        w.setWindowTitle(cFolder)
        show()
    }
    exec()
}

Greetings,
Mahmoud

Muhammad Goni

unread,
Jan 14, 2018, 7:19:29 PM1/14/18
to The Ring Programming Language
How do i will display context menu or popup when somebody right click on tree node? Then, how to handle right click event

Mahmoud Fayed

unread,
Jan 14, 2018, 7:55:51 PM1/14/18
to ring...@googlegroups.com
Hello Muhammad

Check this sample: https://github.com/ring-lang/ring/blob/master/samples/other/contextmenu.ring

load "guilib.ring"

new qApp {
    win
= new qwidget() {
        setwindowtitle
("Context Menu")
        resize
(400,400)
        myfilter
= new qAllEvents(win) {
            setContextmenuEvent
("mymenu()")
       
}
        installeventfilter
(myfilter)
        show
()
   
}
   
exec()
}


func mymenu

       
new qMenu(win) {
            oAction
= new qAction(win) {
                settext
("new")
               
SetCLickevent("See :New")
           
}
            addaction
(oAction)
            oAction
= new qAction(win) {
                settext
("open")
               
SetCLickevent("See :Open")
           
}
            addaction
(oAction)
            oAction
= new qAction(win) {
                settext
("save")
               
SetCLickevent("See :Save")
           
}
            addaction
(oAction)
            oAction
= new qAction(win) {
                settext
("close")
               
SetCLickevent("See :Close")
           
}
            addaction
(oAction)
            oCursor  
= new qCursor()
           
exec(oCursor.pos())
        }

Greetings,
Mahmoud

Muhammad Goni

unread,
Jan 15, 2018, 6:04:00 AM1/15/18
to The Ring Programming Language
But this code not working
func pTreeKey
if oFilter.getButton() = Qt_RightButton
oItem = tree1.currentindex
msgInfo("Hello","Yes you've right click the tree widget node")

CalmoSoft

unread,
Jan 15, 2018, 7:45:46 AM1/15/18
to The Ring Programming Language
Hello Muhammad,

Please send the full code.

Muhammad Goni

unread,
Jan 15, 2018, 9:37:06 AM1/15/18
to The Ring Programming Language
The code is too long, just let me expalain how to detect if right click button has been clicked? On the qtreewidget?

CalmoSoft

unread,
Jan 16, 2018, 1:30:34 AM1/16/18
to ring...@googlegroups.com
Hello Muhammad,

May the next code help you:

CalmoSoft

unread,
Jan 16, 2018, 6:30:08 AM1/16/18
to The Ring Programming Language
Hello Muhammad et All,

The next code works for both left and right mouseclick.

Code:

# Project : Right click

# Date    : 2018/01/16

# Author : Gal Zsolt (~ CalmoSoft ~)

# Email   : <calm...@gmail.com>


Load "guilib.ring"


click = 1


New qApp {


        win1 = new qWidget() {

               setwindowtitle("TreeWidget")

               setGeometry(100,100,400,400)


                layout1 = new qvboxlayout()


                tree1 = new qtreewidget(win1) {

                       setGeometry(00,00,400,400)

                       setcolumncount(1)

                       myitem = new qtreewidgetitem()

                       myitem.settext(0,"The First Step")

                       addtoplevelitem(myitem)

                       for  x = 1 to 10

                               myitem2 = new qtreewidgetitem()

                               myitem2.settext(0,"hello"+x)

                               myitem.addchild(myitem2)

                               for  y = 1 to 10

                                       myitem3 = new qtreewidgetitem()

                                       myitem3.settext(0,"hello"+x)

                                       myitem2.addchild(myitem3)

                               next

                       next

                       setheaderlabel("Steps Tree")  

                       oFilter = new QAllEvents(win1)

                       click = string(oFilter.getButton())

                       setitemSelectionChangedEvent("pTreeKey()")                      

               }

               layout1.addwidget(tree1)

               setlayout(layout1)

               show()

       }

       exec()

}


func pTreeKey

       click = string(oFilter.getButton())

       see "click = " + click + nl

       msgInfo("Hello","Yes you've right click the tree widget node")

RightClick.ring
Reply all
Reply to author
Forward
0 new messages