FLTK自定义组件中Tooltip无法正常显示的问题求助
自定义FLTK组件Tooltip无法显示问题
我正在使用Fl_Tabs及自定义组件开发项目工具,这些自定义组件依赖其他自定义类。目前遇到的问题是:鼠标悬停在自定义组件上时,Tooltip无法正常显示。我尝试了多种排查方式但未解决,认为遗漏了关键细节:
- 根据FLTK官方文档说明:
The internal copy will automatically be freed whenever you assign a new tooltip or when the widget is destroyed.
我曾误以为组件处于Fl_Group内时Tooltip会被释放,但实际并非如此,如下方代码所示。 - 由于我重写了handle函数,虽仅处理FL_PUSH事件,其余事件均交由FLTK原生处理,但仍怀疑这会影响Tooltip的行为。
以下是可复现该问题的代码片段,包含了场景中的所有元素:
#include <FL/Fl.H> #include <FL/Fl_Window.H> #include <FL/Fl_Tabs.H> #include <FL/Fl_Group.H> #include <FL/Fl_Button.H> #include <FL/Fl_Box.H> #include <iostream> class Action{ public: Action(std::string name, int cInit){ _name = name; _counter = cInit; }; void increment(){ _counter++; }; std::string message(){ increment(); return _name + " Counter: " + std::to_string(_counter); }; private: std::string _name; int _counter; }; class MyButton: public Fl_Box{ public: MyButton(int X, int Y, int W, int H, Action* A, Fl_Box* mb, const char* L=0):Fl_Box(X,Y,W,H,L){ box(FL_UP_BOX); _mb = mb; _A = A; } int handle(int event){ switch(event) { case FL_PUSH: sendMessage(); return 0; default: return Fl_Widget::handle(event); } }; void sendMessage(){ _mb->copy_label(_A->message().c_str()); }; private: Fl_Box* _mb; Action* _A; }; int main(int argc, char *argv[]) { Fl_Window *win = new Fl_Window(500,300,"Tabs Example"); { Action* A = new Action("Trees",42); Fl_Box* B = new Fl_Box(10,210,150,50); B -> box(FL_UP_BOX); Fl_Tabs *tabs = new Fl_Tabs(10,10,500-20,200-20); { // Aaa tab Fl_Group *aaa = new Fl_Group(10,35,500-20,200-45,"Aaa"); { MyButton *b1 = new MyButton(50, 60,90,25,A,B,"Button A1"); b1->color(88+1); Fl_Box *b2 = new Fl_Box(50, 90,90,25,"Button A2"); b2->box(FL_UP_BOX); b2->color(88+2); Fl_Button *b3 = new Fl_Button(50,120,90,25,"Button A3"); b3->color(88+3); b1 -> copy_tooltip("b1: is it there?"); b2 -> copy_tooltip("b2: is it there?"); b3 -> copy_tooltip("b3: is it there?"); } aaa->end(); // Bbb tab Fl_Group *bbb = new Fl_Group(10,35,500-10,200-35,"Bbb"); { Fl_Button *b1 = new Fl_Button( 50,60,90,25,"Button B1"); b1->color(88+1); Fl_Button *b2 = new Fl_Button(150,60,90,25,"Button B2"); b2->color(88+3); Fl_Button *b3 = new Fl_Button(250,60,90,25,"Button B3"); b3->color(88+5); Fl_Button *b4 = new Fl_Button( 50,90,90,25,"Button B4"); b4->color(88+2); Fl_Button *b5 = new Fl_Button(150,90,90,25,"Button B5"); b5->color(88+4); Fl_Button *b6 = new Fl_Button(250,90,90,25,"Button B6"); b6->color(88+6); } bbb->end(); } tabs->end(); } win->end(); win->show(); return(Fl::run()); }
开发环境:FLTK 1.3.5、clang 14.0.0,设备为搭载Monterey系统(12.6.1)的MacBookPro。
内容的提问来源于stack exchange,提问作者Eddymage
相关产品推荐
相关产品推荐

