Skip to content

Add QComboBox#250

Merged
a7ul merged 2 commits intonodegui:masterfrom
elviosak:master
Dec 7, 2019
Merged

Add QComboBox#250
a7ul merged 2 commits intonodegui:masterfrom
elviosak:master

Conversation

@elviosak
Copy link
Copy Markdown
Contributor

@elviosak elviosak commented Dec 7, 2019

Only for strings for now, demo shows most functions, setMaxVisibleItems only works when editable is true (according to Qt docs looks like it is the native behavior)

@a7ul
Copy link
Copy Markdown
Collaborator

a7ul commented Dec 7, 2019

Amazing stuff @slidinghotdog

A handy trick that you can use for future is:

You could use this.setProperty (which is a method in QObject) to set properties.
this way you wont need to implement many methods in the C++ wrapper.

For example:

this.setProperty('iconSize', iconSize.native);

and
To know what the properties are:
https://doc.qt.io/qt-5/qcombobox.html#properties

So you could just call this.property("propertyname", propertyvalue) and that should do. This will save some time :)

Thanks for the PR. Merging this.

@a7ul a7ul merged commit ed84031 into nodegui:master Dec 7, 2019
@elviosak
Copy link
Copy Markdown
Contributor Author

elviosak commented Dec 7, 2019

Nice, i'll try that next time, looks like i can also use property() getter if the return value is a simple value or an implemented class right?

@a7ul
Copy link
Copy Markdown
Collaborator

a7ul commented Dec 7, 2019

Yes that is correct.

@elviosak
Copy link
Copy Markdown
Contributor Author

elviosak commented Dec 8, 2019

@master-atul i'm trying to use this.property() but it returns QVariant and QVariant.toBool() returns a string, is that correct?

toBool(): string {

@a7ul
Copy link
Copy Markdown
Collaborator

a7ul commented Dec 8, 2019

Hey @slidinghotdog
this.property('some property') would always return QVariant.
And with QVariant you can convert it to primitives like boolean, string, number, etc via

  • variant.toBool() - converts to boolean
  • variant.toString() - converts to string, etc

But also sometimes you need to get back complex objects like QRect, QPixmap, etc,, For these you would need to use the respective static methods like this.

const rect = QRect.fromQVariant(variant);
or

const pixmap = QPixmap.fromQVariant(variant);

etc.

@elviosak
Copy link
Copy Markdown
Contributor Author

elviosak commented Dec 8, 2019

@master-atul i was referring to the TS types here:

toInt(): string {

    toInt(): string {
        return this.native.toInt();
    }
    toDouble(): string {
        return this.native.toDouble();
    }
    toBool(): string {
        return this.native.toBool();

shouldn't they be changed?

@a7ul
Copy link
Copy Markdown
Collaborator

a7ul commented Dec 8, 2019

@slidinghotdog Thats definetly a mistake 🙈 Thanks for pointing out!
The js values that we get are correct. But typescript annotations are wrong

@a7ul
Copy link
Copy Markdown
Collaborator

a7ul commented Dec 8, 2019

Fixed in #255

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants