Qt focusObjectChanged example?
Qt focusObjectChanged example?
我正在寻找一个示例,说明当接收到'focusObjectChanged'信号时,如何处理插槽接收到的QObject指针。我想知道如何识别获得焦点的对象?
文档指出指针指向的是焦点对象,但我怎么知道是哪个呢?
我试过在调试器中分析指针,但没有发现任何明显的东西。
您可以确定类和对象名称、小部件属性…:
QObject::connect(qApp, &QApplication::focusObjectChanged, [](QObject *obj){
if(obj) qWarning() << obj->metaObject()->className() << obj->objectName();
QWidget* widget = qobject_cast<QWidget*>(obj);
if(widget) qWarning() << widget->geometry(); // or other properties
BaseType* baseType = qobject_cast<BaseType*>(obj);
if(baseType) qWarning() << baseType->some_actions();
Type1* type1 = qobject_cast<Type1*>(obj);
if(Type1) qWarning() << type1->some_actions();
Type2* type2 = qobject_cast<Type2*>(obj);
if(Type2) qWarning() << type2->some_actions();
});
或者将指针与小部件指针进行比较,以找到您需要的小部件:
SomeClassSlot(QObject* obj) {
if(!obj) return;
if(obj == m_mainWindows) ....
if(obj->parent() == m_table) ...
MyClass myClass = qobject_cast<MyClass*>(obj);
if(myClass) myClass->some_method();
}
相关文章:
- 如何运行位于boost/libs/python/example/tutorial目录中的hello.cpp和Jamfil
- Qt focusObjectChanged example?
- 运行命令 "rosbag play example.bag" 时出错。找不到与插件 rosbag/NoEncryptor 对应的库
- QWebSocket Hello World Example
- c++ Doxygen example and description
- Example of CDocument::ReleaseFile for MFC
- 找不到 int com.example.nimashahbazi.mooshak.EncryptingActivity.
- Qt example const_cast
- TensorFlow C++ example for Android
- 运行"OpenPose C++ API Tutorial - Example 3 - Body from image"失败
- _Unwind_RaiseException example
- std::none_of example from cppreference.com
- Microsoft AMP for C++ with Dr Dobbs example?
- 在macOSX上编译boost_asio/example/ssl/server.cpp可以在Linux上工作
- Example for LVM_SUBITEMHITTEST
- Example of C++ 11 std::chrono::duration
- 重写 contiki 源代码“example-mesh.c”以根据计时器值发送消息
- boost::algorithm::boyer_moore_search OO example
- FSEvents C++ Example
- example of embarcadero WindowHandleToPlatform c++