How to customize a class, for use in our program
-
Did as told . This is code for main class.
@
DemoApp::DemoApp(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::DemoApp)
{
TabDialog *tabdialog =new TabDialog();ui->setupUi(this); modifyUi(this); tabdialog(this);
}
@
getting 'tabdialog' cannot be used as a function
-
@o6a6r9v1p tabdialog is a pointer, what do you want to achieve if you write tabdialog(this)?
-
jsulm Lifetime Qt Championreplied to o6a6r9v1p on 1 Feb 2017, 07:49 last edited by jsulm 2 Jan 2017, 07:50
@o6a6r9v1p TabDialog is a dialog, that means it is going to be its own window. If you want to put the stuff from TabDialog into your main window then do not add it to your project but copy its code and put it into your main window.
-
-
@o6a6r9v1p
it uses tabWidget -
@o6a6r9v1p Well just put that code in a private method in your main window and call it in the constructor.
The thing is: TabDialog is a dialog. Do you want to use it as such in your app (means: do you want to show a dialog window in your app)? -
@jsulm
TabDialog is a class constructor & is used to build top level Tabbed windows.
This in turn uses 3 more classes, each class used to build one tab of the window.
the code for TabDialog is
@
TabDialog::TabDialog(const QString &fileName, QWidget *parent)
: QDialog(parent)
{
QFileInfo fileInfo(fileName);tabWidget = new QTabWidget; tabWidget->addTab(new DashBoardTab(fileInfo), tr("DashBoard")); tabWidget->addTab(new SettingsTab(fileInfo), tr("Settings")); tabWidget->addTab(new ValuesTab(fileInfo), tr("Values")); buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); QLabel *fileNameLabel = new QLabel(tr("File Name:")); QLabel *label_Status = new QLabel(tr("Status")); label_Status->setObjectName(QString::fromUtf8("Status")); label_Status->setEnabled(true); label_Status->setGeometry(QRect(410, 10, 41, 21)); label_Status->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter); QLineEdit *deviceConnectedStatus = new QLineEdit(); deviceConnectedStatus->setObjectName(QString::fromUtf8("deviceConnectedStatus")); deviceConnectedStatus->setEnabled(true); deviceConnectedStatus->setGeometry(QRect(20, 10, 391, 20)); deviceConnectedStatus->setReadOnly(true); QHBoxLayout *statusLayout = new QHBoxLayout; statusLayout->addWidget(deviceConnectedStatus); statusLayout->addWidget(label_Status); connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept); connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject); QVBoxLayout *mainLayout = new QVBoxLayout; mainLayout->addLayout(statusLayout); mainLayout->addWidget(tabWidget); mainLayout->addWidget(buttonBox); setLayout(mainLayout); setWindowTitle(tr("Device Monitor"));
}
@
DashBoardTab(fileInfo) , SettingsTab(fileInfo), ValuesTab(fileInfo) are 3 classes for 3 tabs
-
@o6a6r9v1p In this case you should not create the TabDialog instance in the constructor of your main window. Instead do it when you want to show it (user clicks a button or menu or whatever).
-
@o6a6r9v1p
Sorry, I don't understand your description: what is "Top row"? What is "device status"? First you ask whether it is possible to start with tab1 and then you say it has to start with Tab0, I'm confused.
It is possible to activate a specific tab, read documentation: http://doc.qt.io/qt-5/qtabwidget.html#currentIndex-prop -
@o6a6r9v1p Posting images usually does not work here. You can upload it to a sharing service and post the link here.
-
@jsulm
Hi, Link for the image is
https://drive.google.com/open?id=0B-mEoDT_Dr1NajRQQWoyeDNYMTQ -
@o6a6r9v1p Sure, it is possible.
Check their code (constructor) and extend it like this:QVBoxLayout *mainLayout = new QVBoxLayout; QHBoxLayout *topRowLayout = new QHBoxLayout; QLineEdit *lineEdit = new QLineEdit(this); QLabel *label = new QLabel(this); topRowLayout.addWidget(lineEdit); topRowLayout.addWidget(label); mainLayout->addLayout(topRowLayout); mainLayout->addWidget(tabWidget); mainLayout->addWidget(buttonBox); setLayout(mainLayout);
-
@jsulm
In side tabWidget, I need 3 tabs. In that example code, they have used separate classes for them. Now I will do as you suggested.In this, i am getting signal from abcd(child) class and it is to be connected to(parent class) updateGui() in this function.
how to connect them. -
@o6a6r9v1p You do not need to use separate classes for your tabs, but you can if you like. Please read documentation: http://doc.qt.io/qt-5/qtabwidget.html#details
it is explained there:
"Create a QTabWidget.
Create a QWidget for each of the pages in the tab dialog, but do not specify parent widgets for them.
Insert child widgets into the page widget, using layouts to position them as normal.
Call addTab() or insertTab() to put the page widgets into the tab widget, giving each tab a suitable label with an optional keyboard shortcut."How to connect signals/slots? What exactly is the problem? Do it in your parent class where you create the children, for example:
tabWidget = new QTabWidget; DashBoardTab *dashBoardTab = new DashBoardTab(fileInfo); connect(dashBoardTab, SIGNAL(someSignal()), this, SLOT(someSlot())); tabWidget->addTab(dashBoardTab, tr("DashBoard")); tabWidget->addTab(new SettingsTab(fileInfo), tr("Settings")); tabWidget->addTab(new ValuesTab(fileInfo), tr("Values"));
14/24