is there a way to write an if statement in an fltk project such that it looks at the colour of an Fl_Box, and then returns a value?
Something like this:
if(color(Fl_Box)==FL_Blue)
{int i=0}
Thanks in advance.
Sure, all widgets have the color() function (see http://www.fltk.org/doc-1.3/classFl__Widget.html#a03c07e0725994cddf9070f9f1cd215c4 ).
If you look in Enumerations.H in the FLTK includes folder is has const Fl_Color FL_BLUE = 216; so you would want to use FL_BLUE and naturally you would need to actually have a pointer to the widget in question so you would have
if (some_box->color()==FL_BLUE)
where somewhere else in your code you have
Fl_Box* some_box;
some_box = new Fl_Box(x,y,w,h,"Name");
Related
I have a problem right now with my mini-game I am making. The problem is as follows: I have created an level editor for my game and thus I had to create my own delegate and model, the problem occurs when I try to edit through a shapeeditor ( which more likely creates a painterpath ). I then return the painterpath through data but when I try to paint it with my delegate, qt tells me the following error:
/usr/include/qt4/QtCore/qmetatype.h:169: error: 'qt_metatype_id' is not a member of 'QMetaTypeId<QPainterPath>'
I am not quite sure why I am having this error. For information regarding the source code of the project, I can give if needed. But I am simply thinking the conversion from qvariant to qpainterpath isn't possible. They must be a way to do it.
Note: I tried to do the following
QVariant var = index.model()->data(index, Qt::DecorationRole);
QPainterPath path = var.value<QPainterPath>(); // The error occurs here, this is line 169
But this didn't work >.< Thanks if you can help me
Possible solution, is there anyway to create a pixmap from the painterpath? I could simply return the pixmap instead of the painterpath.
Looks like you need to use Q_DECLARE_METATYPE macro with QPainterPath
Like
Q_DECLARE_METATYPE (QPainterPath)
Here is documentation for the same.
straight to the point:
Im learning wxsmith and wxwidgets toolkit, i created some basic GUI containing one button and 2 static text fields. GUI is compilling ok so far. My frame name is proba2Frame, then im adding my own function which is not a member of any class but i declared in header file for proba2Frame that my function is a friend. Below is code of my function:
wxStaticText * dawajpointera()
{
wxStaticText * text;
text = proba2Frame.wxStaticText.StaticText1;
return text;
}
im getting error:
expected primary-expression before ‘.’ token
What exactly im doing wrong and how to get a pointer StaticText in case my solution is completely wrong ?
Thank You in advance
You make it sound like proba2Frame is the name of a class inheriting wxFrame?
If so, you're haveing problems because you haven't created an instance of proba2Frame, and you're trying to access a part of it that hasn't been constructed. Your main frame class is simply a template for your GUI, not the GUI itself.
The best way to go about it would probably be to take an instance of proba2Frame as a parameter-
wxStaticText* dawajpointera(proba2Frame *frame)
{
return frame->StaticText1;
}
Of course, that function itself was a bit pointless, but I'll assume that you're going to do something more involved with the pointer afterwards, and want it set to a pointer named text within the function for the sake of brevity.
void func(proba2Frame *frame)
{
wxStaticText *text = frame->StaticText1;
// Do something with text
}
If you're doing this, though, please consider making the function a method of proba2Frame.
wxStaticText is the name of a wxWidgets class. You should not be naming attributes of your frame 'wxStaticText'. Despite the code you have posted, I doubt that you have really done such a terrible thing. What you probably meant to write, I would guess, is:
text = proba2Frame.StaticText1;
I am guessing that the name of the attribute is StaticText1, a pointer to an instance of the wxStaticText class.
I want to change the font of the richedit control in my win32 program to Consolas. When i try to do the following:
CHARFORMAT2 cformat;
cformat.dwMask = CFM_FACE;
cformat.cbSize = sizeof(cformat);
cformat.szFaceName = "Consolas";
On the last line it says that
Expression must be modifiable value
What is the problem here?
Regards,
Devjeet
From the documentation, you can see that szFaceName is an array. You cannot assign to an array that way. (That's what the compiler is trying to tell you. You're trying to assign "Consolas" to something that cannot be modified in that way.) You need to use a string copy function.
I'm new to C++ and never used macros before but I beleive they may allow me to solve the following problem although I would welcome alternative solutions.
I have written the following macro:
#define COMMAND(NUMBER){ button_ ## NUMBER ## ->hide(); }
and I want to call it like this
for (int i = 1; i < 10; i++)
{
COMMAND(i)
}
in the hope that when the program executes it would do the equivalent of:
button_1->hide();
button_2->hide();
button_3->hide();
button_4->hide();
.
.
button_10->hide();
The idea is that I want to make a FLTK GUI display/hide widgets dynamically depending on a configuration file being read in when the form is loaded.
Unfortunately it appears that the macro above doesn't work and instead what it does is
button_i->hide();
which causes a compile error because button_i doesn't exist!
So my questions are:
A) Is it possible to do this in C++?
B) Is a macro able to accomplish this?
C) If not what can?
D) If macros can do this then how do I amend the above code to actually get it to work!
Thanks
I'm pretty sure there is a way to make a macro trick work, but there are better options.
You can, for example, store your buttons in an array.
Assuming your buttons have a type called struct button, declare your buttons like this:
struct button *buttons[42];
You need to initialize all of them as you would have for your individual button_X variables.
button[i] = <whatever you do to create button number i>;
Then you can simply do:
for (int i=0; i<42; i++) {
button[i]->hide();
}
Or toggle any individual button with just its number. You'll probably find that better than any macro trick in the long run.
(Warning: arrays are 0-based, so your first button is button[0])
If you have control over the button_2 etc. variables, I would recommend using an array instead. That way you could use a look like:
for (int i = 1; i < 10; i++)
{
button[i]->hide();
}
Of course, this is trivial to place in a macro.
In general, you can't accomplish what you want with a plain loop in C. However, if you really want to go that route, look at the boost preprocessor package.
Do not try to manage the buttons yourself, FLTK does not like that. You will have an awesome array of buttons that you cannot see. I am not sure how to do it the way you want but I would do it this way:
Fl_Button * o = (Fl_Button *)myWindow->child(i);
o->hide();
and let the buttons be children of the FLTK window.
I'd like to use the autorepeat feature of the QToolButton class.
The problem is that the instances are created automatically when using QToolBar::addAction() and I can't find a way to reach them: QToolBar::widgetForAction() doesn't seem to work in that case (always returns NULL).
Any ideas?
Thanks
There seem to be no simple way. The best I found is to use QObject::findChldren :
foreach(QToolButton* pButton, pToolBar->findChildren<QToolButton*>()) {
if (pButton->defaultAction() == pTheActionIWant) {
...
}
}
In fact, in my case doesn't return NULL, maybe you are doing something different. My code is as follows:
QToolButton* button = dynamic_cast<QToolButton*>(
ui.toolBar->widgetForAction(ui.action));
For me it works as intended.... Maybe you aren't casting? This method returns a QWidget* and my compiler issues and error if I don't cast.
FYI, I'm using Visual Studio 2005 with Qt 4.6.