Git Product home page Git Product logo

Comments (2)

therecipe avatar therecipe commented on May 10, 2024 1

Hey

Here is some code that should work.
It intercepts the events that are send to the textEdit, so you can inspect them with the filterObject.
And here are some general infos about event filters.

Also you need to you run the [YOUR_PROJECT]/deploy/linux/[YOUR_PROJECT].sh file after you ran qtdeploy build/test desktop YOUR_PROJECT, otherwise you won't see anything in the terminal/shell.

Maybe you should also take a look at these examples and the qt docs.

Feel free to ask, if you run into any problems :)

package main

import (
    "os"

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

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

    var filterObject = core.NewQObject(nil)
    filterObject.ConnectEventFilter(func(watched *core.QObject, event *core.QEvent) bool {

        if event.Type() == core.QEvent__KeyPress {
            var keyEvent = gui.NewQKeyEventFromPointer(event.Pointer()) //like static_cast
            //var textEdit = widgets.NewQPlainTextEditFromPointer(watched.Pointer())

            if keyEvent.Key() == int(core.Qt__Key_Tab) {
                println("filterObject:", "special tab handling")
                return true
            }

            println("filterObject:", keyEvent.Text())
            return false
        }

        return false
    })

    var textEdit = widgets.NewQPlainTextEdit(nil)
    textEdit.InstallEventFilter(filterObject)
    textEdit.ConnectKeyPressEvent(func(event *gui.QKeyEvent) {
        println("textEdit:", event.Text())

        //do something here

        textEdit.KeyPressEventDefault(event) //call default implementation (always suffixed with *Default)
    })

    textEdit.Show()

    widgets.QApplication_Exec()
}

from qt.

testhmaa avatar testhmaa commented on May 10, 2024

Yes, the eventfilter code above has been tested to work fine. thanks for the help and documentation

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.