rowCount in QListWidget ?

2,169 views
Skip to first unread message

Bert Mariani

unread,
Jun 25, 2016, 4:35:27 PM6/25/16
to The Ring Programming Language
Hello ALL

In the RING Doc Example -- Using the QListWidget Class --

How do you find the number of Rows  in the QListWidget ?
Need number of Rows left after one is deleted.
How is rowCount() used ?

===============================

### Using the QListWidget Class

Load "guilib.ring"

New qApp {

        win1 = new qWidget() {

                setGeometry(100,100,400,400)
 
                list1 = new qlistwidget(win1){
                        setGeometry(150,100,200,200)
                        alist = ["one","two","three","four","five"]
                        for x in alist additem(x) next
                        
                        setcurrentrow(3,2)                                               <<<  points to the currenrRow  
                        win1.setwindowtitle("Items Count : " + count() )
                }

                btn1 = new qpushbutton(win1) {
                        setGeometry(10,200,100,30)
                        settext("selected item")
                        setclickevent("pWork()")
                }

                btn2 = new qpushbutton(win1) {
                        setGeometry(10,240,100,30)
                        settext("Delete item")
                        setclickevent("pWork2()")
                }

                show()
        }

        exec()
}

func pWork

        # In ring_qt.ring
        # Class QTableWidget from QAbstractItemView
        #   Func rowCount 
        #       return QTableWidget_rowCount(pObject)
        
        # nbrOfRows = list1.rowcount()                          <<<  How do I find rowCount in the List
        # See " Nbr of rows: " + nbrOfRows +nl             <<<  Looking for the number of rows in the QListWidget  
        
        btn1.settext(string(list1.currentrow()))

func pWork2
        list1 {
                takeitem(currentrow())
        }

Majdi Sobain

unread,
Jun 25, 2016, 8:30:56 PM6/25/16
to The Ring Programming Language
Hello Bert

You can just change rowcount() with count() so it will be like this :

func pWork


       win1.setwindowtitle("Items Count : " + list1.count() )        #This will print the total number of list items in the window title

       btn1.settext(string(list1.currentrow()))




I hope this could help :)

Greetings
Majdi

CalmoSoft

unread,
Jun 26, 2016, 12:24:28 AM6/26/16
to The Ring Programming Language
Hello Bert,

For the right working please change the line:

btn1.settext(string(list1.currentrow()))


for line:

btn1.settext(string(list1.currentrow()+1))


Greetings,
Gal Zsolt
(~ CalmoSoft ~)

CalmoSoft

unread,
Jun 26, 2016, 2:54:10 AM6/26/16
to ring...@googlegroups.com
Hello Bert,

Maybe I am not right but in the ring_qt.ring the QListWidget class has no rowcount() method.
Please use the count() method.

Bert Mariani

unread,
Jun 26, 2016, 10:00:01 AM6/26/16
to The Ring Programming Language
Thank you Madji and Calmo for your suggestions !!!

Mahmoud
Can you update the example in the RING DOCS.  
     file:///C:/RING/bin/../html/index.html  
     Using the QListWidget Class

===============================

func pWork
        
        nbrOfRows = list1.count()
        See "After Selected - Nbr of rows: " + nbrOfRows +nl
        win1.setwindowtitle("After Selected - Items Count : " + list1.count()
        
        btn1.settext(string(list1.currentrow()))

func pWork2
        list1 {
                takeitem(currentrow())
                
                nbrOfRows = count()
                See "After Delete - Nbr of rows: " + nbrOfRows +nl
                win1.setwindowtitle("After Delete - Items Count : " + count()
        }

See screen capture and attached file.

Greetings
Bert Mariani

AA-ItemList.ring

Bert Mariani

unread,
Jun 26, 2016, 4:14:07 PM6/26/16
to The Ring Programming Language
Hello Mahmoud

Attached is an updated example of  your "Using the QListWidget Class".
See screen capture
It shows how --- count(), currentrow(), and currentrow().text()  can be used

Can it be added in built in RING DOCs  html file

Note:  The first item in the list is returned as Item Nbr -  0 

=========================================

func pWork
                
        nbrOfItems = list1.count()
        curItemNbr = list1.currentrow()
        curValue   = list1.item(list1.currentrow()).text()
        
        See "After Select - NbrOfItems: " + nbrOfItems +" CurItemNbr: " + curItemNbr +" CurValue: " + curValue +nl
                
        win1.setwindowtitle( "After Select - NbrOfItems: " + nbrOfItems +" CurItemNbr: " + curItemNbr +" CurValue: " + curValue )
        
        btn1.settext( string(list1.currentrow() ))
        btn1.settext( string(list1.currentrow() ) +" --- " + list1.item(list1.currentrow()).text() )
 return
        

func pWork2
        list1 {
                takeitem(currentrow())
                
                nbrOfItems = count()
                curItemNbr = currentrow()
                curValue   = item(currentrow()).text()
            
                See "After Delete - NbrOfItems: " + nbrOfItems +" CurItemNbr: " + curItemNbr +" CurValue: " + curValue +nl
                
                win1.setwindowtitle("After Delete - NbrOfItems: " + nbrOfItems +" CurItemNbr: " + curItemNbr +" CurValue: " + curValue )
        }
return      

==================================



==================================


On Saturday, June 25, 2016 at 4:35:27 PM UTC-4, Bert Mariani wrote:
On Saturday, June 25, 2016 at 4:35:27 PM UTC-4, Bert Mariani wrote:
AA-UsingTheQListWidgetClass.ring

Mahmoud Fayed

unread,
Jun 26, 2016, 5:33:42 PM6/26/16
to The Ring Programming Language
Hello Bert

You can update the documentation and it will be in Ring 1.1

Just modify the txt files here 

And send the pull request and i will accept it

Note: fell free to update the documentation, fix any English errors and update the samples.

Greetings,
Mahmoud
Reply all
Reply to author
Forward
0 new messages