gpt4 book ai didi

c++ - 带图像的FLTK按钮

转载 作者:行者123 更新时间:2023-12-02 10:24:55 36 4
gpt4 key购买 nike

我正在尝试使用列表中的图像创建按钮。我希望按钮居中。我的代码如下。我不断收到错误消息“在'image'中请求成员'W',它是非类类型'Fl_GIF_Image(const char *)”。我不确定该怎么做。我以为这可以提供图像的宽度。有任何想法吗?

//
// source.cpp
// labapril20
//
// Created by Kate Godfrey on 4/20/17.
// Copyright (c) 2017 Kate Godfrey. All rights reserved.
//

#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Button.H>
#include <FL/Fl_GIF_Image.H>
#include <iostream>
#include <time.h>
#include <vector>
#include <cstdio>

using namespace std;

int main(int argc, char **argv) {
srand(time(NULL)); // set random seed based on current time
vector<string> filenames {"cloudy.gif","fog.gif","lightning.gif","partsunny.gif","rain.gif","sunny.gif"};

string filename = filenames.at(rand() % filenames.size()); // get randome filename
cout << "Image File: " << filename << endl; // for debugging

// Start add code for image on button
Fl_GIF_Image image(const char* filename);

Fl_Window *window = new Fl_Window(image.W(), image.H());

Fl_Button *button = new Fl_Button(0, 0, image.W(), image.H(), filename);
//button->image();

//cout << image.w() << "X" << image.h() << endl; // for debugging

// End code for image on button
window->end();
window->show(argc, argv);
return Fl::run();



}

最佳答案

要找到一个也参加摩尔博士类(class)的人并不容易
试试这个

Fl_Window* w = new Fl_Window(340, 180);
Fl_GIF_Image* gif = new Fl_GIF_Image("fog.gif");
Fl_Button* Btn01 = new Fl_Button(20,40,gif->w(),gif->h());
Btn01->image(gif);

希望它有效!

关于c++ - 带图像的FLTK按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43593658/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com