Qt 6.11 is out! See what's new in the release
blog
[SOLVED]Add custom widget to layout?
General and Desktop
4
Posts
3
Posters
6.4k
Views
1
Watching
-
I have created a custom widget that is based on QTextEdit
@class MyWidget : public QTextEdit
{@and now I want to add a method for showing this widget, but trying
@QWidget *myWidget = new QWidget;
QGridLayout *myLayout = new QGridLayout;
MyWidget customWidget(myWidget);
myLayout->addItem(customWidget); // or addWidget, same result
myWidget->setLayout(myLayout);
myWidget->show();@results in the error
@error: no matching member function for call to 'addItem'
myLayout->addItem(customWidget);
~~~~@^How can I show my custom QWidget?
-
-
Hello,
customWidget should be a pointer.
Try something like this:
@MyWidget* customWidget = new MyWidget(myWidget);
myLayout->addWidget( customWidget );
@best regards,
poorBob