Unable to focus and give input to widgets in Qt5
I am unable to focus on any input type widgets like QTextEdit,QListWidget
etc.
Note: There are no compile time or runtime errors.
I have a MainWindow class derived from QMainWindow as declared in
main_window.h:
class MainWindow : public QMainWindow{
Q_OBJECT
public:
MainWindow(QWidget *parent = 0);
//some other members here
}
I have another class called Stack derived from QWidget defined in stack.h:
class Stack: public QWidget{
public:
Stack(QWidget *parent=0);
//some other members
}
Constructor of Stack as in stack.cpp :
Stack::Stack(QWidget *parent):QWidget(parent){
main = new QHBoxLayout;
QTextEdit *test = new QTextEdit;
main->addWidget(test);
//other things added to main layout
setLayout(main);
}
If i open up this widget in a separate window from the MainWindow using
test->show(), the things work as expected/as i want. But doing this in the
MainWindow constructor, renders it unclickable.
MainWindow::MainWindow(QWidget *parent):QMainWindow(parent){
Stack *test = new Stack;
//test->show();
setCentralWidget(test);
}
This is strange. Why am i not able to focus any widget that can take input
e.g. QTextEdit,QListWidget or click any QPushButton widget?
No comments:
Post a Comment