Methods of QTableWidget class

965 views
Skip to first unread message

Marino Esteban Liranzo Cruz

unread,
Aug 25, 2016, 6:09:01 PM8/25/16
to The Ring Programming Language
Hello Mahmoud Fayed
It's great what you has accomplished to do with programming language, making with few lines of code will do great things.

You could tell me some methods to manage QTableWidget class, the most important:

1- Methods to move the focus from the left to the right cell after the Enter event and change lines after the last column.

2- method to add Combobox and other elements to the cells of a QTableWidget.

Besides the main methods to work with this important class.

regards
Marino Liranzo
Message has been deleted

CalmoSoft

unread,
Aug 26, 2016, 12:04:46 PM8/26/16
to ring...@googlegroups.com
Hello Marino,

For the method to add Combobox and other elements to the cells of a QTableWidget see the next code:

Load "guilib.ring"


New qApp {

                win1 = new qMainWindow() {

                setGeometry(100,100,1100,370)

                setwindowtitle("Using QTableWidget")


                Table1 = new qTableWidget(win1) {

                             setrowcount(10) setcolumncount(10)

                             setGeometry(0,0,800,400)

                             setselectionbehavior(QAbstractItemView_SelectRows)


                  for x = 1 to 10

                       for y = 1 to 10

                            item1 = new qtablewidgetitem("R"+X+"C"+Y)

                            setitem(x-1,y-1, item1)

                       next

                  next


                  cmb = new QComboBox(Table1) {

                            alist = ["one","two","three","four","five"]

                            for x in aList additem(x,0) next                            }


                  setCellWidget(5, 5, cmb)

                  }

                  setcentralwidget(table1)

                  show()

       }

       exec()

}



Output:



Greetings,
Gal Zsolt
(~ CalmoSoft ~)
CalmoSoft.ring

Bert Mariani

unread,
Aug 26, 2016, 2:23:32 PM8/26/16
to The Ring Programming Language
Hello Gal, Marino

Thanks for you example Gal !

I was able to slightly modify your code.
The Arrow Keys will move around the Table
Data can be entered in the Cells selected - See output capture image

However hitting the Enter Key does not move to the next Cell (vertical or horizontal)

============
INPUT

Load "guilib.ring"


New qApp
{

    win1 = new qMainWindow()
    {
        setGeometry(100,100,1100,370)
        setwindowtitle("Using QTableWidget")

        Table1 = new qTableWidget(win1)
        {
            setrowcount(10) setcolumncount(10)
            setGeometry(0,0,800,400)

            # QAbstractItemView_SelectItems = 0
            # QAbstractItemView_SelectRows = 1
            # QAbstractItemView_SelectColumns = 2

            # setselectionbehavior(QAbstractItemView_SelectRows)   ### commented out
            setSelectionMode(QAbstractItemView_SelectItems)          ### replaced with this line

            for x = 1 to 10
                for y = 1 to 10
                    item1 = new qtablewidgetitem("R"+X+"C"+Y)
                    setitem(x-1,y-1, item1)
                next
            next

            cmb = new QComboBox(Table1)
            {
                alist = ["one","two","three","four","five"]
                for x in aList
                    additem(x,0)
                next
            }

            setCellWidget(5, 5, cmb)

        }

        setcentralwidget(table1)
          show()
    }

    exec()

}

============
OUTPUT



============
AA-Widgets-2.ring
QWidget-1.jpg

CalmoSoft

unread,
Aug 26, 2016, 2:33:48 PM8/26/16
to The Ring Programming Language
Hello Bert,

Thank you very much for your reply and modification of the code.

Marino Esteban Liranzo Cruz

unread,
Aug 26, 2016, 7:47:39 PM8/26/16
to The Ring Programming Language
Hi Gal, Belt
The code that you put at my disposal is very interesting and very helpful, I would like when I press the Enter key focus is changed, moving to the cell on the right.

Again I reiterate my appreciation for the light you shed novice programmers in the language Ring.

Greetings
Marino Liranzo

On Thursday, August 25, 2016 at 2:09:01 PM UTC-4, Marino Esteban Liranzo Cruz wrote:

Mahmoud Fayed

unread,
Aug 27, 2016, 12:49:56 AM8/27/16
to ring...@googlegroups.com
Hello Marino

The next code is just an update to the sample created by Gal and Bert (Thanks to them)
The update will enable the user to move to the next cell when he/she press ENTER
If it's the last column - the move will be to the first cell in the next row

Load "guilib.ring"


New qApp

{

    win1 = new qMainWindow()

    {

        setGeometry(100,100,1100,370)

        setwindowtitle("Using QTableWidget")

        Table1 = new qTableWidget(win1)

        {

            setrowcount(10) setcolumncount(10)

            setGeometry(0,0,800,400)

            setSelectionMode(QAbstractItemView_SelectItems)  

            for x = 1 to 10

                for y = 1 to 10

                    item1 = new qtablewidgetitem("R"+X+"C"+Y)

                    setitem(x-1,y-1, item1)

                next

            next

           cmb = new QComboBox(Table1)

            {

                alist = ["one","two","three","four","five"]

                for x in aList

                    additem(x,0)

                next

            }

           setCellWidget(5, 5, cmb)

       }

        setcentralwidget(table1)

        myfilter = new qallevents(win1)

        myfilter.setKeyPressEvent("pKeyPress()")

        installeventfilter(myfilter)

        show()

   }

   exec()

}


func pKeyPress

        nKeyCode = myfilter.getkeycode()

        #see "keycode " + nKeyCode +  nl

        if nKeyCode = 16777220

                Table1 {

                        if currentcolumn() = ColumnCount()-1

                                setcurrentcell(currentrow()+1,  0)

                        else

                                setcurrentcell( currentrow() , currentcolumn() + 1)

                        ok      

                }

        ok


Greetings,
Mahmoud

CalmoSoft

unread,
Aug 27, 2016, 9:39:52 AM8/27/16
to ring...@googlegroups.com
Hello Bert, Marino, Mahmoud,

I have changed the code a little.
When you click "Enter" in the last cell the focus jumps to the first cell:

                    if currentrow() = rowcount()-1 and currentcolumn() = columncount()-1

                       setcurrentcell(0, 0) 

                    else

                       if currentcolumn() = columncount()-1

                          setcurrentcell(currentrow()+1,  0)

                       else

                         setcurrentcell( currentrow() , currentcolumn() + 1)

                    ok ok    

                    }

       ok

CalmoSoft.ring

Marino Esteban Liranzo Cruz

unread,
Aug 27, 2016, 8:57:18 PM8/27/16
to The Ring Programming Language
Hello Mahmoud,  Bert and Gal

Nice code. Thanks You.

Greetings
Marino Liranzo 

On Thursday, August 25, 2016 at 2:09:01 PM UTC-4, Marino Esteban Liranzo Cruz wrote:

Mahmoud Fayed

unread,
Aug 27, 2016, 10:19:28 PM8/27/16
to The Ring Programming Language
Hello Marino

You are welcome :D

Greetings,
Mahmoud

Marino Esteban Liranzo Cruz

unread,
Aug 28, 2016, 2:13:35 AM8/28/16
to The Ring Programming Language


On Thursday, August 25, 2016 at 2:09:01 PM UTC-4, Marino Esteban Liranzo Cruz wrote:

Marino Esteban Liranzo Cruz

unread,
Aug 28, 2016, 2:19:32 AM8/28/16
to The Ring Programming Language


Hello Mahmoud
I tried the code you sent me recently, when the cells are not editing works perfectly; but when I add values in cells and pressed the Enter key does not work, only when I press the Enter key the second time the focus moves to the next cell.

Greetings
Marino Liranzo

CalmoSoft

unread,
Aug 28, 2016, 4:46:35 AM8/28/16
to The Ring Programming Language
Hello Marino,

I think this is a normal behavior.

CalmoSoft

unread,
Aug 28, 2016, 7:01:26 AM8/28/16
to ring...@googlegroups.com
Hello Bert, Marino, Mahmoud,

I need your help.
See the next code.
I have the "First cell" button to jump focus to the first cell
and the "Last cell" button to jump to the last cell.
Do you know what do I wrong?
Thank you very much.

Load "guilib.ring"


New qApp
             {
              win1 = new qMainWindow()
             {
              setGeometry(100,100,1100,370)    
              setwindowtitle("Using QTableWidget")
              Table1 = new qTableWidget(win1)
              {
              setrowcount(10) setcolumncount(10)
              setGeometry(0,0,800,400)
              setSelectionMode(QAbstractItemView_SelectItems)  

              for x = 1 to 10
                   for y = 1 to 10
                        item1 = new qtablewidgetitem("R"+X+"C"+Y)
                        setitem(x-1,y-1, item1)
                   next
              next

              cmb = new QComboBox(Table1)
             {
                         alist = ["one","two","three","four","five"]
                         for x in aList
                              additem(x, 0)
                         next 
              }

              btn1 = new QPushButton(win1){
                         settext("First cell")
                         setClickEvent("pFirst()")
              } 

              btn2 = new QPushButton(win1){
                         settext("Last cell")
                         setClickEvent("pLast()")
              } 

              setCellWidget(5, 5, cmb)
              setCellWidget(5, 6, btn1)
              setCellWidget(5, 7, btn2)

              }

              setcentralwidget(table1)
              myfilter = new qallevents(win1)
              myfilter.setKeyPressEvent("pKeyPress()")
              installeventfilter(myfilter)
              show()
   }
   exec()
}

func pKeyPress
       nKeyCode = myfilter.getkeycode()
       if nKeyCode = 16777220
         Table1 { 
                    if currentrow() = rowcount()-1 and currentcolumn() = columncount()-1
                       setcurrentcell(0, 0) 
                    else
                       if currentcolumn() = columncount()-1
                          setcurrentcell(currentrow()+1,  0)
                       else
                         setcurrentcell( currentrow() , currentcolumn() + 1)
                    ok ok    
                    }
       ok

func pFirst
       Table1.setcurrentcell(0, 0)
       see Table1.currentrow() + nl
       see Table1.currentcolumn() + nl + nl

func pLast
       Table1.setcurrentcell(Table1.rowcount()-1, Table1.columncount()-1)
       see Table1.currentrow() + nl
       see Table1.currentcolumn() + nl + nl


Greetings,
CalmoSoft.ring

CalmoSoft

unread,
Aug 28, 2016, 5:48:22 PM8/28/16
to ring...@googlegroups.com
Hello Bert, Marino, Mahmoud,

I have solved my problem using setfocus() method.

Code:

     Table1.setfocus(1)
     Table1.setcurrentcell(0, 0)

func pLast
     Table1.setfocus(100)
     Table1.setcurrentcell(Table1.rowcount()-1, Table1.columncount()-1)

Output:

CalmoSoft.ring

Mahmoud Fayed

unread,
Aug 28, 2016, 7:13:20 PM8/28/16
to The Ring Programming Language
Hello Gal

Keep up the good work :D

Greetings,
Mahmoud

CalmoSoft

unread,
Aug 29, 2016, 5:57:27 AM8/29/16
to The Ring Programming Language
Hello Mahmoud,

Thank you very much for your kind words,

CalmoSoft

unread,
Aug 29, 2016, 8:04:10 AM8/29/16
to ring...@googlegroups.com
Hello Bert, Marino, Mahmoud,

I added the "Go to Cell" button.

Code:

              btn3 = new QPushButton(win1){
                     settext("Go to Cell")
                     setClickEvent("pEdit()")
              }

              lineedit1 = new qlineedit(win1) {
                          settext("Go to Row")
                                      setalignment(Qt_AlignHCenter)
              } 
 
              lineedit2 = new qlineedit(win1) {
                          settext("Go to Column")
                                      setalignment(Qt_AlignHCenter)
              } 

              setCellWidget(5, 5, cmb)
              setCellWidget(5, 6, btn1)
              setCellWidget(5, 7, btn2)
              setCellWidget(6, 5, lineedit1)
              setCellWidget(6, 6, lineedit2)
              setCellWidget(6, 7, btn3)
     Table1.setcurrentcell(Table1.rowcount()-1, Table1.columncount()-1)

func pEdit
     lineedit1{row = text()}
     lineedit2{column = text()}
     Table1.setfocus(1)
     Table1.setcurrentcell(row-1, column-1)


Output:

CalmoSoft.ring

Bert Mariani

unread,
Aug 30, 2016, 2:12:30 PM8/30/16
to The Ring Programming Language
Hi Gal, Mahmoud, Marini

Very nice updates to the qTableWidget , Gal !!!

1.
I noticed one thing in the behaviour with the  "Table1.setfocus(z)".
SetFocus() can have any value (z) , and the focus will just go to the cell (x,y)  pointed to by  "Table1.setcurrentcell(x,y)

2.
In Excel:  When data is entered in a Cell,  the Enter Key is pressed "once",  the focus then goes to the Cell in the Next Row, Current Column.
Is there a way to make qTableWidget behave the same way ?

----------------------

Example: Using these values made no difference in the behaviour of the setfocus () code.

func pFirst
       Table1.setfocus(3)               ### <<< Can use any number
       Table1.setcurrentcell(0, 0)   ### <<< Goes to this Cell

func pLast
       Table1.setfocus(3)
       Table1.setcurrentcell(Table1.rowcount()-1, Table1.columncount()-1)

func pEdit
       lineedit1{row = text()}
       lineedit2{column = text()}
       Table1.setfocus(3)
       Table1.setcurrentcell(row-1, column-1)


Greeting
Bert Mariani

On Thursday, August 25, 2016 at 2:09:01 PM UTC-4, Marino Esteban Liranzo Cruz wrote:

CalmoSoft

unread,
Aug 30, 2016, 2:25:43 PM8/30/16
to ring...@googlegroups.com
Hello Bert,

Thank you very much for your reply and suggestions.
I also observed the behaviour with the "Table1.setfocus(z)". 
Message has been deleted

CalmoSoft

unread,
Aug 31, 2016, 1:25:26 PM8/31/16
to ring...@googlegroups.com
Hello Bert, Marino, Mahmoud,

"Is there a way to make qTableWidget behave the same way like in Excel?"
I have solved this problem.
I added the next line:

setitemChangedEvent("pPress()")

Code:

Load "guilib.ring"

New qApp
       {
       win1 = new qMainWindow()
              {
              setGeometry(100,100,1100,370)    
              setwindowtitle("Using QTableWidget")
              Table1 = new qTableWidget(win1)
              {
              setrowcount(10) setcolumncount(10)
              setGeometry(0,0,800,400)
              setSelectionMode(QAbstractItemView_SelectItems)
                  setitemChangedEvent("pPress()") 
- Idézett szöveg elrejtése -

              }

              setcentralwidget(table1)
              myfilter = new qallevents(win1)
              myfilter.setKeyPressEvent("pKeyPress()")
              installeventfilter(myfilter)
              show()
   }
   exec()
}

func pKeyPress
     nKeyCode = myfilter.getkeycode()
     if nKeyCode = 16777220
        Table1 { 
               if currentrow() = rowcount()-1 and currentcolumn() = columncount()-1
                  setcurrentcell(0, 0) 
               else
                  if currentcolumn() = columncount()-1
                     setcurrentcell(currentrow()+1,  0)
                  else
                     setcurrentcell( currentrow() , currentcolumn() + 1)
               ok ok    
               }
        ok

func pFirst
     Table1.setfocus(1)
     Table1.setcurrentcell(0, 0)

func pLast
     Table1.setfocus(100)
     Table1.setcurrentcell(Table1.rowcount()-1, Table1.columncount()-1)

func pEdit
     lineedit1{row = text()}
     lineedit2{column = text()}
     Table1.setfocus(1)
     Table1.setcurrentcell(row-1, column-1)

func pPress

       Table1 {

                 if currentrow() = rowcount()-1 and currentcolumn() = columncount()-1

                    setcurrentcell(0, 0)

                 but currentrow() = rowcount()-1 

                    setcurrentcell( 0 , currentcolumn() + 1)

                 else

                    setcurrentcell( currentrow()+1 , currentcolumn()) ok

                 }


Greetings,
CalmoSoft.ring

Bert Mariani

unread,
Aug 31, 2016, 7:54:50 PM8/31/16
to The Ring Programming Language
Hello Gal 
Great Work !!!

It works like Excel.
It looks like    setreturnPressedEvent("pPress()")    make the piece of code below redundant

Can you look at this link. The code is in qTCL. 
I don't know how to port it, or simulate it in RING Lang.

I commented out this piece and it still Works !

/*
              setcentralwidget(table1)
              myfilter = new qallevents(win1)
              myfilter.setKeyPressEvent("pKeyPress()")            
              installeventfilter(myfilter)
 */

/*
func pKeyPress 
       nKeyCode = myfilter.getkeycode()
       if nKeyCode = 16777220
         Table1 { 
                    if currentrow() = rowcount()-1 and currentcolumn() = columncount()-1
                       setcurrentcell(0, 0) 
                    else
                       if currentcolumn() = columncount()-1
                          setcurrentcell(currentrow()+1,  0)
                       else
                         setcurrentcell( currentrow() , currentcolumn() + 1)
                         //setcurrentcell( currentrow()+1 , currentcolumn())
                    ok ok    
                    }
         ok
*/


Greetings
Bert Mariani

On Thursday, August 25, 2016 at 2:09:01 PM UTC-4, Marino Esteban Liranzo Cruz wrote:

CalmoSoft

unread,
Aug 31, 2016, 9:10:04 PM8/31/16
to ring...@googlegroups.com
Hello Bert,

Thank you very much for your kind words and suggestions.
As you suggested I deleted the next line:

setreturnPressedEvent("pPress()")

Greetings,

Marino Esteban Liranzo Cruz

unread,
Sep 1, 2016, 3:18:43 AM9/1/16
to The Ring Programming Language
Hi Gal,Bert, Mahmoud
Thank you for your assistance and for their wise advice and suggestions

I tried to set the column width and row height of a QtableWidget. I tried with Table1.setColumnWidth (i, 50), where i is the number of columns, Table1.setRowHeight (j, 20).
In both cases I do not get results.

Thankful in advance.

Greetings,
Marino Liranzo

On Thursday, August 25, 2016 at 2:09:01 PM UTC-4, Marino Esteban Liranzo Cruz wrote:

CalmoSoft

unread,
Sep 1, 2016, 7:03:46 AM9/1/16
to ring...@googlegroups.com
Hello Marino,

QTableWidget class has no setColumnWidth(int, int) and setRowHeight(int, int) methods.
For setColumnWidth(int, int) and setRowHeight(int, int) methods see the next QT-link:

CalmoSoft

unread,
Sep 1, 2016, 8:25:50 AM9/1/16
to ring...@googlegroups.com
Hello Bert,

The piece of the code you commented out moves the focus from the left to the right cell after the Enter event (without editing cell) and change lines after the last column.

Bert Mariani

unread,
Sep 1, 2016, 2:20:07 PM9/1/16
to The Ring Programming Language
Hello Gal

I retested it, with commented out code. See attachment
The row moves down when the value is typed in and the Enter Key pressed
Kept this code.

     setSelectionMode(QAbstractItemView_SelectItems)  ### <<< NEED
     setitemChangedEvent("pPress()")                  ### <<< NEED --> Func

Screen capture shown

AA-Widget-Table-7-CS.ring

Bert Mariani

unread,
Sep 1, 2016, 2:32:18 PM9/1/16
to The Ring Programming Language
Hello Marino et ALL

Look in this Ring file

Ring\bin\ring_qt.ring
        It has all the QT definitions implemented by RING

Line 3622 starts definitions for:
        Class QTableWidget from QAbstractItemView

CalmoSoft

unread,
Sep 1, 2016, 2:35:15 PM9/1/16
to The Ring Programming Language
Hello Bert,

Thank you very much for your reply and suggestions.
You are right but Marino write the next in the first reply of this topic:


"1- Methods to move the focus from the left to the right cell after the Enter event and change lines after the last column."


Greeting,

CalmoSoft

unread,
Sep 1, 2016, 2:43:49 PM9/1/16
to ring...@googlegroups.com
Hello Bert,

I have updated the code as you suggested:

              setcentralwidget(table1)
              show()
   }
   exec()
}

func pFirst
       Table1.setfocus(true)
       Table1.setcurrentcell(0, 0)

func pLast
       Table1.setfocus(true)
       Table1.setcurrentcell(Table1.rowcount()-1, Table1.columncount()-1)

func pEdit
       lineedit1{row = text()}
       lineedit2{column = text()}
       Table1.setfocus(true)
       Table1.setcurrentcell(row-1, column-1)

func pPress 
       Table1 {
                  if currentrow() = rowcount()-1 and currentcolumn() = columncount()-1
                     setcurrentcell(0, 0)
                  but currentrow() = rowcount()-1 
                     setcurrentcell( 0 , currentcolumn() + 1)
                  else
                     setcurrentcell( currentrow()+1 , currentcolumn()) ok
                  }     


Greetings,
CalmoSoft.ring

Bert Mariani

unread,
Sep 1, 2016, 3:59:15 PM9/1/16
to The Ring Programming Language
Hello Gal, Marino

Marino wrote
"1- Methods to move the focus from the left to the right cell after the Enter event and change lines after the last column."

Excel behaviour
 - Moves to next row down after the Enter Key is hit.

I think the Excel behaviour is the proper one to use.



On Thursday, August 25, 2016 at 2:09:01 PM UTC-4, Marino Esteban Liranzo Cruz wrote:
Hello Mahmoud Fayed
It's great what you has accomplished to do with programming language, making with few lines of code will do great things.

You could tell me some methods to manage QTableWidget class, the most important:

1- Methods to move the focus from the left to the right cell after the Enter event and change lines after the last column.

CalmoSoft

unread,
Sep 1, 2016, 4:50:21 PM9/1/16
to The Ring Programming Language
Hello Bert,

Excue me. You are right.

Mahmoud Fayed

unread,
Sep 1, 2016, 6:52:04 PM9/1/16
to The Ring Programming Language
Hello Gal, Bert and Marino

It's the user choice to select the order of entering data 

When i enter large set of numbers i prefer moving from row to the next 
While when i enter textual data (many records) i prefer to move from column to the next.

Also i prefer keeping the database in a good state

When i develop an application for students and marks 
I may have the subject marks for all students - but not all other subjects
This way i will enter the data of one column for all records 

But in other applications that i have the complete record data
I prefer to enter a complete record (all columns) each time.

This is based on the opinions collected from some of my users in 2007 and 2009 in two different applications.

Greetings,
Mahmoud

CalmoSoft

unread,
Sep 3, 2016, 1:48:34 PM9/3/16
to ring...@googlegroups.com
Hello Bert, Marino, Mahmoud,

Now the next code works like Excel:

                          setreturnPressedEvent("pPress()")
              } 

              lineedit2 = new qlineedit(win1) {
                          settext("Go to Column")
                          setalignment(Qt_AlignHCenter)
              } 

              setCellWidget(5, 5, cmb)
              setCellWidget(5, 6, btn1)
              setCellWidget(5, 7, btn2)
              setCellWidget(6, 5, lineedit1)
              setCellWidget(6, 6, lineedit2)
              setCellWidget(6, 7, btn3)
              }

              setcentralwidget(table1)
              myfilter = new qallevents(win1)
              myfilter.setKeyPressEvent("pKeyPress()")            
              installeventfilter(myfilter)
              show()
   }
   exec()
}

func pKeyPress 
     nKeyCode = myfilter.getkeycode()
     if nKeyCode = 16777220
        Table1 { 
               if currentrow() = rowcount()-1 and currentcolumn() = columncount()-1
                  setcurrentcell(0, 0) 
               else
                  if currentrow() = rowcount()-1
                     setcurrentcell(0, currentcolumn()+1)
                  else
                     setcurrentcell( currentrow()+1 , currentcolumn())
               ok ok    
               }
        ok

func pFirst
     Table1.setfocus(true)
     Table1.setcurrentcell(0, 0)

func pLast
     Table1.setfocus(true)
     Table1.setcurrentcell(Table1.rowcount()-1, Table1.columncount()-1)

func pEdit
     lineedit1{row = text()}
     lineedit2{column = text()}
     Table1.setfocus(true)
     Table1.setcurrentcell(row-1, column-1)

func pPress 
     Table1 {
            if currentrow() = rowcount()-1 and currentcolumn() = columncount()-1
               setcurrentcell(0, 0)
            but currentrow() = rowcount()-1 
                setcurrentcell( 0 , currentcolumn() + 1)
            else
                setcurrentcell( currentrow()+1 , currentcolumn()) ok
            }
         

Marino Esteban Liranzo Cruz

unread,
Sep 3, 2016, 9:02:04 PM9/3/16
to The Ring Programming Language
Hell Gal, Bert, Mahmoud and all

It's great the final solution of this code, many improvements were raised and all became improvements to the code. THANK YOU.

I would like to set the column width and row height; but I have made several attempts, I read the tutorial and documentation suggested Qt without results.

Please give me help.

Greetings
Marino Liranzo

Mahmoud Fayed

unread,
Sep 3, 2016, 10:56:37 PM9/3/16
to ring...@googlegroups.com
Hello Marino

To do this we need to use the SetColumnWidth() method
The QTableWidget Class get this method from QTableView class (through inheritance)

RingQt miss the QTableView class, so i have already added it in this commit

You can build Ring from the source code, or just download the next binary update

Extract the files to the ring\bin folder and accept replacement

Then you can run the next example 

Load "guilib.ring"

New qApp {

        win1 = new qMainWindow() {

                setGeometry(100,100,1100,370)
                setwindowtitle("Using QTableWidget")

                Table1 = new qTableWidget(win1) {

                        setrowcount(10) setcolumncount(5)
                        setGeometry(0,0,800,400)
                        setselectionbehavior(QAbstractItemView_SelectRows)

                        for x = 1 to 10
                                for y = 1 to 5
                                        item1 = new qtablewidgetitem("R"+X+"C"+Y)
                                        setitem(x-1,y-1,item1)
                                next
                        next

SetColumnWidth(0,200)
SetColumnWidth(1,50)
SetColumnWidth(2,50)
SetColumnWidth(3,100)
SetColumnWidth(4,100)
                }

                setcentralwidget(table1)
                show()

        }

        exec()
}

Greetings,
Mahmoud

Marino Esteban Liranzo Cruz

unread,
Sep 4, 2016, 12:14:30 AM9/4/16
to The Ring Programming Language
Hello Mr. Mahmoud Fayed,

Thank you for help. The method work fine.

Mahmoud Fayed

unread,
Sep 4, 2016, 1:52:32 AM9/4/16
to The Ring Programming Language
Hello Marino

Thanks for your kind words, You are welcome :D

Greetings,
Mahmoud

Bert Mariani

unread,
Sep 4, 2016, 3:31:57 AM9/4/16
to The Ring Programming Language
Hello Mahmound

Thank you for importing more QT functionality.
     "...RingQt miss the QTableView class ..."

Is it possible to also import -- setHorizontalHeaderLabels
As shown in the example frm this link


QTableWidget Class

voidsetHorizontalHeaderItem(int column, QTableWidgetItem *item)
voidsetHorizontalHeaderLabels(const QStringList &labels)

Greetings
Bert Mariani

CalmoSoft

unread,
Sep 4, 2016, 7:46:22 AM9/4/16
to ring...@googlegroups.com
Hello Bert, Marino, Mahmoud,

I have added the "Set row height" and "Set column widht" buttons to the code:

Load "guilib.ring"


New qApp
       {
       win1 = new qMainWindow()
       {
       setGeometry(100,100,1100,370)    
       setwindowtitle("Using QTableWidget")
       Table1 = new qTableWidget(win1)
       {
       setrowcount(10) setcolumncount(10)
       setGeometry(0,0,800,400)
       setSelectionMode(QAbstractItemView_SelectItems)  
       setitemChangedEvent("pPress()")

       for x = 1 to 10
           for y = 1 to 10
               item1 = new qtablewidgetitem("R"+X+"C"+Y)
               setitem(x-1,y-1, item1)
           next
       next

       cmb = new QComboBox(Table1)
       {
             alist = ["one","two","three","four","five"]
             for x in aList
                 additem(x, 0)
             next 
       }

       btn1 = new QPushButton(win1){
                  settext("First cell")
                  setClickEvent("pFirst()")
       } 

       btn2 = new QPushButton(win1){
                  settext("Last cell")
                  setClickEvent("pLast()")
       }

       btn3 = new QPushButton(win1){
              settext("Go to Cell")
              setClickEvent("pEdit()")
       }

       btn4 = new QPushButton(win1){
              settext("Set row height")
              setClickEvent("setHeight()")
       }

       btn5 = new QPushButton(win1){
              settext("Set column width")
              setClickEvent("setWidth()")
       }

       lineedit1 = new qlineedit(win1) {
                   settext("Go to Row")
                   setalignment(Qt_AlignHCenter)
                   setreturnPressedEvent("pPress()")
       } 

       lineedit2 = new qlineedit(win1) {
                   settext("Go to Column")
                   setalignment(Qt_AlignHCenter)
       }

       lineedit3 = new qlineedit(win1) {
                   settext("Set row")
                   setalignment(Qt_AlignHCenter)
       } 

       lineedit4 = new qlineedit(win1) {
                   settext("Row height")
                   setalignment(Qt_AlignHCenter)
       } 

       lineedit5 = new qlineedit(win1) {
                   settext("Set column")
                   setalignment(Qt_AlignHCenter)
       } 

       lineedit6 = new qlineedit(win1) {
                   settext("Row width")
                   setalignment(Qt_AlignHCenter)
       } 

       setCellWidget(3, 5, cmb)
       setCellWidget(3, 6, btn1)
       setCellWidget(3, 7, btn2)
       setCellWidget(4, 5, lineedit1)
       setCellWidget(4, 6, lineedit2)
       setCellWidget(4, 7, btn3)
       setCellWidget(5, 5, lineedit3)
       setCellWidget(5, 6, lineedit4)
       setCellWidget(6, 5, lineedit5)
       setCellWidget(6, 6, lineedit6)
       setCellWidget(5, 7, btn4)
       setCellWidget(6, 7, btn5)
func setHeight
     Table1 {
            lineedit3 {setRow = number(text())}
            lineedit4 {setHeight = number(text())}
            setRowHeight(setRow, setHeight)
            }    

func setWidth
     Table1 {
            lineedit5 {setColumn = number(text())}
            lineedit6 {setWidth = number(text())}
            setColumnWidth(setColumn, setWidth)
            }

Greetings,
CalmoSoft.ring

Mahmoud Fayed

unread,
Sep 4, 2016, 9:00:09 PM9/4/16
to The Ring Programming Language
Load "guilib.ring"

New qApp {

        win1 = new qMainWindow() {

                setGeometry(100,100,1100,370)
                setwindowtitle("Using QTableWidget")

                Table1 = new qTableWidget(win1) {

                        setrowcount(10) setcolumncount(5)
                        setGeometry(0,0,800,400)
                        setselectionbehavior(QAbstractItemView_SelectRows)

                        for x = 1 to 10
                                for y = 1 to 5
                                        item1 = new qtablewidgetitem("R"+X+"C"+Y)
                                        setitem(x-1,y-1,item1)
                                next
                        next

SetColumnWidth(0,200)
SetColumnWidth(1,50)
SetColumnWidth(2,50)
SetColumnWidth(3,100)
SetColumnWidth(4,100)

mycols = new qstringlist() {
append("one")
append("Two")
append("three")
append("four")
append("five")
}

setHorizontalHeaderLabels(mycols)
                }

                setcentralwidget(table1)
                show()

        }

        exec()
}
 

Greetings,
Mahmoud

Bert Mariani

unread,
Sep 5, 2016, 2:39:53 AM9/5/16
to The Ring Programming Language
Hello Mahmoud

Thank you very much for adding the QT HorizontalHeaderLabels  to Ring.
And also for your sample code, showing how to use them

I modified your code slightly to:
 - Horizontal header text shows Blue
 - Vertical headere test shows Red
 - Alternating color Rows

 - However could not get the Header background-color  to work properly.
 - If you have ideas, please help

           setHorizontalHeaderLabels(mycols)
                        
           setAlternatingRowColors(true)
          #setStyleSheet("background-color: yellow")       
                      
           horizontalHeader().setStyleSheet("color: blue")
             verticalHeader().setStyleSheet("color: red");
.

AA-Widget-Table-11-Headers-MF.ring
Message has been deleted

Marino Esteban Liranzo Cruz

unread,
Sep 6, 2016, 3:07:31 AM9/6/16
to The Ring Programming Language
Hi Bert, Mahmoud and all

Thanks for the improvements and the great knowledge we are taught. Is great the last improvements made to the Qtablewidget class.

I show a slightly different alternative that save me a few lines of codes.



Greetings
Marino Liranzo
AA-Widget-Table-11-Headers-MF.ring

Mahmoud Fayed

unread,
Sep 6, 2016, 9:05:36 AM9/6/16
to The Ring Programming Language
Hello Marino, Gal  and Bert

Keep up the good work :D

Greetings,
Mahmoud

Bert Mariani

unread,
Sep 6, 2016, 6:57:55 PM9/6/16
to The Ring Programming Language

Hello ALL

See attached file
For some colour to the TableWidget

 - Yellow headers
 - Orange body
 - Blue text on horizontal labels
 - Red text on vertical row
 - Alternate colour on rows


    setAlternatingRowColors(true) 
                       
    setStyleSheet("QHeaderView::section { background-color: yellow }")
    setStyleSheet("background-color: orange")
                        
    horizontalHeader().setStyleSheet("color: blue")
      verticalHeader().setStyleSheet("color: red");

Mahmoud Fayed

unread,
Sep 7, 2016, 1:32:16 AM9/7/16
to The Ring Programming Language
Hello Bert, Gal and Marino

Nice Example, Keep up the good work :D

Please Each one add his examples in this folder

Just send the pull request using GitHub and i will accept it.

Greetings,
Mahmoud

CalmoSoft

unread,
Sep 7, 2016, 11:49:42 AM9/7/16
to The Ring Programming Language
Hello Mahmoud,

How can I change the background color of a cell in the QTableWidget class?

CalmoSoft

unread,
Sep 7, 2016, 1:32:24 PM9/7/16
to ring...@googlegroups.com
Hello Bert, Marino, Mahmoud,

I have solved the problem.
I added line:

setStyleSheet("QTableWidget::item{background-color: orange}")

Code:

Load "guilib.ring"

New qApp 
{

    win1 = new qMainWindow() 
    {
           setGeometry(100,100,1100,370)
           setwindowtitle("Using QTableWidget")

           Table1 = new qTableWidget(win1) 
           {
                    setrowcount(10) setcolumncount(5)
                    setGeometry(0,0,800,400)
                    setselectionbehavior(QAbstractItemView_SelectRows)
                    setSelectionMode(QAbstractItemView_SelectItems) 

                    for x = 1 to 10
                        for y = 1 to 5
                            item1 = new qtablewidgetitem("R"+X+"-C"+Y)
                            setitem(x-1,y-1,item1)                                                                       
                        next
                    next

                    SetColumnWidth(0,200)
                    SetColumnWidth(1,50)
                    SetColumnWidth(2,50)
                    SetColumnWidth(3,100)
                    SetColumnWidth(4,100)

                                    mycols = new qstringlist() 

                    {
                            append("SYMBOL") 
                            append("NAME")
                            append("GROUP")
                            append("CHANGE")
                            append("RATIO")
                    }
                    setHorizontalHeaderLabels(mycols)
                    //setAlternatingRowColors(true)
                        
                    setStyleSheet("QHeaderView::section { background-color: yellow }")
                    setStyleSheet("QTableWidget::item{background-color: orange}")
                       
                    horizontalHeader().setStyleSheet("color: blue")
                    verticalHeader().setStyleSheet("color: red")                         
           }
                    setcentralwidget(table1)
           show()
    }
    exec()
}


Output:

CalmoSoftQTableWidgetColor.ring

Mahmoud Fayed

unread,
Sep 7, 2016, 1:36:07 PM9/7/16
to The Ring Programming Language
Hello Gal

Nice samples, Keep up the good work :D

Greetings,
Mahmoud

CalmoSoft

unread,
Sep 7, 2016, 1:40:47 PM9/7/16
to The Ring Programming Language
Hello Mahmoud,

Thank you very much for your kind words.

Mahmoud Fayed

unread,
Sep 7, 2016, 1:42:20 PM9/7/16
to The Ring Programming Language
Hello Gal

You are welcome :D

Greetings,
Mahmoud

Marino Esteban Liranzo Cruz

unread,
Sep 7, 2016, 9:46:01 PM9/7/16
to The Ring Programming Language
Hello Gal,

Is great, simply great.

Greetings
Marino Liranzo

Bert Mariani

unread,
Sep 8, 2016, 1:45:23 AM9/8/16
to The Ring Programming Language
Hello Mahmoud et ALL

I ran into this problem with QTableWidget:
Program is attached.

When inserting data into the data cells:
 - Inserting "Apha"  data works
 - Inserting "Numeric" data fails --. "ring.exe has stopped working"

Using the Class Company  with members. Some are alpha data, some are numbers
Example:  AMZN Amazon Cloud 3 154.80 117.39

=============================
INPUT SECTION

Table1 = new qTableWidget(win1) 
    {   See nl + "TableWidget called: " +nl
    
        setrowcount(10) setcolumncount(10)     ###  10 X 10
        setGeometry(60,60,800,600)
        setselectionbehavior(QAbstractItemView_SelectRows)
        setSelectionMode(QAbstractItemView_SelectItems)         
        
        for x = 1 to len(sortedList)
            
                item1 = new qtablewidgetitem(sortedList[x].Symbolz)
                item2 = new qtablewidgetitem(sortedList[x].Namez)
                item3 = new qtablewidgetitem(sortedList[x].Groupz)
                
                ### FAILS - Number -- "ring.exe has stopped working"
                item4 = new qtablewidgetitem(sortedList[x].Positionz)           ### <<< Positionz has number values 3, 2, 5, 4, 1, 0
                
                ### Works - Alpha 
                item4 = new qtablewidgetitem("D " + sortedList[x].Positionz)  ### <<< Preceeded by "D " +  Positionz  -- no problem
                
                item5 = new qtablewidgetitem("E " + sortedList[x].Changez)
                item6 = new qtablewidgetitem("F " + sortedList[x].Ratioz)
                
                setitem(x-1,0, item1) 
                setitem(x-1,1, item2) 
                setitem(x-1,2, item3) 
                setitem(x-1,3, item4) 
                setitem(x-1,4, item5) 
                setitem(x-1,5, item6) 
        next

==============================
OUTPUT

SORT:

AMZN Amazon Cloud 3 154.80 117.39
FB Facebook Tech 2 143.34 114.02
GOOGL Google Cloud 5 126.70 107.83
NVDA Nvidia Chips 4 287.49 141.35
SDYL SPDivs ETF 1 152.33 119.85
SPY SP500 Index 0 109.24 107.21

TableWidget called:

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

AA-Widget-Table-14-Test.ring

Marino Esteban Liranzo Cruz

unread,
Sep 8, 2016, 3:48:19 AM9/8/16
to The Ring Programming Language
Hello Mahmoud Fayed, Gal, Bert and all

I have on my table four columns in which I put combobox (column 4, column 5, column 6 and column 7) when I click on one of these columns a combobox is placed, when I select an item in the combobox that is placed in the cell, up here it works well; but if I select in the next cell the same element this is not fixed in the cell, the cell is blank.

If I press again the cells with the mouse button once the cell has value, an error occurs and execution stops.


Greetings
Marino Liranzo
frmCalLosas.ring

Mahmoud Fayed

unread,
Sep 8, 2016, 5:01:51 AM9/8/16
to ring...@googlegroups.com
Hello Bert

you can use the string() function to convert numbers to string
num1 =123
mystr
=string(num1)

or you can use
num1 = 123
mystr
=""+num1

when you pass parameters
num1=123
myfunc
(string(123))

or
num1 = 123
myfunc
(""+num1)


Greetings,
Mahmoud

Mahmoud Fayed

unread,
Sep 8, 2016, 5:16:09 AM9/8/16
to The Ring Programming Language
Hello Marino

The problem reason is using the same combobox object in many cells !

Just create new object for each cell

When you define the table items, check for the columns where you need a combobox 
then create a new combobox for the cell

Also after this modification, You don't need the click event to change the cell object.

Greetings,
Mahmoud

CalmoSoft

unread,
Sep 8, 2016, 6:59:33 AM9/8/16
to ring...@googlegroups.com
Hello Bert,

You can use the next lines:

item4 = new qtablewidgetitem("" + sortedList[x].Positionz)                 
item5 = new qtablewidgetitem("" + sortedList[x].Changez)
item6 = new qtablewidgetitem("" + sortedList[x].Ratioz)

Greetings,
AA-Widget-Table-15-Test.ring

Bert Mariani

unread,
Sep 8, 2016, 11:26:16 AM9/8/16
to The Ring Programming Language
I guess the questions would be:

- Why does WidgetItem not accept a numeric input ?

- Why does Ring stop working, when a number is entered into the widget item ?

Marino Esteban Liranzo Cruz

unread,
Sep 8, 2016, 4:15:40 PM9/8/16
to The Ring Programming Language

Hello Mr. Mahmoud

I have made the suggested changes to my project qTablewidget; but continues to perform the same situation, text entered via the combobox is erased if I put items on the next line.

I can not find the methods setVisible (true) for the QComboBox object.

Greetings
Marino Liranzo
frmCalLosas.ring
Message has been deleted

CalmoSoft

unread,
Sep 9, 2016, 10:26:44 AM9/9/16
to The Ring Programming Language
Hello Mostafa,

In the next line you have pLib() function without a definition:

myfilter.setMouseButtonReleaseEvent("pLib()")

Greetings,

Bert Mariani

unread,
Sep 9, 2016, 7:27:14 PM9/9/16
to The Ring Programming Language
Hello Marino

See attached version
I added some "See" statements and renamed some things ...  cbo1, cbo2 etc

- In Qt the widget table   starts at "Row 0"  I think you have a problem with currentRow()
- Your code is missing "func pLib"

==========
Output

pBox1: B Row: 0 Col: 5
pClick
pBox2: F Row: 1 Col: 6
pClick
pBox3: M Row: 2 Col: 7
pClick
pBox4: S Row: 3 Col: 8

AA-Widget-Table-15-Marino.ring

Bert Mariani

unread,
Sep 10, 2016, 12:38:53 AM9/10/16
to The Ring Programming Language
Hello Mahmoud et ALL

This program opens 2 WidgetTables. See attached
 - The first one  inside the main window - win1 - Table1
 - The second one as a separate window - win2 - Table2

The problem is:
 - The first one Table1 (yellow) calls its Functions and Works. It inserts a value from the drop-down list
 - The second one Table2 (aqua) calls its Functions but Fails. --   "Using initialized variable: table2"  --  

I cannot figure out why.
Can you help

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

cbo0 = new qCombobox(Table1) { for i in cbList addItem(i,0) next setcurrentIndexChangedEvent("pBox0()") }
...
    func pBox0
            Table1 {
                item0 = new qtablewidgetitem(cbo0.currentText())
                 setitem(currentrow(), 0, item0)
            }

----------------

cb2o0 = new qCombobox(Table2) { for i in cb2List addItem(i,0) next setcurrentIndexChangedEvent("p2Box0()") }
...
    func p2Box0
            Table2 {
                item0 = new qtablewidgetitem(cbo0.currentText())
                 setitem(currentrow(), 0, item0)

-----------------------

Line 172 Error (R24) : Using uninitialized variable : table2
In function p2box0() in file C:/RING/bin/AA-Widget-Table-16-Multi.ring
called from line 1  In qapp_exec In method exec() in file ring_qt.ring
called from line 63  in file C:/RING/bin/AA-Widget-Table-16-Multi.ring

=====================
AA-Widget-Table-16-Multi.ring

Marino Esteban Liranzo Cruz

unread,
Sep 10, 2016, 1:20:00 AM9/10/16
to The Ring Programming Language
Hello Mr. Bert,

If you look at your code I made some small changes. I believe that with these changes the problem is solved.

Greetings
Marino Liranzo


AA-Widget-Table-16-Multi.ring

CalmoSoft

unread,
Sep 10, 2016, 11:44:14 AM9/10/16
to ring...@googlegroups.com
Hello Marino, Bert, Mahmoud,

I have changed the code a little.

Code:

Load "guilib.ring"
win2 = NULL
table2=NULL
New qapp 
{
    win1 = new qMainWindow()
    {
        ###------------------------------------------------------
        setGeometry(200,200,800,500)
        setwindowtitle("qMainWindow -- Win 1 Table 1")
        
            Table1 = new qTableWidget(win1) 
            {
                setrowcount(6)
                setcolumncount(8)
                
                setGeometry(20,20,700,400)
                setselectionbehavior(QAbstractItemView_SelectRows)
                setSelectionMode(QAbstractItemView_SelectItems)             
    
                SetColumnWidth(0,60)    # 
                SetColumnWidth(1,100)   # 
                SetColumnWidth(2,75)    # 

                mycols = new qstringlist() 
                {
                    append("SYMBOL") 
                    append("NAME")
                    append("GROUP")

                }       
                
                setHorizontalHeaderLabels(mycols)
                setAlternatingRowColors(true)               
                setStyleSheet("QHeaderView::section { background-color: yellow }")
                horizontalHeader().setStyleSheet("color: blue")
                verticalHeader().setStyleSheet("color: red")  
                
                
                cbList =[" ", "Sort-H", "Sort-L", "X", "Y"]
                
                
                for i = 1 to 3
                     for j = 1 to 3
                          cbo = new qCombobox(Table1) { for x in cbList addItem(x,0) next setcurrentIndexChangedEvent("pBox1(i, j)") }
                          setCellWidget(i-1, j-1, cbo)
                     next
                next 

                ###---------------------
                ### TABLE 2 Widget
                
                DisplayWidgetTable()    
        
            }                       

            ###-------------------------------------------
        
        show()
            
    }

    exec()
}



###-----------------------------------------------
### Widget TABLE 2

Func DisplayWidgetTable 
if isobject(win2)
win2.activatewindow()
return
ok

    win2 = new qwidget() 
    {       
        setGeometry(30,40,700,400)
        setwindowtitle("Display qwidget - Win2 Table2")
        
            Table2 = new qTableWidget(win2) 
            {
                setrowcount(5)
                setcolumncount(6)
                
                setGeometry(75,50,800,600)
                setselectionbehavior(QAbstractItemView_SelectRows)
                setSelectionMode(QAbstractItemView_SelectItems)         
                
                SetColumnWidth(0,60)    # 
                SetColumnWidth(1,100)   # 
                SetColumnWidth(2,75)    #

                mycols = new qstringlist() 
                {
                    append("ABLE") 
                    append("BAKER")
                    append("CHARLIE")
                }
                    
                setHorizontalHeaderLabels(mycols)
                setAlternatingRowColors(true)
                    
                setStyleSheet("QHeaderView::section { background-color: aqua }")
                   
                horizontalHeader().setStyleSheet("color: blue")
                verticalHeader().setStyleSheet("color: red")  
                
                
                cb2List =[" ", "Look-M", "Look-N", "R", "S"]
                
                for i = 1 to 3
                     for j = 1 to 3
                          cbo = new qCombobox(Table2) { for x in cb2List addItem(x,0) next setcurrentIndexChangedEvent("pBox2(i, j)") }
                          setCellWidget(i-1, j-1, cbo)
                     next
                next 
   
            }
            
            ###-----------------------
        
        show()
            
    }

    ### exec()      
    
return
        

###-----------------------

    ###------------------------------------
    ### TABLE !
    
    func pBox1 m, n
            Table1 {
                item = new qtablewidgetitem(cbo.currentText())
                 setitem(m-1, n-1, item)
            } 

    func pBox2 m, n
            Table1 {
                item = new qtablewidgetitem(cbo.currentText())
                 setitem(m-1, n-1, item)
 
    ###------------------------------------
        
######################################

Output:



Greetings,
Gal Zsolt
(~ Gal Zsolt ~)
AA-Widget-Table-17-Multi.ring

Bert Mariani

unread,
Sep 10, 2016, 4:44:48 PM9/10/16
to The Ring Programming Language
Thank you Marino and Gal,  for the edited widget programs

There is still a problem with Win2, Table2  cBox2 etc
I changed the labels below to try a make it clear what  belongs to each Win.

Win1 =  ABC  cBox1A   cBox1List  pBox1A()   etc
Win2 =  XYZ  cBoc2X   cBox2List   Box2X()    etc

Each Win:   checkBox, List, Objects, Values  etc  should be completely separate from the other Win

The following error shows when calling the Win2  functions, objects     

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

Func - pBox1A: pBox1A D    <<<  Win1  selections Good
Func - pBox1B: pBox1B C
Func - pBox1C: pBox1C B

Func - pBox2Y:                    <<< Win2 selection Fails

Line 180 Error (R13) : Object is required
In function pbox2y() in file C:/RING/bin/AA-Table-16-Multi-2cMA.ring
called from line 1  In qapp_exec In method exec() in file ring_qt.ring
called from line 66  in file C:/RING/bin/AA-Table-16-Multi-2cMA.ring

======================================================
AA-Table-16-Multi-2cMA.ring

Marino Esteban Liranzo Cruz

unread,
Sep 11, 2016, 12:58:33 AM9/11/16
to The Ring Programming Language

Hello Mr. Bert,

Attached is a possible solution to the error messages presented.

Greetings
Marino Liranzo

AA-Table-16-Multi-2cMA.ring

Mahmoud Fayed

unread,
Sep 11, 2016, 1:33:59 PM9/11/16
to The Ring Programming Language
Hello Bert

Q : Why does WidgetItem not accept a numeric input ?
A : the function prototype used in RingQt accept only strings

Q : Why does Ring stop working, when a number is entered into the widget item ?
A : Thanks for the report

I have already fixed the problem in code generator in this commit

Then in RingQt in this commit

You can build from source code or download the last binary update

Greetings,
Mahmoud

Bert Mariani

unread,
Sep 12, 2016, 1:43:41 AM9/12/16
to The Ring Programming Language
Thank you Mahmoud

RING now detects the "numeric" as being bad data input to the Widget Item,
And continues running.

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

TableWidget called:

Line 3240 Bad parameter type!
In qtablewidgetitem_new In method init() in file ring_qt.ring
called from line 3239  In function displaywidgettable() in file C:/RING/bin/AA-Widget-Table-14-Test-fix.ring
called from line 35  in file C:/RING/bin/AA-Widget-Table-14-Test-fix.ring

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

Bert Mariani

unread,
Sep 12, 2016, 2:34:31 AM9/12/16
to The Ring Programming Language
Hello Marino, Gal, Mahmoud et ALL

I really do not understand the logic of this  qt  code.
I added some "See" statements, commented out some code , etc. Highlighted in Blue and Red below

I also was able to  "activatewindow()"  inside the Table 2  code

Some "return" statements prevent the "Func pBox2.." from being execute but values (X, Z)  still show up in the Item cell ???
It all seems to be a mystery.
Why some things seem to work when they should not, and vice versa ???

Can you figure it out ?

========================
OUTPUT

Func - pBox1A: pBox1A A                      <<<  Good
Func - pBox1B: pBox1B B                      <<<  Good
Func - pBox1C: pBox1C C                      <<<  Good

pBox2X - win.Activate                              <<< "Func pBox1X"  does not execute because of previous "return", But letter "X" shows up ???
pBox2Z - win.Activate                              <<< "Func pBox1Z"  does not execute because of previous "return", But letter "Z" shows up ???

pBox2Y - win.Activate
Func - pBox2Y:                                          <<< "return" was commented out, Complains about Object
Line 153 Error (R13) : Object is required
In function pbox2y() in file C:/RING/bin/AA-Table-16-Multi-3 .ring
called from line 1  In qapp_exec In method exec() in file ring_qt.ring
called from line 59  in file C:/RING/bin/AA-Table-16-Multi-3 .ring



========================
INPUT

Load "guilib.ring"

win2   = NULL
table2 = NULL

New qapp 
{
    win1 = new qMainWindow()
    {
        ###------------------------------------------------------
        setGeometry(200,200,800,500)
        setwindowtitle("qMainWindow -- Win 1 Table 1 ABCD")
        
            Table1 = new qTableWidget(win1) 
            {
                setrowcount(6)
                setcolumncount(8)
                
                setGeometry(20,20,700,400)
                setselectionbehavior(QAbstractItemView_SelectRows)
                setSelectionMode(QAbstractItemView_SelectItems)             
    
                SetColumnWidth(0,60)    # 
                SetColumnWidth(1,100)   # 
                SetColumnWidth(2,75)    # 

                mycols = new qstringlist() 
                {
                    append("SYMBOL") 
                    append("NAME")
                    append("GROUP")
                }       
                
                setHorizontalHeaderLabels(mycols)
                setAlternatingRowColors(true)               
                setStyleSheet("QHeaderView::section { background-color: yellow }")
                horizontalHeader().setStyleSheet("color: blue")
                verticalHeader().setStyleSheet("color: red")                
                
                cBox1List =[" ", "A", "B", "C", "D"]
                
                cBox1A = new qCombobox(Table1) { for i in cBox1List addItem(i,0) next setcurrentIndexChangedEvent("pBox1A()") }
                cBox1B = new qCombobox(Table1) { for i in cBox1List addItem(i,0) next setcurrentIndexChangedEvent("pBox1B()") }
                cBox1C = new qCombobox(Table1) { for i in cBox1List addItem(i,0) next setcurrentIndexChangedEvent("pBox1C()") }
              
                setCellWidget(0, 0, cBox1A)
                setCellWidget(0, 1, cBox1B)
                setCellWidget(0, 2, cBox1C)

                ###---------------------
                ### TABLE 2 Widget
                
                DisplayWidgetTable()           
            }                       

            ###-------------------------------------------      
        show()       
    }
    exec()
}

###-----------------------------------------------
### Widget TABLE 2

Func DisplayWidgetTable 

#if isobject(win2)                                                                ### <<< Commented out.  Never called
#   win2.activatewindow()
#   See "Func DisplayWidgetTable - win.Activate" +nl      ### <<< See never called
#   return
#ok

    win2 = new qwidget() 
    {       
        setGeometry(30,40,700,400)
        setwindowtitle("Display qwidget - Win2 Table2 XYZW")
        
            Table2 = new qTableWidget(win2) 
            {
                setrowcount(5)
                setcolumncount(6)
                
                setGeometry(75,50,800,600)
                setselectionbehavior(QAbstractItemView_SelectRows)
                setSelectionMode(QAbstractItemView_SelectItems)         
                
                SetColumnWidth(0,60)    # 
                SetColumnWidth(1,100)   # 
                SetColumnWidth(2,75)    #

                mycols = new qstringlist() 
                {
                    append("ABLE") 
                    append("BAKER")
                    append("CHARLIE")
                }
                    
                setHorizontalHeaderLabels(mycols)
                setAlternatingRowColors(true)
                    
                setStyleSheet("QHeaderView::section { background-color: aqua }")
                   
                horizontalHeader().setStyleSheet("color: blue")
                verticalHeader().setStyleSheet("color: red")  
                               
                cBox2List =[" ", "X", "Y", "Z", "W"]
                
                cBox2X = new qCombobox(Table2) { for i in cBox2List addItem(i,0) next setcurrentIndexChangedEvent("pBox2X()") }
                cBox2Y = new qCombobox(Table2) { for i in cBox2List addItem(i,0) next setcurrentIndexChangedEvent("pBox2Y()") }
                cBox2Z = new qCombobox(Table2) { for i in cBox2List addItem(i,0) next setcurrentIndexChangedEvent("pBox2Z()") }
        
                setCellWidget(0, 0, cBox2X)
                setCellWidget(0, 1, cBox2Y)
                setCellWidget(0, 2, cBox2Z)           
            }
            
            ###-----------------------     
        show()
    }
 
    ### exec()  
    win2.activateWindow()   ### <<< ACTIVATE ADDED HERE 
    
return
        
###-----------------------

    ###------------------------------------
    ### TABLE 2
    
    func pBox2X
    if isobject(Table2)
        #win2.activatewindow()                 ### <<< Commented out. Win2.activatewindow()  done  in Table 2 Widget before
        #Table2.activatewindow()              ### <<< Commented out
        See "pBox2X - win.Activate" +nl
        return                                            ### <<< Next code pBox2X never called, but letter "X" shows up in Item cell ?!
    ok
            See "Func - pBox2X: "
            Table2 {
                See "pBox2X " + cBox2X.currentText() +nl
                item2X = new qtablewidgetitem(cBox2X.currentText())
                setitem(currentrow(), 0, item2X)
            }
            
    func pBox2Y
    if isobject(Table2)
        win2.activatewindow()
        See "pBox2Y - win.Activate" +nl
        #return                                                      ###  <<< Commented out
    ok
            See "Func - pBox2Y: "                           ### <<< Next code pBox2Y FAILS. -- Object is required
            Table2 {
                See "pBox2Y " + cBox2Y.currentText() +nl
                item2Y = new qtablewidgetitem(cBox2Y.currentText())
                setitem(currentrow(), 1, item2Y)
            }
            
    func pBox2Z
    if isobject(Table2)
        win2.activatewindow()
        See "pBox2Z - win.Activate" +nl
        return                                             ### <<< Next code pBox2Z never called, but letter "Z" shows up in Item cell ?!
    ok
            See "Func - pBox2Z: "
            Table2 {
                See "pBox2Z " + cBox2Z.currentText() +nl
                item2Z = new qtablewidgetitem(cBox2z.currentText())
                setitem(currentrow(), 2, item2Z)
            }
            
    
    ###------------------------------------
    ### TABLE !
    
    func pBox1A
            See "Func - pBox1A: "
            Table1 {
                See "pBox1A " + cBox1A.currentText() +nl
                item1A = new qtablewidgetitem(cBox1A.currentText())
                setitem(currentrow(), 0, item1A)
            }
    func pBox1B
            See "Func - pBox1B: "
            Table1 {
                See "pBox1B " + cBox1B.currentText() +nl
                item1B = new qtablewidgetitem(cBox1B.currentText())
                 setitem(currentrow(), 1, item1B)
            }
    func pBox1C
            See "Func - pBox1C: "
            Table1 {
                See "pBox1C " + cBox1C.currentText() +nl
                item1C = new qtablewidgetitem(cBox1C.currentText())
                setitem(currentrow(), 2, item1C)
            }
  
    ###----------------------------------------
        
######################################
AA-Table-16-Multi-3 .ring

Mahmoud Fayed

unread,
Sep 12, 2016, 3:18:25 AM9/12/16
to The Ring Programming Language
Hello Bert

The error message "Line 153 Error (R13) : Object is required In function pbox2y() "

The code
See "pBox2Y " + cBox2Y.currentText() +nl

You are using cBox2Y which is not an object ! because the variable is not defined in this scope - it's a local variable in another function

Quick Solution, in the start of the program
cBox2Y = NULL

This way cBox2Y will become a global variable that you can access from any function.

Better Solution :
In the future (for large programs this will be more important to avoid global variables)
(1) Create a Class for each window
(2) Define controls As attributes in the class
(3) Access controls from any method in the class 
(4) Events uses object.method() instead of function()


Note : Also when you create a class and make it general - you can create many objects (windows) from this class
This avoid code redundancy when you need more than window will similar behavior


Greetings,
Mahmoud

Mahmoud Fayed

unread,
Sep 12, 2016, 3:37:46 AM9/12/16
to The Ring Programming Language
Hello Bert

Another simple example about using a class for each window

Load "guilib.ring"

new qApp {
        oClient
= new Client { client() }
        oServer
= new Server { server() }
       
exec()
}

Class Client

        win1 lineedit1  cOutput
=""
        oTcpSocket

        func client

                win1
= new qwidget()

               
new qpushbutton(win1) {
                        setgeometry
(50,50,100,30)
                        settext
("connect")
                        setclickevent
("oClient.Connect()")
               
}

                lineedit1
= new qtextedit(win1) {
                        setGeometry
(150,50,200,300)
               
}

                win1
{
                        setwindowtitle
("client")
                        setgeometry
(10,100,400,400)
                        show
()
               
}

        func connect
                cOutput
= "Connect to host 127.0.0.1 port 9999" + nl
                lineedit1
.settext(cOutput)
                oTcpSocket
= new qTcpSocket(win1) {
                        setconnectedevent
("oClient.pConnected()")
                        setreadyreadevent
("oClient.pRead()")
                        connecttohost
("127.0.0.1",9999,3,0)
                        waitforconnected
(5000)
               
}

        func pConnected

                cOutput
+= "Connected!" + nl
                lineedit1
.settext(cOutput)

        func pRead

                cOutput
+= "Ready Read!" + nl
                lineedit1
.settext(cOutput)
                cOutput
+= oTcpSocket.readall().data() + nl
                lineedit1
.settext(cOutput)

Class Server

        win1 lineedit1
        oTcpServer oTcpClient
        cOutput
= ""

        func server

                win1
= new qwidget()

                lineedit1
= new qtextedit(win1) {
                        setGeometry
(150,50,200,300)
               
}

                win1
{
                        setwindowtitle
("Server")
                        setgeometry
(450,100,400,400)
                        show
()
               
}

                oTcpServer
= new qTcpServer(win1) {
                        setNewConnectionEvent
("oServer.pNewConnection()")
                        oHostAddress
= new qHostAddress()
                        oHostAddress
.SetAddress("127.0.0.1")
                        listen
(oHostAddress,9999)
               
}
                cOutput
= "Server Started" + nl +
                           
"listen to port 9999" + nl

                lineedit1
.settext(cOutput)

       
Func pNewConnection

                oTcpClient
= oTcpServer.nextPendingConnection()
                cOutput
+= "Accept Connection" + nl
                lineedit1
.settext(cOutput)
                oTcpClient
{
                        cStr
="Hello from server to client!"+char(13)+char(10)
                        write
(cStr,len(cStr))
                        flush
()
                        waitforbyteswritten
(300000)
                        close
()
               
}

Greetings,
Mahmoud

Bert Mariani

unread,
Sep 12, 2016, 3:55:39 PM9/12/16
to The Ring Programming Language
Hello Mahmoud, Marino, Gal et ALL

Weird stuff with QT and multiple Widget Windows, Tables and CheckBox:

All the Functions do nothing, yet the CheckBoxes get filled in with proper letter  ??!!
How can that be ?
See code below and attached.

Does anybody have an explanation ?

----------------------------------------------
        func pBox2X
See "func pBox2X: " +nl
return

        func pBox1A
See "func pBox1A: " +nl
return
---------------------------------------------




====================
OUTPUT

func pBox1A:
func pBox1B:
func pBox1C:
func pBox2X:
func pBox2Y:
func pBox2Z:

============
INPUT

    win2.activateWindow()   ### <<< ACTIVATE HERE 
    
return
        
###-----------------------

    ###------------------------------------
    ### TABLE 2
    
    func pBox2X
        See "func pBox2X: " +nl
    return
            
    func pBox2Y
        See "func pBox2Y: " +nl 
    return
    
    func pBox2Z
        See "func pBox2Z: " +nl 
    return
    
    ###------------------------------------
    ### TABLE !
    
    func pBox1A
        See "func pBox1A: " +nl
    return
            
    func pBox1B
        See "func pBox1B: " +nl
    return
            
    func pBox1C
        See "func pBox1C: " +nl
    return
AA-Table-16-Multi-3c .ring

Bert Mariani

unread,
Sep 13, 2016, 1:59:19 AM9/13/16
to The Ring Programming Language
As per Mahmoud's suggestion

Define the Functions related to Table2 as NULL  (global)
     win2   = NULL
     table2 = NULL
     cBox2X = NULL
     cBox2Y = NULL
     cBox2Z = NULL


After a CheckBox selection is made, the Value can be read by the Called Func  using " cBox2X.currentText() "

    func pBox2X
        See "func pBox2X: " 
        See " X= " + cBox2X.currentText() +nl
    return


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

See "func pBox2X: " 
See " X= " + cBox2X.currentText() +nl

   func pBox1A:  A=  A
   func pBox1B:  B=  B
   func pBox1C:  C=  C

   func pBox2X:  X=  X
   func pBox2Y:  Y=  Y
   func pBox2Z:  Z=  Z


========================
.
Load "guilib.ring"

win2   = NULL
table2 = NULL

cBox2X = NULL
cBox2Y = NULL
cBox2Z = NULL
        See " X= " + cBox2X.currentText() +nl
    return
            
    func pBox2Y
        See "func pBox2Y: " 
        See " Y= " + cBox2Y.currentText() +nl
    return
    
    func pBox2Z
        See "func pBox2Z: " 
        See " Z= " + cBox2Z.currentText() +nl
    return
    
    ###------------------------------------
    ### TABLE !
    
    func pBox1A
        See "func pBox1A: " 
        See " A= " + cBox1A.currentText() +nl
    return
            
    func pBox1B
        See "func pBox1B: " 
        See " B= " + cBox1B.currentText() +nl
    return
            
    func pBox1C
        See "func pBox1C: " 
        See " C= " + cBox1C.currentText() +nl
    return
  
    ###----------------------------------------
        
######################################




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

CalmoSoft

unread,
Sep 13, 2016, 4:00:24 PM9/13/16
to ring...@googlegroups.com
Hello Marino, Bert, Mahmoud,

I have the next code but it doesn't work properly.
What do I wrong?
Thank you very much.

Code:

Load "guilib.ring"

win2   = NULL
table2 = NULL
cbo = NULL

New qapp 
{
    win1 = new qMainWindow()
    {
        ###------------------------------------------------------
        setGeometry(200,200,800,500)
        setwindowtitle("qMainWindow -- Win 1 Table 1 ABCD")
        
            Table1 = new qTableWidget(win1) 
            {
                setrowcount(6)
                setcolumncount(8)
                
                setGeometry(20,20,700,400)
                setselectionbehavior(QAbstractItemView_SelectRows)
                setSelectionMode(QAbstractItemView_SelectItems)             
    
                SetColumnWidth(0,60)    # 
                SetColumnWidth(1,100)   # 
                SetColumnWidth(2,75)    # 

                mycols = new qstringlist() 
                {
                    append("SYMBOL") 
                    append("NAME")
                    append("GROUP")
                }       
                
                setHorizontalHeaderLabels(mycols)
                setAlternatingRowColors(true)               
                setStyleSheet("QHeaderView::section { background-color: yellow }")
                horizontalHeader().setStyleSheet("color: blue")
                verticalHeader().setStyleSheet("color: red")                
                
                cBox1List =[" ", "A", "B", "C", "D"]
                
                for i = 1 to 3
                     for j = 1 to 3
                          cbo = new qCombobox(Table1) { for x in cBox1List addItem(x,0) next setcurrentIndexChangedEvent("pBox1(i, j)") }
                          setCellWidget(i-1, j-1, cbo)
                     next
                next 

                for i = 1 to 3
                     for j = 1 to 3
                          cbo = new qCombobox(Table2) { for x in cBox2List addItem(x,0) next setcurrentIndexChangedEvent("pBox2(i, j)") }
                          setCellWidget(i-1, j-1, cbo)
                     next
                next 
                
            }
            
            ###-----------------------     
        show()
    }
 
    ### exec()  
    win2.activateWindow()   ### <<< ACTIVATE HERE 
    
return
        
###-----------------------

    func pBox1 m, n

           Table1 {
                     item = new qtablewidgetitem(cbo.currentText())
                     setitem(m-1, n-1, item)
                     see "func pBox1: " 
                     see " ABCD= " + cbo.currentText() + nl
                     } 
    
    func pBox2 m, n

           Table2 {
                     item = new qtablewidgetitem(cbo.currentText())
                     setitem(m-1, n-1, item)
                     see "func pBox2: " 
                     see " XYZW= " + cbo.currentText() + nl
                     }
        
######################################


Greetings,
AA-Table-16-Multi-4c.ring

Bert Mariani

unread,
Sep 13, 2016, 8:43:01 PM9/13/16
to The Ring Programming Language
Hello Gal

This is the best I have been able to do so far today.


=============
OUTPUT

func pBox1:  ABCD=   Index: 0
func pBox1:  ABCD=   Index: 0
func pBox1:  ABCD= C Index: 3    <<< Only last combo box shows value

func pBox2:  XYZW=   Index: 0
func pBox2:  XYZW=   Index: 0
func pBox2:  XYZW= Z Index: 3    <<< Only last combo box shows value


-----------------------
INPUT Changes

win2   = NULL
table2 = NULL
cbo2   = NULL
pBox2  = NULL

....
### Loop OVERLAYS  cbo1  CheckBox.  Only last one is valid
                for i = 1 to 3
                     for j = 1 to 3
                          cbo1 = new qCombobox(Table1) { for x in cBox1List addItem(x,0) next setcurrentIndexChangedEvent("pBox1(i, j)") }
                          setCellWidget(i-1, j-1, cbo1)
                     next
                next 

...
....
### Loop OVERLAYS  cbo2  CheckBox.  Only last one is valid
                for i = 1 to 3
                     for j = 1 to 3
                          cbo2 = new qCombobox(Table2) { for x in cBox2List addItem(x,0) next setcurrentIndexChangedEvent("pBox2(i, j)") }
                          setCellWidget(i-1, j-1, cbo2)
                     next
                next 

.....
.....
func pBox1 m, n

           #Table1 {
                     #item = new qtablewidgetitem(cbo1.currentText())
                     #setitem(m-1, n-1, item)
                     
                     see "func pBox1: " 
                     see " ABCD= " + cbo1.currentText() +" Index: "+ cbo2.currentIndex() + nl
                     
                     #} 
    
    func pBox2 m, n

           #Table2 {
                     #item = new qtablewidgetitem(cbo2.currentText())
                     #setitem(m-1, n-1, item)
                                         
                     see "func pBox2: " 
                     see " XYZW= " + cbo2.currentText()  +" Index: "+ cbo2.currentIndex() + nl 
                     
                     #}

==============================
AA-Table-16-Multi-4bCS.ring

CalmoSoft

unread,
Sep 14, 2016, 5:15:14 AM9/14/16
to The Ring Programming Language
Hello Bert,

Thank you very much for your code.

CalmoSoft

unread,
Sep 14, 2016, 1:43:32 PM9/14/16
to ring...@googlegroups.com
Hello Bert, Marino, Mahmoud,

How can I get the text of selected item in combobox?
Thank you very much.

Marino Esteban Liranzo Cruz

unread,
Sep 14, 2016, 6:03:04 PM9/14/16
to The Ring Programming Language
Hello Gal

You can get an item from a combobox using the method currentIndex () This indicates the index of the element, if you will use the value of the element in any operation can use the method currentText (). See on the project I am adding, in this I am making use both of these methods.

Greetings
Marino Liranzo
clsDatosG2.ring

Marino Esteban Liranzo Cruz

unread,
Sep 14, 2016, 6:34:12 PM9/14/16
to The Ring Programming Language
Hello Mr. Mahmoud, Mr. Bert
I would like if you could take a moment to check the code I sent to Mr. Gal, this code despite that I am placing the variables as class attributes at the beginning of class, I get the error required object, this I have forced to declare each variable as global.

 Greetings.
Marino Liranzo

Mahmoud Fayed

unread,
Sep 15, 2016, 2:15:39 AM9/15/16
to The Ring Programming Language
Hello Marino

Remember that we have Three scopes (Local Scope, Object Scope and Global Scope) and when we
are inside a class method, we expect that we have access to the object attributes and methods and
this is true until we use braces to access another object attributes and methods because in this case
our object scope will be switched to another object.

new point { test() }

class point
x=10 y=20
func test
see x + nl + y + nl # works fine
myobj = new otherclass {
see name + nl
see x + nl + y + nl # error !
}

class otherclass
name = "test"

output

10
20
test

Line 8 Error (R24) : Using uninitialized variable : x
In method test() in file methodbraceerror.ring
called from line 5  in file methodbraceerror.ring

Now what we will do to solve the previous problem?

The best solution : Don't Use Braces

new point { test() }

class point
x=10 y=20
func test
see x + nl + y + nl  
myobj = new otherclass 
see x + nl + y + nl

class otherclass
name = "test"


output
10
20
test
10
20

Other Solution (May lead to other errors) : Copy the self object 

new point { test() }

class point
x=10 y=20
func test
oSelf = self
see x + nl + y + nl  
myobj = new otherclass {
see name + nl
see oself.x + nl + oself.y + nl  
}

class otherclass
name = "test"

Now look at this line

oself = self

The problem with the previous line is that we will have a new copy from the object
Because in Ring the assignment operator copy lists and objects by value (not by reference).

When we access the new object attributes (reading) we don't have problems 

But if we modified the object attributes (Then we will modify the copy!).

In GUI application, we may create a class contains the window objects as attributes to be able 
to access the controls from different methods. Remember the previous information when you try to access
objects using braces inside methods because in this case you can't access the object attributes directly
and if you copied the self object you will work on a copy and the new controls that you create will be 
related to the copy and you can't access them.

Greetings,
Mahmoud

CalmoSoft

unread,
Sep 15, 2016, 7:31:37 AM9/15/16
to The Ring Programming Language
Hello Marino,

Thank you very much for your help and code.

Bert Mariani

unread,
Sep 15, 2016, 7:48:24 PM9/15/16
to The Ring Programming Language
Hello Mahmoud

After reading he explanation again about Local, Global and Object Scope ...
It is not clear to me why Ring behaves like it does

How would you modify the attached program so that it does not use global's at the top.
A main window plus a second window with a widget table.

Also in the Class Company,  any name used  should not interfere with some global name. 
"company.symbol"   is different from "symbol" used elsewhere
I am treating "Class Company" purely as a structure.

   Load "guilib.ring"
   win2   = NULL
   table2 = NULL
   cBox2X = NULL
   cBox2Y = NULL
   cBox2Z = NULL

Greetings
Bert Mariani

Marino Esteban Liranzo Cruz

unread,
Sep 15, 2016, 10:28:21 PM9/15/16
to The Ring Programming Language
Hello Mr. Mahmoud Fayed,

Thanks for the explanation offered, however there seems to work according to the aforementioned scope.


Greetings
Marino Liranzo


Bert Mariani

unread,
Sep 16, 2016, 12:31:21 AM9/16/16
to The Ring Programming Language
Hello Mahmoud

Sorry forgot to attach program.
AA-Table-16-Multi-3e-object .ring

Mahmoud Fayed

unread,
Sep 16, 2016, 7:13:56 AM9/16/16
to ring...@googlegroups.com
Hello Bert

I have already converted the program to use classes (A Class for each window)

The process is very simple (requires no effort) and i hope that you will like it :D

The idea
(1) Create the window under the class name directly
In this area the three scopes are 
1 - The global scope ---> The global scope
2 - The object scope ---> The object scope
3 - The local scope ---->  The object scope
Since the local scope is the object scope, then when we uses braces { } in this area while creating windows and controls we still have access
to the object scope, so we can use nested braces as we want and when we create controls they will be added as the object attributes so we can
access them from methods. 

(2) To define events we need to determine the object name and the method name, we used one global variable $objectname to store the object name.

Source Code:

Load "guilib.ring"

New qapp 
{
    $ObjectName = "oFirstWindow"
    oFirstWindow = new FirstWindow

    $ObjectName = "oSecondWindow"
    oSecondWindow = new SecondWindow
    exec()
}


class firstwindow

    win1 = new qMainWindow()
    {
        ###------------------------------------------------------
        setGeometry(200,200,800,500)
        setwindowtitle("qMainWindow -- Win 1 Table 1 ABCD")
        
            Table1 = new qTableWidget(win1) 
            {
                setrowcount(6)
                setcolumncount(8)
                
                setGeometry(20,20,700,400)
                setselectionbehavior(QAbstractItemView_SelectRows)
                setSelectionMode(QAbstractItemView_SelectItems)             
    
                SetColumnWidth(0,60)    # 
                SetColumnWidth(1,100)   # 
                SetColumnWidth(2,75)    # 

                mycols = new qstringlist() 
                {
                    append("SYMBOL") 
                    append("NAME")
                    append("GROUP")
                }       
                
                setHorizontalHeaderLabels(mycols)
                setAlternatingRowColors(true)               
                setStyleSheet("QHeaderView::section { background-color: yellow }")
                horizontalHeader().setStyleSheet("color: blue")
                verticalHeader().setStyleSheet("color: red")                
                
                cBox1List =[" ", "A", "B", "C", "D"]
                
                cBox1A = new qCombobox(Table1) { for i in cBox1List addItem(i,0) next setcurrentIndexChangedEvent($ObjectName+".pBox1A()") }
                cBox1B = new qCombobox(Table1) { for i in cBox1List addItem(i,0) next setcurrentIndexChangedEvent($ObjectName+".pBox1B()") }
                cBox1C = new qCombobox(Table1) { for i in cBox1List addItem(i,0) next setcurrentIndexChangedEvent($ObjectName+".pBox1C()") }
              
                setCellWidget(0, 0, cBox1A)
                setCellWidget(0, 1, cBox1B)
                setCellWidget(0, 2, cBox1C)
                
                ###---------------------------
                ### Add some Table Widget Items
                
                setItem(1,0, new qTableWidgetItem("ATT") )
                setItem(2,1, new qTableWidgetItem("BAC") )  
                setItem(3,2, new qTableWidgetItem("CVX") )  
                

                ###---------------------
                ### TABLE 2 Widget
                
  #$ObjectName = $ObjectName + ".oSecondWindow"   # oFirstWindow.oSecondWindow
                #oSecondWindow = new DisplayWidgetTable
            }                       

            ###-------------------------------------------      
        show()       
    }

###-----------------------

    ###------------------------------------
    ### TABLE Methods
    
    func pBox1A
        See "func pBox-1A: " + cBox1A.currentText() +" Index: "+  cBox1A.currentIndex() +nl
    return
            
    func pBox1B
        See "func pBox-1B: " + cBox1B.currentText() +" Index: "+  cBox1B.currentIndex() +nl
    return
            
    func pBox1C
        See "func pBox-1C: " + cBox1C.currentText() +" Index: "+  cBox1C.currentIndex() +nl
    return
  
    ###----------------------------------------



###-----------------------------------------------
### Widget TABLE 2

Class SecondWindow

    win2 = new qwidget() 
    {       
        setGeometry(30,40,700,400)
        setwindowtitle("Display qwidget - Win2 Table2 XYZW")
        
            Table2 = new qTableWidget(win2) 
            {
                setrowcount(8)
                setcolumncount(6)
                
                setGeometry(20,20,800,600)
                setselectionbehavior(QAbstractItemView_SelectRows)
                setSelectionMode(QAbstractItemView_SelectItems)         
                
                SetColumnWidth(0,60)    # 
                SetColumnWidth(1,100)   # 
                SetColumnWidth(2,75)    #

                mycols = new qstringlist() 
                {
                    append("ABLE") 
                    append("BAKER")
                    append("CHARLIE")
                }
                    
                setHorizontalHeaderLabels(mycols)
                setAlternatingRowColors(true)
                    
                setStyleSheet("QHeaderView::section { background-color: aqua }")
                   
                horizontalHeader().setStyleSheet("color: blue")
                verticalHeader().setStyleSheet("color: red")  
                               
                cBox2List =[" ", "X", "Y", "Z", "W"]
                
                cBox2X = new qCombobox(Table2) { for i in cBox2List addItem(i,0) next setcurrentIndexChangedEvent($ObjectName+".pBox2X()") }
                cBox2Y = new qCombobox(Table2) { for i in cBox2List addItem(i,0) next setcurrentIndexChangedEvent($ObjectName+".pBox2Y()") }
                cBox2Z = new qCombobox(Table2) { for i in cBox2List addItem(i,0) next setcurrentIndexChangedEvent($ObjectName+".pBox2Z()") }
        
                setCellWidget(0, 0, cBox2X)
                setCellWidget(0, 1, cBox2Y)
                setCellWidget(0, 2, cBox2Z)   
                
                ###---------------------------
                ### Fill in Widget Table
                companyList = []
                
                aList = 
                [
                  [ "SPY",   "SP500",    "Index", 0, 109.24, 107.21 ],
                  [ "SDYL",  "SPDivs",   "ETF",   1, 152.33, 119.85 ],
                  [ "FB",    "Facebook", "Tech",  2, 143.34, 114.02 ],
                  [ "AMZN",  "Amazon",   "Cloud", 3, 154.80, 117.39 ],
                  [ "NVDA",  "Nvidia",   "Chips", 4, 287.49, 141.35 ],
                  [ "GOOGL", "Google",   "Cloud", 5, 126.70, 107.83 ]
                ]

                for x = 1 to 6
                    Add(companyList,  new Company { Symbolz=aList[x][1]  Namez=aList[x][2]  Groupz=aList[x][3]  Positionz=aList[x][4] Changez=aList[x][5]  Ratioz=aList[x][6]  } )
                next      

                ###------------------------------
                ### Put data in Widget Cells
                
                for x = 1 to len(companyList)               
                    
                    item1 = new qtablewidgetitem(companyList[x].Symbolz)
                    item2 = new qtablewidgetitem(companyList[x].Namez)
                    item3 = new qtablewidgetitem(companyList[x].Groupz)
                    item4 = new qtablewidgetitem("" + companyList[x].Positionz)
                    item5 = new qtablewidgetitem("" + companyList[x].Changez)
                    item6 = new qtablewidgetitem("" + companyList[x].Ratioz)
                    
                    setitem(x, 0, item1) 
                    setitem(x, 1, item2) 
                    setitem(x, 2, item3) 
                    setitem(x, 3, item4) 
                    setitem(x, 4, item5) 
                    setitem(x, 5, item6) 
    
                next
                
                setItem(1,3, new qTableWidgetItem("Item13") )
                setItem(3,1, new qTableWidgetItem("Item31") )               
          
            }
            
            ###-----------------------     
        show()
    }
 
###-----------------------

    ###------------------------------------
    ### TABLE 2 Methods
    
    func pBox2X
        See "func pBox-2X: " + cBox2X.currentText() +" Index: "+  cBox2X.currentIndex() +nl
    return
            
    func pBox2Y
        See "func pBox-2Y: " + cBox2Y.currentText() +" Index: "+  cBox2Y.currentIndex() +nl
    return
    
    func pBox2Z
        See "func pBox-2Z: " + cBox2Z.currentText() +" Index: "+  cBox2Z.currentIndex() +nl
        
        Table2.item(5,3).setText("Changed03")
        See "  Item-R4-C1: " + Table2.item(4,1).text() +nl
        See "  Item-R5-C2: " + Table2.item(5,2).text() +nl
    return
    

 
Class Company 
   symbolz
   namez 
   groupz
   positionz 
   changez
   ratioz
   
######################################



Greetings,
Mahmoud
TwoClassesTwoWindows.ring

Bert Mariani

unread,
Sep 16, 2016, 1:49:57 PM9/16/16
to The Ring Programming Language
Hello Mahmoud

Thank you very much for modifying the program "Two Classes Two Windows" 
Showing how to use Class for separate windows.
I like it :D
I really appreciate it.

In order to find out what the first few lines were doing, I added some See statements.
The output helped me understand your code.

    $ObjectName   = "oFirstWindow"    ### Class FirstWindow ex. ($ObjectName+".pBox1A()")
    oFirstWindow  = new FirstWindow   ### Class called FirstWindow

    $ObjectName   = "oSecondWindow"   ### Class SecondWindow ex. ($ObjectName+".pBox2X()")
    oSecondWindow = new SecondWindow  ### Class called SecondWindow


OUTPUT of SEE statements

===== ObjectName First: =====

oFirstWindow

===== oFirstWindow: ========

win1:      Object...
table1:    Object...
mycols:    Object...
cbox1list: List...

cbox1a:   Object...
n_sys_var_59175: 6.000000

i: 1.000000
cbox1b:   Object...
n_sys_var_59305: 6.000000

cbox1c:   Object...
n_sys_var_59435: 6.000000

ring_temp_object: Object...
ring_temp_object: Object...
ring_temp_object: Object...

===== ObjectName Second: ======

oSecondWindow

===== oSecondWindow: =========

win2:      Object...
table2:    Object...
mycols:    Object...
cbox2list: List...

cbox2x:   Object...
n_sys_var_60432: 6.000000

i: 1.000000
cbox2y:   Object...
n_sys_var_60562: 6.000000

cbox2z:   Object...
n_sys_var_60692: 6.000000

companylist: List...
alist:       List...
x: 7.000000 

ring_temp_object: Object...
ring_temp_object: Object...
ring_temp_object: Object...
ring_temp_object: Object...
ring_temp_object: Object...
ring_temp_object: Object...

item1: Object...
item2: Object...
item3: Object...
item4: Object...
item5: Object...
item6: Object...

ring_temp_object: Object...
ring_temp_object: Object...

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

Greeting
Bert Mariani

Bert Mariani

unread,
Sep 16, 2016, 2:42:15 PM9/16/16
to The Ring Programming Language
Hello Mahmoud

I modified the "TwoClass TwoWindows" program to use the same object names in each window.
They do not interfere with each other. Great !!!

I tried  using "symbolz"  in  class Window-1.
It did not interfere with the "Class Company symbolz"  in  class Window-2.  Great !!!

Then I tried using "symbolz" label  in class Window-2
It does interfere with the "Class Company symbolz
See image.

symbolz = "Inside Win-2 symbolz"  ### shows OBJECT: symbolz: GOOGL  --- R6C0 = NULL instead of GOOGL --- Column 0 ALL = NULL
...
...
Add(companyList,  new Company { Symbolz=aList[x][1] ...
item1 = new qtablewidgetitem(companyList[x].Symbolz)
setitem(x, 0, item1) ...

"symbolz" as a member of the "Class Company"  is not the same as "symbolz" as a label used elsewhere.
I think Ring should make the distinction.





OUTPUT


===== oSecondWindow: =========

win2: Object...
symbolz: GOOGL
table2: Object...
mycols: Object...
cbox1list: List...
cbox1a: Object...
n_sys_var_60453: 6.000000
i: 1.000000
cbox1b: Object...
n_sys_var_60583: 6.000000
cbox1c: Object...
n_sys_var_60713: 6.000000
companylist: List...
alist: List...
x: 7.000000
ring_temp_object: Object...
ring_temp_object: Object...
ring_temp_object: Object...
ring_temp_object: Object...
ring_temp_object: Object...
ring_temp_object: Object...
item1: Object...
item2: Object...
item3: Object...
item4: Object...
item5: Object...
item6: Object...
ring_temp_object: Object...
ring_temp_object: Object...

===================
AA-Table-17c-TwoClassesTwoWindows.ring

Mahmoud Fayed

unread,
Sep 16, 2016, 5:52:34 PM9/16/16
to The Ring Programming Language
Hello Bert

This is the expected behavior according to the scope rules.

In this region in the class we have three scopes
Global Scope ---> Global Scope
Object Scope ---> Object Scope
Local Scope ---> Object Scope 

Since the local scope point to the object scope also, we can use braces to access objects (by switching the object scope) and still have access to the object scope through the local scope.

Now when Ring find a variable
Search in local scope first then object scope then global scope

The local scope in this region point to the object scope of the current class 
Solution to refer to the attribute of the company class use

Self.symbolz

Because self. means (pass the local scope and use the object scope) 
Here the object scope (after using braces) means the company class attributes 
While the local scope (that we pass) means the form/window class attributes

Greetings,
Mahmoud

Marino Esteban Liranzo Cruz

unread,
Sep 16, 2016, 7:24:34 PM9/16/16
to The Ring Programming Language
Hello Mr. Mahmoud Fayed,

I'm here raining sobremojado; but I have some gaps regarding scopes. To try to understand correctly the fear will show the following doubts.

1- When I have a LineEdit and I want you on this one setTextChangedEvent is done by activating a method in which a mathematical operation is carried out; but the results of this operation will manifest in another LineEdit control which is different object.

If you see the picture shown, I have a LineEdit front of the label "Walls Partitions" indicated by the number 1 represented by a "Murod" in the code, object the result should appear in the LineEdit indicated by number 3, represented in the code with "Wtot" object.

In the attached code vera details.


Greetings
Marino Liranzo


clsDatosG2.ring
picclsDatosG2.jpg

Bert Mariani

unread,
Sep 16, 2016, 7:34:26 PM9/16/16
to The Ring Programming Language
Hello Mahmoud

Exactly how and where do I use "self.Symbols" in the code
I tried a few places but was not successful. The Win-2 widget table still shows "NULL" in column 0
Can you modify the code, thanks.


========

Class SecondWindow

    win2 = new qwidget() 
    {       
symbolz = "Inside Win-2 symbolz"  ### shows OBJECT: symbolz: GOOGL  --- R6C0 = NULL instead of GOOGL --- Column 0 ALL = NULL
...
...
    for x = 1 to 6
                    Add(companyList,  new Company { Symbolz=aList[x][1]  ......
     next
...
...
       ###------------------------------
       ### Put data in Widget Cells
                
       for x = 1 to len(companyList)                               
             item1 = new qtablewidgetitem(companyList[x].Symbolz)
...
...
Class Company 
   Symbolz      ###  AddAttribute(self,"symbolz") --- self.symbolz
   Namez 

==============
AA-Table-17c-TwoClassesTwoWindows.ring

Mahmoud Fayed

unread,
Sep 17, 2016, 1:17:51 AM9/17/16
to The Ring Programming Language
Hello Marino

The code contains the next two problems

(1) Conflict between global variables and class attributes

where you defined the next global variables

cbox1 =NULL win2 = Null

hbox = Null

abox = Null

line2 = Null

line3 = Null

wTot=Null

pTotal=Null


Then in the class (after the class name)

Class NuevoDatos
 pesoL pesoF pesoE pesoM

win2 cbox1 hbox abox line1 line2 line3 line4 line5 line6  Elos Efno Enc Emo

 wLos wFin wEnc wMo PesoL PesoF PesoE PesoM muroD wVar wTot


In the previous code, if the attribute name is the same as the global variable, it will not be defined and the global variable will be used

Solution(1) : Remove the global variables  (if the global variable and the attribute mean the same thing)
Solution(2):  Change the global variable name (use the $ mark before global variables names) (if they are different variables).

(2) Using braces inside class method (this change the object scope) then trying to access the object attribute (you have changed the object scope and you don't have access to it)

    Func pDatos

       win2 =  new qwidget() {

               setWindowTitle("Datos Generales")

               setWinIcon(self, "imagenes/loguito.png")

               move(200,150)

               resize(500,350)

               fr1 = new qFrame(win2,2) {

                        move(10,10)

                       resize(480,45)

                       setFrameStyle (QFrame_Sunken| QFrame_StyledPanel)

               }      

                fr2 = new qFrame(win2,2) {

                       move(10,65)

                       resize(250,245)

                       setFrameStyle (QFrame_Plain| QFrame_StyledPanel)

               }

               cbox1 = new qCombobox(fr2) {


In the previous code, In the start of pDatos method you have access to the object attributes like cbox1

But once you have used braces (you changed the object scope) and lost the access to cbox1
 win2 =  new qwidget() {

this happens after the previous line where you access qWidget attributes and methods instead of NuevoDatos attributes and methods.

Solution(1) : Don't use braces when you need to access the NuevoDatos attributes and methods 
Solution(2) : Use another way to convert programs that uses global variables and functions to classes, objects and methods

Greetings,
Mahmoud

Mahmoud Fayed

unread,
Sep 17, 2016, 1:21:37 AM9/17/16
to The Ring Programming Language
Hello Bert

I mean in this line
new Company { Symbolz=aList[x][1]

to be  self.Symbolz 

Case : Conflict between Class Attributes and Local Variables
 

        func main
              name = "nice"
          o1 = new person {name="mahmoud" address="Egypt"  phone = 000 }
         see o1

        class person
           name
           address
        phone



 In the previous example we have the local variable name.

The value of this variable will be set to "mahmoud" instead of the object attribute.

Solution : Just use Self 

        func main
          name = "nice"
          o1 = new person {self.name="mahmoud" address="Egypt"  phone = 000 }
          see o1

        class person
           name
          address
          phone


Greetings,
Mahmoud

Bert Mariani

unread,
Sep 17, 2016, 2:57:39 PM9/17/16
to The Ring Programming Language
Hello Mahmoud

I had tried the self.Symbolz in the place where you suggested.
It does not work.
Attached  is the modified code  with screen captures.

If the code refers to  a "Class Person -> Member"
Then the compiler should only look for that  Person->Name in the Class called Person with a Member called Name.


         o1 = new person {name="mahmoud" address="Egypt"  phone = 000 }
         see o1

        Class Person
           name

----------------
symbolz = "Inside Win-2 symbolz" 
...
for x = 1 to 6
    Add(companyList,  new Company 
          { self.Symbolz   = aList[x][1]  
            self.Namez     = aList[x][2]  
            self.Groupz    = aList[x][3]  
            self.Positionz = aList[x][4] 
            self.Changez   = aList[x][5]  
            self.Ratioz    = aList[x][6] 
          }
       )
next      
...
Class Company
   Symbolz   
   Namez 
   Groupz
   Positionz 
   Changez
   Ratioz

-----------------

Bad output. Column 0 has all "NULL"s.  should be actual Symbolz



Correct output should look like this. Column 0 has proper Symbolz



------


BAD Output   ===== oSecondWindow: =========

win2: Object...
symbolz: GOOGL
table2: Object...
mycols: Object...
cbox1list: List...
cbox1a: Object...

Correct Output  ===== oSecondWindow: =========

win2: Object...
table2: Object...
mycols: Object...
cbox1list: List...
cbox1a: Object...

----------------------
AA-Table-17c-TwoClassesTwoWindows-SelfConflict.ring

Mahmoud Fayed

unread,
Sep 17, 2016, 5:25:18 PM9/17/16
to The Ring Programming Language
Hello Bert

Very nice question, It's just another type of conflict, thanks for discovering it.

The next code solve it

 for x = 1 to 6


                 companyList +  new Company  


                 companyList[len(companyList)] {


                            companyList[len(companyList)].Symbolz   = aList[x][1]                  


                            Namez     = aList[x][2]  


                            Groupz    = aList[x][3]  


                            Positionz  = aList[x][4]


                            Changez   = aList[x][5]  


                            Ratioz    = aList[x][6]


                          }                      


  next      



Description

In this region after the class name we have
global scope ---> global scope
object scope ----> object scope
local scope ----> object scope

when we uses braces and change the object scope, we still have access through the local scope 

Ring search in the local scope first (here the local scope point to the window class )

****New Information****

Since the local scope point to the window class, using self will point to the window class (not the company class)

Solution : In this case of conflict don't use self to solve it (because we have conflict in self itself)
Use the list item to determine the object.

Another solution 
  Create a method in the company class and pass parameters to this method and let it modify the class attributes.

Another solution
   Keep your code the same and remove the Symbolz attribute from the window class.

Greetings,
Mahmoud

Mahmoud Fayed

unread,
Sep 17, 2016, 6:04:17 PM9/17/16
to The Ring Programming Language
Hello Bert

Also Ring must gives error for the next code

  self.Namez     = aList[x][2]  
           self.Groupz    = aList[x][3]  
           self.Positionz = aList[x][4]
            self.Changez   = aList[x][5]  
           self.Ratioz    = aList[x][6]

Because self will refer to the window class
While Namez and others are not member of this class
they belong to the company class (that you get access to through braces)

You discovered a bug here, that i have already solved, Thanks for the report.

The bug description: When we uses self.attribute and the attribute is not found, Ring continue searching for the attribute in scope opened by braces and in the global scope too.
This is not correct and is fixed and the search will be only on the object attributed that we access using self.

Just build from the source code or download the last binary update

Greetings,
Mahmoud


On Saturday, September 17, 2016 at 5:57:39 PM UTC+3, Bert Mariani wrote:

Marino Esteban Liranzo Cruz

unread,
Sep 17, 2016, 11:03:48 PM9/17/16
to The Ring Programming Language
Hello Mr. Mahmoud Fayed,

Thank you with last explanation i solve the problem in the code.

Greetings
Marino Liranzo


Bert Mariani

unread,
Sep 18, 2016, 1:13:12 AM9/18/16
to The Ring Programming Language
Hello Mahmoud

Thank you for the updates which I downloaded.

Your suggested code worked.
It is more complex  (messy) and seems to be written to adapt it to the compiler.

The cleaner looking code does Not work.
It should. The compiler should adapt to written code.


=====================
Suggested Code

for x = 1 to 6
    companyList  + new Company       
    companyList[x] { companyList[x].Symbolz   = aList[x][1]      
                                    Namez     = aList[x][2]  
                                    Groupz    = aList[x][3]  
                                    Positionz = aList[x][4]
                                    Changez   = aList[x][5]  
                                    Ratioz    = aList[x][6]
                   }                      
next 
   
==============================
Cleaner looking code does Not work

for x = 1 to 6
     Add(companyList, new Company { Symbolz   = aList[x][1]  
                                    Namez     = aList[x][2]  
                                    Groupz    = aList[x][3]  
                                    Positionz = aList[x][4] 
                                    Changez   = aList[x][5]  
AA-Table-17d-TwoClWin-SelfConflict.ring
It is loading more messages.
0 new messages