Hi, It's my first time trying Qt and followed the tutorials on widgets first, then the address book tutorial. My problem is with arranging widgets in a QGridLayout, I use proper row/column numbers but when I run the program, all of them are palced at top left.
/Here's the code\
adressbook.hpp:
#include <QWidget>
#include <QLineEdit>
#include <QTextEdit>
class address_book
: public QWidget { Q_OBJECT
public:
};
#include <QWidget>
#include <QLineEdit>
#include <QTextEdit>
class address_book: public QWidget {
Q_OBJECT
QLineEdit name;
QTextEdit address;
public:
address_book(QWidget *parent=0);
};
To copy to clipboard, switch view to plain text mode
addressbook.cpp:
#include "addressbook.hpp"
#include <QLabel>
#include <QGridLayout>
address_book
::address_book(QWidget *parent
): QWidget(parent
), name
(), address
() { QLabel laddress
(tr
("Address:"));
layout.setSpacing(10);
layout.addWidget(&lname, 0, 0);
layout.addWidget(&name, 0, 1);
layout.addWidget(&laddress, 1, 0);
layout.addWidget(&address, 1, 1);
setWindowTitle(tr("Address Book"));
}
#include "addressbook.hpp"
#include <QLabel>
#include <QGridLayout>
address_book::address_book(QWidget *parent): QWidget(parent), name(), address() {
QLabel lname(tr("Name:"));
QLabel laddress(tr("Address:"));
QGridLayout layout(this);
layout.setSpacing(10);
layout.addWidget(&lname, 0, 0);
layout.addWidget(&name, 0, 1);
layout.addWidget(&laddress, 1, 0);
layout.addWidget(&address, 1, 1);
setWindowTitle(tr("Address Book"));
}
To copy to clipboard, switch view to plain text mode
Here's the screenshot:
app.jpg
What might be causing this behaviour?
Bookmarks