Ok.. Here's the code:
main.cpp
#include <QtGui/QApplication>
#include "dialog.h"
int main(int argc, char *argv[])
{
Dialog dialog;
CNameDlg test;
dialog.addPage(&test);
return dialog.exec();
}
#include <QtGui/QApplication>
#include "dialog.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
Dialog dialog;
CNameDlg test;
dialog.addPage(&test);
return dialog.exec();
}
To copy to clipboard, switch view to plain text mode
dialog.cpp
#include <QtGui>
#include "dialog.h"
Dialog::Dialog()
{
this->setupUi(this);
}
void Dialog
::addPage(QWidget* page
) {
if (page)
{
vboxLayout->insertWidget(0, page);
page->show();
page->setFocus(Qt::OtherFocusReason);
}
}
{
this->setupUi(this);
}
#include <QtGui>
#include "dialog.h"
Dialog::Dialog()
{
this->setupUi(this);
}
void Dialog::addPage(QWidget* page)
{
if (page)
{
vboxLayout->insertWidget(0, page);
page->show();
page->setFocus(Qt::OtherFocusReason);
}
}
CNameDlg::CNameDlg(QWidget* parent) : QWidget(parent)
{
this->setupUi(this);
}
To copy to clipboard, switch view to plain text mode
dialog.h
#ifndef DIALOG_H
#define DIALOG_H
#include <QtGui/QDialog>
#include <QtGui/QLabel>
#include <QtGui/QLineEdit>
#include <QtGui/QVBoxLayout>
#include <QtGui/QWidget>
#include <QtGui/QApplication>
{
Q_OBJECT
public:
Dialog();
private:
{
if (Dialog->objectName().isEmpty())
Dialog
->setObjectName
(QString::fromUtf8("Dialog"));
Dialog->resize(535, 302);
Dialog->setFocusPolicy(Qt::StrongFocus);
verticalLayout
= new QWidget(Dialog
);
verticalLayout
->setObjectName
(QString::fromUtf8("verticalLayout"));
verticalLayout
->setGeometry
(QRect(10,
30,
511,
221));
vboxLayout
->setObjectName
(QString::fromUtf8("vboxLayout"));
vboxLayout->setContentsMargins(0, 0, 0, 0);
label
->setObjectName
(QString::fromUtf8("label"));
label
->setGeometry
(QRect(10,
10,
54,
18));
} // setupUi
};
{
Q_OBJECT
public:
{
if (CNameDlg->objectName().isEmpty())
CNameDlg
->setObjectName
(QString::fromUtf8("CNameDlg"));
CNameDlg->resize(410, 111);
CNameDlg->setFocusPolicy(Qt::StrongFocus);
label
->setObjectName
(QString::fromUtf8("label"));
label
->setGeometry
(QRect(10,
10,
250,
18));
m_name
->setObjectName
(QString::fromUtf8("m_name"));
m_name
->setGeometry
(QRect(10,
60,
240,
27));
} // setupUi
};
#endif
#ifndef DIALOG_H
#define DIALOG_H
#include <QtGui/QDialog>
#include <QtGui/QLabel>
#include <QtGui/QLineEdit>
#include <QtGui/QVBoxLayout>
#include <QtGui/QWidget>
#include <QtGui/QApplication>
class Dialog : public QDialog
{
Q_OBJECT
public:
Dialog();
void addPage(QWidget* page);
private:
QWidget *verticalLayout;
QVBoxLayout *vboxLayout;
QLabel *label;
void setupUi(QDialog *Dialog)
{
if (Dialog->objectName().isEmpty())
Dialog->setObjectName(QString::fromUtf8("Dialog"));
Dialog->resize(535, 302);
Dialog->setFocusPolicy(Qt::StrongFocus);
verticalLayout = new QWidget(Dialog);
verticalLayout->setObjectName(QString::fromUtf8("verticalLayout"));
verticalLayout->setGeometry(QRect(10, 30, 511, 221));
vboxLayout = new QVBoxLayout(verticalLayout);
vboxLayout->setObjectName(QString::fromUtf8("vboxLayout"));
vboxLayout->setContentsMargins(0, 0, 0, 0);
label = new QLabel(Dialog);
label->setObjectName(QString::fromUtf8("label"));
label->setGeometry(QRect(10, 10, 54, 18));
Dialog->setWindowTitle(QApplication::translate("Dialog", "Dialog", 0, QApplication::UnicodeUTF8));
label->setText(QApplication::translate("Dialog", "Test", 0, QApplication::UnicodeUTF8));
} // setupUi
};
class CNameDlg : public QWidget
{
Q_OBJECT
public:
CNameDlg(QWidget *parent = 0);
QLabel *label;
QLineEdit *m_name;
void setupUi(QWidget *CNameDlg)
{
if (CNameDlg->objectName().isEmpty())
CNameDlg->setObjectName(QString::fromUtf8("CNameDlg"));
CNameDlg->resize(410, 111);
CNameDlg->setFocusPolicy(Qt::StrongFocus);
label = new QLabel(CNameDlg);
label->setObjectName(QString::fromUtf8("label"));
label->setGeometry(QRect(10, 10, 250, 18));
m_name = new QLineEdit(CNameDlg);
m_name->setObjectName(QString::fromUtf8("m_name"));
m_name->setGeometry(QRect(10, 60, 240, 27));
} // setupUi
};
#endif
To copy to clipboard, switch view to plain text mode
and finally focus.pro
HEADERS = dialog.h
SOURCES = dialog.cpp \
main.cpp
# install
target.path = .
sources.files = $$SOURCES $$HEADERS *.pro
sources.path = .
INSTALLS += target sources
HEADERS = dialog.h
SOURCES = dialog.cpp \
main.cpp
# install
target.path = .
sources.files = $$SOURCES $$HEADERS *.pro
sources.path = .
INSTALLS += target sources
To copy to clipboard, switch view to plain text mode
Note that some of the code was copied from the compile of the .ui files I have.
If you compile & run this, you'll have a dialog, with a label ("test") and an QLineEdit. The QLineEdit is +not+ the focus.
Vycke
Bookmarks