简体   繁体   中英

Qt: TextEdit in GraphicsView with weird gray bar below

I'm using QGraphicsView / QGraphicsScene and added a QTestEdit-Widget. Unfortunately, the TextEdit gets rendered with a gray bar below, and I'm unable to get rid of it. 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:

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. Seems weird ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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