I have developed a graphic userinterface for a small program in c. Its some kind of calculator. I have two inputfields where one can enter numbers and I want to display the result as a text-label in the same window.
I do not know how to make the window or the text-label to update itself. I am used with GUIS in java and there are a method called invalidate() to refresh the window and its child-items? Is there a similar function in the gtk3-lib in c?
I don't understand. I think there is a button to press after entering numbers in inputfields, am i right? If so, just connect a function to the button clicked signal.
This function make the sum of 2 numbers and set the label text.
If you don't have the button, i think you need to connect the signal to the inputfields, something like:
"on_spinbutton1_value_changed" : update_text_label
P.S.
I don't know C, usally i use python, but i think is quite similar.
P.P.S.
Is this the same question founded here?
Related
I am more or less a complete beginner, so please excuse me if that Question does come across as too easy, but I try to create in QT an Array of Bottons. It should look similarly to the Minesweeper Game. Is there another way than to create every single butto or even have, when the program is running, the user choose how big the Array is, for example an 8x8 field.
My Goal is in the end that the user can make somewhat like a map where he can Color each button in the Array differently, but it would be really helpful if someone could tell me just how to create the Array. If possible in Detail, because I am not that used to work with QT or C++.
You can use nested QVector instead of arrays to save your buttons, and here is a peace of code which creates 8*8 buttons view on Qt MainWindow and saves the buttons in QVector, it may help
QGridLayout* layout = new QGridLayout();
ui->centralwidget->setLayout(layout);
QVector<QVector<QPushButton*>> buttons2DVector(8);
for (int i=0;i<8;i++){
buttons2DVector[i].resize(8);
for(int j=0;j<8;j++){
QPushButton *b = new QPushButton("button");
layout->addWidget(b,i,j);
buttons2DVector[i][j] = b;
}
}
Then you can easily access any of your buttons using
buttons2DVector[rowNum][columnNum]->func();
I am having problems with using a camera in OpenGL/freeGLUT. Here is my code:
http://pastebin.com/VCi3Bjq5
(For some reason, when I paste the code into the code feature on this site, it gives extremely weird output.)
As far as I can tell this should rotate the camera when arrow keys are pressed - but it does nothing. It also seems that even the initial camera position is wrong. Any clue why this is?
The display function is only called once. You need to either set an idle function with glutIdleFunc() or tell GLUT that the display function must be called again with glutPostRedisplay().
The flowchart I'm making doesn't look right. I've looked in my textbook for examples, but they don't seem to apply to this particular assignment. The pseudocode is right, because the Java is right, but the flowchart just looks wrong.
In this assignment the program is to display an array of items (iPod, Xbox, etc.) by using an array. The program is to ask the user which items they would like to order. The user is to enter the item. The program displays "In Stock". Then the program replaces the item from the array with an empty string. The program asks the user if they would like to make another order. If the user enters in the same item, the message "Out of Stock" is displayed.If the user enters another item, the same process repeats. (While loop) Entering the the word "No" ends the program.
You can see all this in the pseudocode, I just thought writing it all out might be easier. (Or not, maybe it just took extra work reading it.)
(Click image to enlarge)
I'm no flowchart guru, but I see that you have the 2nd WHILE as a conditional diamond with the loop completely under it. How does it ever escape that loop? The flow should always come into the top of the diamond, with the exit options on either side. This means that the first WHILE is wrong too.
Also, the third WHILE only has a single exit. And the same for the IF underneath it.
For all of these test/condition diamonds the flow should come in the top and exit either side.
I'm trying to make a simple text editor with winapi, its working for simple letter, but its not with capital letter or shift key.
char keys[256];
int x = 0;
while (1)
{
for (x = 0; x <= 256; x++)
{
if (GetAsyncKeyState(x) == -32767)
{
char c[5];
GetKeyboardState(keys);
ToAscii(x, MapVirtualKey(x, 0), keys, c, 0);
putchar(c[0]);
}
}
}
The behaviors of keyboard input are far more complex than what you think. Your method doesn't work because:
GetAsyncKeyState can miss keys. What happens when the user hits a key between calls?
What happens when you hold down a key? What about keyboard repeat?
Most critically, your code assumes a 1:1 relationship between key and character. You don't have any mechanism to deal with combinations like shift / caps lock state, or dead keys.
It would be better if you tried to explain what you're trying to do, and you can get advice on the right way to approach it. Trying to re-invent the behaviors of such a fundamental input device is not likely to be the best approach.
GetAsyncKeyState is likely not the way to go here: the real way to make a text editor type control is to instead handle the WM_KEYDOWN and WM_CHAR messages. Windows will send these to your WndProc when your HWND has focus. This is the technique used by the Windows EDIT and RichEdit controls.
Use WM_KEYDOWN to handle the non-character keys - like arrows (VK_LEFT, VK_RIGHT), page up and so on; and use WM_CHAR for text characters. WM_KEYDOWN tells you the key pressed using a VK_ value, and doesn't take shift state into account; while WM_CHAR does take shift state, so gives you 'A' vs 'a' or '1' vs '!' as appropriate. (Note that you have to have TranslateMessage in your messsage loop for this to happen.)
Having said all that, an even easier/better thing to do is just use the existing Windows EDIT or RichEdit controls and let them do the work for you - there's rarely a good reason to reinvent the wheel - unless you're playing around for fun and learning Win32 perhaps. Writing a proper text editor is pretty complex; there's a lot of non-obvious stuff to consider, especially when you get into non-English text: you'd need to ensure it works correctly with right-to-left text (Arabic, Hebrew), works with IMEs which are used to enter Japanese and Chinese characters. And you have to ensure that your control is accessible to screenreaders so that users with visual impairments can still use the control. EDIT and RichEdit do all this for you.
The actual Notepad app, for example, is just a wrapper for an EDIT control; while WordPad just wraps a RichEdit control; both let the control do all the hard work, and just add the extra UI and file save/load functionality on top.
Try to call
GetKeyState(VK_CAPITAL);
before
GetKeyboardState(keys);
I am creating printouts in WPF using flow documents. These printouts are set in separate window where DocumentViewer is placed.
When user clicks print I would like to show a progress bar that informs about current page that is sending to the printer. How can I do this?
I'm not sure exactly where your print code is, or where you want the progress bar, but I did something similar to this recently. This will be in VB.net.
First of all, create a new progressbar in the same class as the code you use to send the page to the printer. Then, we're going to take advantage of the "top-down" order in a block of code to change the progress bar.
The progress bar's value should be set to "0" be default. Now, in the code for sending the page to the printer, you're going to increase the progressbar's value (such as with the code "MyProgressBar.Value = MyProgressBar.Value + 1"). Put this code in between each line of the code you want to show progress for.
I would change the "+ 1" part of the code, however, to another value, so your progress bar progresses equally after each step. If you have three lines of code, then use "+ 33" (100\3), four lines use "+ 25", etc.
Finally, at the end of the code, set "MyProgressBar.Value = 100"
This only works, however, if you have access to a code longer than one line. For one line of code, I'm not sure how this works, unless you can get to the block of code that line points to.
If you have to use code from another class, you may need to do something like...
Dim MyWindowWhereProgressIs As New MyWindowWhereProgressIs
And then, each time you need to change the value, try...
MyWindowWhereProgressIs.MyProgressBar.Value = MyWindowWhereProgressIs.MyProgressBar.Value + 1
I'm not entirely sure whether or not those last two lines of code will work, as I'm away from Visual Studio right now, but it is worth a shot.