Add menubar to QDialog or convert QDialog to QMainWindow ?
I made my program and declared it(the c++ file I am executing in the main c++ file) as a class public QDialog like this
Code:
#include <QDialog>
class DateListDialog
: public QDialog {Q_OBJECT
public:DateListDialog();
}
but I want to add a menubar and I am not sure how if it is a QDialog so I wish to turn the QDialog into a QMainWindow I tried changing the code on the header to:
Code:
#include <QMainWindow>
Q_OBJECT
public:DateListDialog();
}
but then when I do that and add the menubar all it shows it the menubar and not all the other gui items so basically its just an empty QMainWindow
the code I used to add the gui items is this:
Code:
#include <QtGui>
#include "datelistdialog.h"
#include "listwidgetdialog.h"
#include <sstream>
#include <iostream>
using namespace std;
DateListDialog::DateListDialog()
{
QStringList dates, foods, totalCalories, totalProteins, totalCarbs, totalFats, totalSugars, totalSodiums, totalFibers;
labels << tr("Dates") << tr("Foods") << tr("Total Calories") << tr("Total Proteins") << tr("Total Carbs") << tr("Total Fats") << tr("Total Sugars") << tr("Total Sodiums") << tr("Total Fibers");
treeWidget->setColumnCount(9);
treeWidget->setHeaderLabels(labels);
mainLayout->addWidget(treeWidget);
setLayout(mainLayout);
QFile file(QDir::homePath() + "/caloriecounter.txt");
input.setCodec("UTF-8");
while(!input.atEnd()){
//dates << input.readLine();
foods << input.readLine();
totalCalories << input.readLine();
totalProteins << input.readLine();
totalCarbs << input.readLine();
totalFats << input.readLine();
totalSugars << input.readLine();
totalSodiums << input.readLine();
totalFibers << input.readLine();
input.readLine();
}
}
for (int i = 0; i < foods.size(); ++i) {
//item->setText(0, dates[i]);
item->setText(1, foods[i]);
item->setText(2, totalCalories[i]);
item->setText(3, totalProteins[i]);
item->setText(4, totalCarbs[i]);
item->setText(5, totalFats[i]);
item->setText(6, totalSugars[i]);
item->setText(7,totalSodiums[i]);
item->setText(8, totalFibers[i]);
treeWidget->addTopLevelItem(item);
}
//createActions();
//createMenus();
}
Any suggestions would be greatly appreciated.
Thanks!
Re: Add menubar to QDialog or convert QDialog to QMainWindow ?
EDIT::: I think I figured a way how to do it but I will need a little bit of help with it I cannot find anything on the internet on how to do it.
What I think will work is to set the QDialog from the datelistdialog.cpp file as the main widget of another file called MainWindow which is a mainwindow
I tried doing this for the header:
Code:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
{
public:
MainWindow();
};
#endif // MAINWINDOW_H
and this for the c++ file:
Code:
#include "mainwindow.h"
#include "datelistdialog.h"
MainWindow::MainWindow()
{
DateListDialog w;
setCentralWidget(w);
}
unfortunately it did not work =/
so I tried this for the c++
Code:
#include "mainwindow.h"
#include "datelistdialog.h"
MainWindow::MainWindow()
{
DateListDialog w;
w.exec();
}
it opens the QDialog but it does not set it as the centralWidget of the MainWindow tho =/
EDIT!:!:!:!:!:!:
The reason it was not working for me was after i turned it to a MainWindow I forgot the "setCentralWidget" because you do not need that on QDialogs.