Hi All
I am writing a Qt program, I want to change color of my menu by pressing a key on keyboard. I wonder that , may i make the same effect by code not pressing on keyboard?
Infact how my i make call keypress event without pressing any key?
Hi All
I am writing a Qt program, I want to change color of my menu by pressing a key on keyboard. I wonder that , may i make the same effect by code not pressing on keyboard?
Infact how my i make call keypress event without pressing any key?
Look into QEvent(), QCoreApplication::sendEvent(), and QCoreApplication::postEvent()
Qt Code:
qApp->postEvent(objectThatHandlesKeypresses, ev);To copy to clipboard, switch view to plain text mode
But if you are only doing this to programatically change the color of a menu item, then it is wrong. You could directly call the function that does that.
I tried to do this but it didnt work? I wrote it to main function.
Qt Code:
gkdpr w; w.setGeometry(0,0,800,480); //w.setWindowFlags(Qt::FramelessWindowHint); w.show(); a.installTranslator(&w.translator); a.connect(&a, SIGNAL(lastWindowClosed()), &a, SLOT(quit())); return a.exec();To copy to clipboard, switch view to plain text mode
I wrote this code.I want to send keypress event to "w". Is it possible?
main.cpp:16: error: no matching function for call to ‘QCoreApplication::sendEvent(gkdpr&, QKeyEvent*&)’
/usr/include/QtCore/qcoreapplication.h:201: note: candidates are: static bool QCoreApplication::sendEvent(QObject*, QEvent*)
make[1]: *** [moc/main.o] Error 1
make: *** [x86] Error 2
make[1]: Leaving directory `/home/can/finalize/workspace/gkdpr'
Why don't you just trigger() the QAction object asociated with the menu entry?
Dear wysota,
I want to read a file and according to information in that file, I want to make this keypress effect by reading a file. I don't have any keyboard on my device. The other way i will use a serial port. According to information of this port i want to simulate this keypress events.
May I do this with QAction?
What do you need those events for? What is the goal of your piece of code?
Except main thread, I have an other thread ,Which is checking a file's content, in my program. According to it's content for example there is character 'A' or 'a' in this file. I want to make my program work as if it is pressed 'A' button on keyboard.
Ok, but why? What is it meant to do with the key press? I mean what is the point of the wholeoperation?
Bookmarks