Coder Social home page Coder Social logo

Connect Event parameters about qt HOT 3 CLOSED

therecipe avatar therecipe commented on September 24, 2024
Connect Event parameters

from qt.

Comments (3)

therecipe avatar therecipe commented on September 24, 2024

Hey

Yes, you are doing it right.
But, it's currently not possible to override virtual functions/events in parent classes.

So you can override the keyPressEvent in QWidget, but not in QListWidget.
I also stated some other limitations here: #9

package main

import (
    "os"

    "github.com/therecipe/qt/gui"
    "github.com/therecipe/qt/widgets"
)

func main() {
    widgets.NewQApplication(len(os.Args), os.Args)

    var widget = widgets.NewQWidget(nil, 0)
    widget.ConnectKeyPressEvent(keyPressEvent)
    widget.Show()

    widgets.QApplication_Exec()
}

func keyPressEvent(event *gui.QKeyEvent) {
    println("keyPressEvent:", event.Text())
}

I'm going to look into this now, maybe I will find a simple way to fix this.

from qt.

therecipe avatar therecipe commented on September 24, 2024

Okay, I pushed the changes.

This should work now:

package main

import (
    "os"

    "github.com/therecipe/qt/gui"
    "github.com/therecipe/qt/widgets"
)

func main() {
    widgets.NewQApplication(len(os.Args), os.Args)

    var listWidget = widgets.NewQListWidget(nil)
    listWidget.AddItems([]string{"some", "test", "labels"})
    listWidget.ConnectKeyPressEvent(keyPressEvent)
    listWidget.Show()

    widgets.QApplication_Exec()
}

func keyPressEvent(event *gui.QKeyEvent) {
    println("keyPressEvent:", event.Text())
}

But there are still some limitations, like not being able to call the default virtual implementation.

Feel free to ask, if you need some other functions added.

from qt.

5k3105 avatar 5k3105 commented on September 24, 2024

Wow. That was fast. Thank you for your help.

from qt.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.