Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
QTabWidget get the tab page's widgets
chronix last edited by
So I'm using PyQt5 to develop an app.
I'm able to create a new tab with a custom widget.
This widget had 3 orther widgets in a custom layout, ie. a QTextEdit, a QLineEdit and a QPushButton.
I can get the QWidget for the current tab, by
tabWidget.currentWidget()bt I don't understand how to get to that
QLineEditor any of the other widgets for that matter.
Can you tell me how to fix this problem?
Thanks in advance :)
I have never tried PyQt5 so forgive me if not the same as c++.
I assume you are not using UI files?
so there is no UI to use ?
You insert the widgets by new ?
Maybe you can use findChildren function ?
QList<QPushButton *> allPButtons = tabWidget.findChildren<QPushButton *>();
chronix last edited by
Thank you replaying.
yeah I'm using UI (UI files are not used directly, the are converted into python code, by a program, even C++ does with MOC, bt here we have to do it manually and import that python file) files bt to create a new tab i have to define a custom widget. Also no pointers in python, I understand your reply bt i don't know how to impilment it in python
Usually when someone tries to get the sub-widgets of a widget, there's a design issue in the making. Why do you need to get the QLineEdit for ?
Masonsu last edited by
![alt text](image http://sip-communicator.org/wiki/pub/sip-communicator/screenshots/chat-window-dispmua.png)
@SGaist Hi, SGaist, I am now have the same problem. I need to do a chat app, just like the image above. I create a tabwidget and the tabwidget have several chat pages. Every chat page is a class Chatlog, which contain a QTextEdit, a QLineEdit and a sendButton. My problem is when I receive a message from others, I know the name but I need to put the message into the right QTextEdit, Also , I need to mention that I define a QHash<QString, Chatlog*>, each name represent a chatpage. Now I don't have a good idea to achieve this, can you give me some advice?
Thanks in advance
@Masonsu your QTextEdit is an implementation detail of your Chatlog widget. You should use e.g. a slot in Chatlog that will internally append the text to your QTextEdit. So if you change it for something else. You don't have to rewrite everything because of that.