question

Bj6565Sing-3187 avatar image
1 Vote"
Bj6565Sing-3187 asked JeanineZhang-MSFT commented

Qt: can create widget in ctor, but not in mousePressEvent

I want to dynamically create a child widget on the click of the mouse. When I manually create it in ctor, everything is ok.

 Foo::Foo(QWidget *partent) : QWidget(parent)
 {
     auto *txt{ new QPlainTextEdit(this) };
 }

but when I do the same in mousePressEvent, it doesn't appear.

 Foo::mousePressEvent(QMouseEvent *event)
 {
     auto *txt{ new QPlainTextEdit(this) };
    
     QWidget::mousePressEvent(event);
 }

What might be the problem? Is there something in the ctor that triggers the appearance of the widget?


c++
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@Bj6565Sing-3187

According to your description, It is related to Qt, I suggest you could post the issue to the Qt forum for better help.


0 Votes 0 ·

0 Answers