我正在使用Fl_Tabs和一些自定义小部件为一个项目创建一个工具,其中包含一些其他自定义类。
我希望当鼠标在自定义小部件上拖动时,会出现一个工具提示,但实际上并没有发生。
我试图从几个方面检查解决方案,但我失败了,我认为我遗漏了一些东西:
-
我认为当指针被销毁时,工具提示会被释放,根据
help
:
每当您指定新的工具提示或小部件被销毁时,内部副本将自动释放。
由于指针位于Fl_Group内,我认为工具提示是自由的:但事实并非如此,正如下面的代码所示。
-
既然我凌驾于
handle
函数,这可能会干扰工具提示行为:但我只检查了
FL_PUSH
活动,我让其他人由FLTK管理。
下面可以找到一个代码片段
1.
重现我的问题:它有点长,但我想把我所有的元素都放在我的案例中。我正在使用FLTK 1.3.5,clang 14.0.0在配备蒙特利操作系统(12.6.1)的MacBook Pro上工作。
#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());
}
1.
这个例子的灵感来自
one
的
examples
在Erco的作弊页面上。