QSplitter becoming undistinguishable between QWidget and QTabWidget

前端 未结 7 1119
庸人自扰
庸人自扰 2021-02-04 06:30

I am puting a QWidget and a QTabWidget next to each other in one horisontal splitter. And the splitter loses it\'s shape, you can know that there is a splitter only by hovering

7条回答
  •  名媛妹妹
    2021-02-04 07:01

    Since the QSplitterHandle (which is what most people think of as the 'splitter') is derived from QWidget, you can add other widgets to it. Here is what I have done to solve this exact problem in the past:

    // Now add the line to the splitter handle
    // Note: index 0 handle is always hidden, index 1 is between the two widgets
    QSplitterHandle *handle = pSplitter->handle(1);
    QVBoxLayout *layout = new QVBoxLayout(handle);
    layout->setSpacing(0);
    layout->setMargin(0);
    
    QFrame *line = new QFrame(handle);
    line->setFrameShape(QFrame::HLine);
    line->setFrameShadow(QFrame::Sunken);
    layout->addWidget(line);
    

    This adds a sunken line to the splitter handle. You can, of course, choose another style for the frame line or use something entirely different as the widget you add to the splitter handle.

提交回复
热议问题