[Solved]Custom Widget?
-
Hello,
How do I create a simple widget that would contain a first, middle and last name field and add it to the main window class?
I ask because I cant figure out why is this simple widget attempt below is not working, what have I missed?
main
@int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();return a.exec();
}@
mainWindow class
@MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent){
QMainWindow *mainView = new QMainWindow;
setCentralWidget(mainView);CardUI *card = new CardUI; QHBoxLayout *hCard = new QHBoxLayout; hCard->addWidget(card); mainView->setLayout(hCard); mainView->show();
}@
cardui class
@CardUI::CardUI(QWidget *parent) : QWidget(parent){
QLineEdit *fnText = new QLineEdit;
QLineEdit *miText = new QLineEdit;
QLineEdit *lnText = new QLineEdit;QHBoxLayout *name = new QHBoxLayout; name->addWidget(fnText); name->addWidget(miText); name->addWidget(lnText); setLayout(name);
}@
-
From "Sack Overflow":http://stackoverflow.com/questions/11872210/custom-qt-widget/11872467#11872467:
bq. You should not change layout of QMainWindow. Use setCentralWidget or add toolbars/docks using given API instead. In this particular case you shouldn't create mainView as QMainWindow (you cannot have two main windows in one application, right?). You can change mainView type to QWidget, but you can even don't create any proxy widgets, and just
@MainWindow::MainWindow(QWidget *parent); : QMainWindow(parent){
card = new CardUI;
setCentralWidget(card);
}@