Thank you all for your contribution, now code will finally compile without errors, but unfornately doc (new TestDocument widget) won't show up.
This is all the code I have for this app:
TestApp.h
#ifndef TESTAPP_H
#define TESTAPP_H
#include <QMainWindow>
#include <QVBoxLayout>
#include <QScrollBar>
#include <QAbstractScrollArea>
{
Q_OBJECT
public:
TestApp();
private:
};
#endif // TESTAPP_H
#ifndef TESTAPP_H
#define TESTAPP_H
#include <QMainWindow>
#include <QVBoxLayout>
#include <QScrollBar>
#include <QAbstractScrollArea>
class TestApp : public QMainWindow
{
Q_OBJECT
public:
TestApp();
private:
QVBoxLayout *layoutMain;
QWidget *window;
QScrollBar *scrollBar;
QAbstractScrollArea *scrollArea;
};
#endif // TESTAPP_H
To copy to clipboard, switch view to plain text mode
TestDocument.h
#ifndef TESTDOCUMENT_H
#define TESTDOCUMENT_H
#include <QtGui>
#include <QTextEdit>
{
Q_OBJECT
public:
{
setViewportMargins(30,30,30,30);
}
};
#endif // TESTDOCUMENT_H
#ifndef TESTDOCUMENT_H
#define TESTDOCUMENT_H
#include <QtGui>
#include <QTextEdit>
class TestDocument : public QTextEdit
{
Q_OBJECT
public:
TestDocument(QWidget *p = 0) : QTextEdit(p)
{
setViewportMargins(30,30,30,30);
}
};
#endif // TESTDOCUMENT_H
To copy to clipboard, switch view to plain text mode
TestApp.cpp
#include <TestApp.h>
#include <TestDocument.h>
#include <QtGui>
TestApp::TestApp()
{
TestDocument doc;
layoutMain->addWidget(&doc);
//layoutMain->setMargin(0);
window->setLayout(layoutMain);
setCentralWidget(window);
}
#include <TestApp.h>
#include <TestDocument.h>
#include <QtGui>
TestApp::TestApp()
{
TestDocument doc;
layoutMain = new QVBoxLayout;
layoutMain->addWidget(&doc);
//layoutMain->setMargin(0);
window = new QWidget;
window->setLayout(layoutMain);
setCentralWidget(window);
}
To copy to clipboard, switch view to plain text mode
main.cpp
#include <QApplication>
#include <TestApp.h>
int main(int argc, char *argv[])
{
TestApp test;
test.show();
return app.exec();
}
#include <QApplication>
#include <TestApp.h>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
TestApp test;
test.show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
First I thought it was too big margins, but even if I set them all to 10, doc won't show up.
I tried using doc.show(), I tried declaring "TestDocument *doc;" in TestApp.h and then "doc = new TestDocument" in TestApp.cpp, but neither works (second method showed some errors, so it had to be wrong idea).
Bookmarks