0

How to build a simple custom widget with Qt? The widget is very simple with just 2 line edit QLineEdit' in a vertical box layoutQVBoxLayout`. How to do it? I read Qt's examples on custom widget generation. They reimplement paint event to rendering the custom widget. However, mine is so simple that I cannot find a solution in Qt's reference.

user1899020
  • 12,499
  • 17
  • 70
  • 145

1 Answers1

2

Well to do it all programatically it would look something like this:

class MyWidget : public QWidget {
    public:
        MyWidget(QWidget *parent=0) : QWidget(parent) {
            QVboxLayout *layout = new QVboxLayout();
            setLayout(layout);
            layout->addWidget(new QLineEdit());
            layout->addWidget(new QLineEdit());
        }
};

Depending on your needs you could make the line edits member variables and manipulate them as you see fit.

Chris
  • 16,401
  • 3
  • 53
  • 59