简体   繁体   English

Qt:GraphicsView中的TextEdit,下方有奇怪的灰色条

[英]Qt: TextEdit in GraphicsView with weird gray bar below

I'm using QGraphicsView / QGraphicsScene and added a QTestEdit-Widget. 我正在使用QGraphicsView / QGraphicsScene并添加了QTestEdit-Widget。 Unfortunately, the TextEdit gets rendered with a gray bar below, and I'm unable to get rid of it. 不幸的是,TextEdit的下方带有灰色条,因此我无法摆脱它。 Does anyone know how to achieve this? 有谁知道如何实现这一目标?

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    QGraphicsView *view = new QGraphicsView(ui->centralWidget);

    QGraphicsScene *scene = new QGraphicsScene(0, 0, 2000, 2000, view);
    scene->setSceneRect(-100,-100,400,400);

    view->setTransformationAnchor(QGraphicsView::NoAnchor);
    view->setScene(scene);

    QTextEdit *edt_test = new QTextEdit(0);
    edt_test->setGeometry(10,20,80,60);
    edt_test->setFrameStyle(QFrame::Plain | QFrame::Box);
    scene->addWidget(edt_test);
}

应用程序窗口,带有QTextEdit呈现,但下面有灰色条

using StyleSheet didn't solve the problem, but the following worked fine: 使用StyleSheet不能解决问题,但是以下方法可以正常工作:

QTextEdit *edt_test = new QTextEdit(0);
QGraphicsProxyWidget *proxy = scene->addWidget(edt_test);
edt_test->setFrameStyle(QFrame::Plain | QFrame::Box);
proxy->setGeometry(QRectF(10,20,80,60));

calling setGeometry based on the ProxyWidget is the solution. 解决方案是基于ProxyWidget调用setGeometry。 Seems weird ... 似乎很奇怪...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM