dropdown items text-align center in combobox

58 views
Skip to first unread message

kofa kofa

unread,
Jan 3, 2026, 4:11:58 AMJan 3
to The Ring Programming Language
hello everyone
how can i set   text-align center in combobox dropdown

Mahmoud Fayed

unread,
Jan 3, 2026, 11:31:52 AMJan 3
to The Ring Programming Language
Hello Kofa

>> "how can i set   text-align center in combobox dropdown"

See the next example

centeritems.png

Source Code:

load "guilib.ring"

new qApp {

        win1 = new qWidget() {

                setwindowtitle("Using QComboBox")
                setGeometry(100,100,400,400)

                new QComboBox(win1) {

// If you want to center the selected item
// setEditable(True)
// lineEdit().setAlignment(Qt_AlignHCenter)
// lineEdit().setReadOnly(True)

setGeometry(150,100,200,30)
alist = ["one","two","three","four","five"]
for x in aList
additem(x,0)
next

// Center items in the drop list
centerComboItems(self)

                }
 
                show()
        }

        exec()
}

func centerComboItems oComboBox

Qt_TextAlignmentRole = 7
property = new QVariant2(Qt_AlignHCenter)


oComboBox {
for t=1 to count()
setItemData(t-1,property, Qt_TextAlignmentRole);
next
}


Greetings,
Mahmoud

kofa kofa

unread,
Jan 4, 2026, 11:59:00 AMJan 4
to The Ring Programming Language
when i enable these settinge :

setEditable(True)

lineEdit().setAlignment(Qt_AlignHCenter)

lineEdit().setReadOnly(True)

the combobox button pressed not workng

kofa kofa

unread,
Jan 4, 2026, 12:00:47 PMJan 4
to The Ring Programming Language
i mean box of combobox pressed not working

Mahmoud Fayed

unread,
Jan 4, 2026, 12:09:15 PMJan 4
to The Ring Programming Language
Hello Kofa

>> "the combobox button pressed not working"

Yes, but you can click on the (down button at the right of the combobox to see the dropdown list)
It's a Qt behaviour.

If you want a workaround try padding by calling setStyleSheet() method on the QComboBox object

setStyleSheet("QComboBox {padding-left: 100px;} ")

Greetings,
Mahmoud

kofa kofa

unread,
Jan 4, 2026, 12:14:46 PMJan 4
to The Ring Programming Language
thank youUntitled.jpg

Mahmoud Fayed

unread,
Jan 4, 2026, 12:18:29 PMJan 4
to The Ring Programming Language
Hello Kofa

You are welcome :D

Greetings,
Mahmoud

kofa kofa

unread,
Jan 4, 2026, 12:19:13 PMJan 4
to The Ring Programming Language
May I suggest that the elements' properties be set to `false` and `true`?

For example: `

combobox.text-center=true`
`combobox.dropdowen.text-center=true`

Mahmoud Fayed

unread,
Jan 4, 2026, 12:23:41 PMJan 4
to The Ring Programming Language
Hello Kofa

You can use inheritance and create your library to customize RingQt


The goal behind RingQt is to be much close to Qt 
Then enable customization through external libraries

During PWCT2 development, I created my classes for the TreeWidget based on the software needs
The same could be applied for other applications


Greetings,
Mahmoud

kofa kofa

unread,
Jan 4, 2026, 12:36:10 PMJan 4
to The Ring Programming Language
thank you very much

Mahmoud Fayed

unread,
Jan 4, 2026, 12:41:24 PMJan 4
to The Ring Programming Language
Hello Kofa

You are welcome :D

Greetings,
Mahmoud

Reply all
Reply to author
Forward
0 new messages