sorry.. only a short test.. the answer will follow
//mainwindow.h
//[SKIP]
{
Q_OBJECT
public:
MainWindow();
protected:
private slots:
// [SKIP]
void about();
void indexEnv(); // first steps
void documentWasModified();
private:
void createActions();
//[SKIP]
PreviewWindow *previewWindow; // first call of a sub dialog
QMenu *indexMenu;
// first steps to create an index menu --> my own menu
//[SKIP]
QAction *indexEnvAct;
// first steps to create an index menu --> Action for my own menu };
// mainwindow.cpp
//[SKIP]
void MainWindow::createActions()
{
//[SKIP]
aboutQtAct
= new QAction(tr
("About &Qt"),
this);
aboutQtAct->setStatusTip(tr("Show the Qt library's About box"));
connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
indexEnvAct
= new QAction(tr
("&Index Environment settings"),
this);
// my own action and menu and so on ... indexEnvAct->setStatusTip(tr("Opens the index environment setting dialog"));
connect(indexEnvAct, SIGNAL(triggered()), qApp, SLOT(indexEnv()));
cutAct->setEnabled(false);
copyAct->setEnabled(false);
connect(textEdit, SIGNAL(copyAvailable(bool)),
cutAct, SLOT(setEnabled(bool)));
connect(textEdit, SIGNAL(copyAvailable(bool)),
copyAct, SLOT(setEnabled(bool)));
}
void MainWindow::createMenus()
{
//[SKIP]
menuBar()->addSeparator();
indexMenu = menuBar()->addMenu(tr("&Index"));
indexMenu->addAction(indexEnvAct);
}
void MainWindow::indexEnv() // this here is the last part...
{
previewWindow = new PreviewWindow(this);
previewWindow->activateWindow();
previewWindow->show();
}
//mainwindow.h
//[SKIP]
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow();
protected:
void closeEvent(QCloseEvent *event);
private slots:
// [SKIP]
void about();
void indexEnv(); // first steps
void documentWasModified();
private:
void createActions();
//[SKIP]
PreviewWindow *previewWindow; // first call of a sub dialog
QTextEdit *textEdit;
QString curFile;
QMenu *fileMenu;
QMenu *editMenu;
QMenu *indexMenu; // first steps to create an index menu --> my own menu
QMenu *helpMenu;
QToolBar *fileToolBar;
QToolBar *editToolBar;
//[SKIP]
QAction *aboutQtAct;
QAction *indexEnvAct; // first steps to create an index menu --> Action for my own menu
};
// mainwindow.cpp
//[SKIP]
void MainWindow::createActions()
{
//[SKIP]
aboutQtAct = new QAction(tr("About &Qt"), this);
aboutQtAct->setStatusTip(tr("Show the Qt library's About box"));
connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
indexEnvAct = new QAction(tr("&Index Environment settings"), this); // my own action and menu and so on ...
indexEnvAct->setStatusTip(tr("Opens the index environment setting dialog"));
connect(indexEnvAct, SIGNAL(triggered()), qApp, SLOT(indexEnv()));
cutAct->setEnabled(false);
copyAct->setEnabled(false);
connect(textEdit, SIGNAL(copyAvailable(bool)),
cutAct, SLOT(setEnabled(bool)));
connect(textEdit, SIGNAL(copyAvailable(bool)),
copyAct, SLOT(setEnabled(bool)));
}
void MainWindow::createMenus()
{
//[SKIP]
menuBar()->addSeparator();
indexMenu = menuBar()->addMenu(tr("&Index"));
indexMenu->addAction(indexEnvAct);
}
void MainWindow::indexEnv() // this here is the last part...
{
previewWindow = new PreviewWindow(this);
previewWindow->activateWindow();
previewWindow->show();
}
To copy to clipboard, switch view to plain text mode
so, now I'm hopping, there is somewhere an error... which I can't find...
// previewwindow.h
#ifndef PREVIEWWINDOW_H
#define PREVIEWWINDOW_H
#include <QWidget>
class PreviewWindow
: public QWidget{
Q_OBJECT
public:
PreviewWindow
(QWidget *parent
= 0);
// void setWindowFlags(Qt::WindowFlags flags);
private:
};
#endif
// previewwindow.cpp
#include <QtGui>
#include "previewwindow.h"
PreviewWindow
::PreviewWindow(QWidget *parent
){
textEdit->setReadOnly(true);
textEdit
->setLineWrapMode
(QTextEdit::NoWrap);
connect(closeButton, SIGNAL(clicked()), this, SLOT(close()));
layout->addWidget(textEdit);
layout->addWidget(closeButton);
setLayout(layout);
setWindowTitle(tr("Preview"));
}
// previewwindow.h
#ifndef PREVIEWWINDOW_H
#define PREVIEWWINDOW_H
#include <QWidget>
class QPushButton;
class QTextEdit;
class PreviewWindow : public QWidget
{
Q_OBJECT
public:
PreviewWindow(QWidget *parent = 0);
// void setWindowFlags(Qt::WindowFlags flags);
private:
QTextEdit *textEdit;
QPushButton *closeButton;
};
#endif
// previewwindow.cpp
#include <QtGui>
#include "previewwindow.h"
PreviewWindow::PreviewWindow(QWidget *parent)
: QWidget(parent)
{
textEdit = new QTextEdit;
textEdit->setReadOnly(true);
textEdit->setLineWrapMode(QTextEdit::NoWrap);
closeButton = new QPushButton(tr("&Close"));
connect(closeButton, SIGNAL(clicked()), this, SLOT(close()));
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(textEdit);
layout->addWidget(closeButton);
setLayout(layout);
setWindowTitle(tr("Preview"));
}
To copy to clipboard, switch view to plain text mode
Is there an error??
For me it seems correct... the 5 steps you described above seems for me to realised..
thanks in advanced
Bookmarks