Adding Separate Widgets into Layout
I've created 3 separate widgets(3different classes), I would like to add them into my QMainwindow in the 3 frames that I've created using the Qt designer. I cant seem to get it to work here is my main file hopefully someone could tell me whats wrong with it.
the 3 different classes are secret, decode & pick.
Thank you
Code:
int main(int argc, char *argv[])
{
Ui::MainWindow mainwindow;
mainwindow.setupUi(MyAppWindow);
mainwindow.
secretFrame->secret
(QWidget *parent
);
mainwindow.
boardFrame->decode
(QWidget *parent
);
mainwindow.
pickerFrame->pick
(QWidget *parent
);
MyAppWindow->show();
return app.exec();
}
Re: Adding Separate Widgets into Layout
well, fixing syntax error give this...
mainwindow.secretFrame->secret(parent);
mainwindow.boardFrame->decode(parent);
mainwindow.pickerFrame->pick(parent);
but since you dont have any 'parent' variable, or show what secret(), decode() and pick() do, it's impossible to tell you how to fix your code (which we cant see).
if you want to add widget(s) to a frame, you could put them in a layout and add the layout to the frame
Re: Adding Separate Widgets into Layout
here is one of my widgets
.h file
Code:
{
public:
//constructor
//declaration of private methods
string peg;
protected:
};
#endif
.cpp file
Code:
{
decodepeg(layout);
decodepeg(layout);
decodepeg(layout);
decodepeg(layout);
}
{
string pegs;
Peg *peg = new Peg();
cout<<"Choose a color for the SecretCode Pegs"<<endl;
cin>>pegs;
peg->colour(pegs);
layout -> addWidget(peg);
}
I'm getting an error at this part
Code:
mainwindow.
secretFrame->secret
(QWidget *parent
);
mainwindow.
boardFrame->decode
(QWidget *parent
);
mainwindow.
pickerFrame->pick
(QWidget *parent
);
of the main.cpp file
Re: Adding Separate Widgets into Layout
as I say - you get an error because that isnt valid c++.
Are you trying to call the constuctor directy? Because you wont be allowed to do that either.
Re: Adding Separate Widgets into Layout
is there a way to insert the entire class as a widget to the layout?
Re: Adding Separate Widgets into Layout
yes.
QLayout and its specialisations. read the docs.
Re: Adding Separate Widgets into Layout
Quote:
Originally Posted by
ashboi
I've created 3 separate widgets(3different classes), I would like to add them into my QMainwindow in the 3 frames that I've created using the Qt designer.
Then put them in the 3 frames you created in Designer using Designer. Drop a QWidget into each frame and promote it.
You really need to earn some basic C++ because lines 8 through 10 are not even close to being useful. Here are some questions to ask yourself:
- What type is Ui::MainWindow::secretFrame, boardFrame or pickerFrame?
- What functions and members are available in that type of object?
- Do those members include one called decode(), secret() or pick()?
- Where do you think the methods decode(), secret() or pick() are supposed to come from?
- What do they have to do with your class Decode? Does it have a method decode()?
- How would you pass a widget object to a decode() function if you had one?
As exercise you should read the code that uic generates from a simple Designer *.ui file.
Also read the documentation on ways to use a Designer Ui in your application especially the last paragraph of the "Direct Approach" section on the limits this imposes.