Skip to content

Add QComboBox - #250

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

a7ul merged 2 commits into
nodegui:masterfrom
elviosak:master

Conversation

@elviosak

@elviosak elviosak commented Dec 7, 2019

Copy link
Copy Markdown
Contributor

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

a7ul commented Dec 7, 2019

Copy link
Copy Markdown
Collaborator

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

elviosak commented Dec 7, 2019

Copy link
Copy Markdown
Contributor Author

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

a7ul commented Dec 7, 2019

Copy link
Copy Markdown
Collaborator

Yes that is correct.

@elviosak

elviosak commented Dec 8, 2019

Copy link
Copy Markdown
Contributor Author

@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

a7ul commented Dec 8, 2019

Copy link
Copy Markdown
Collaborator

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

elviosak commented Dec 8, 2019

Copy link
Copy Markdown
Contributor Author

@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

a7ul commented Dec 8, 2019

Copy link
Copy Markdown
Collaborator

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

@a7ul

a7ul commented Dec 8, 2019

Copy link
Copy Markdown
Collaborator

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