[英]Setting minimum fixed size QCustomPlot bar graph inside QSplitter
I am using QCustomPlot
to plot a bar graph.我正在使用
QCustomPlot
绘制条形图。 There are two such bar graphs horizontally arranged inside a QSplitter
(which can be dragged).在
QSplitter
(可以拖动)内有两个这样的条形图水平排列。 On dragging the splitter horizontally, the bar graphs resize and scale to the point that the axes labels start to overlap.水平拖动拆分器时,条形图会调整大小并缩放到轴标签开始重叠的点。 I have a parent
QWidget
which contains a QScrollArea
which ultimately contains the plot.我有一个父
QWidget
,它包含一个最终包含绘图的QScrollArea
。 This widget is added to the QSplitter
.这个小部件被添加到
QSplitter
。
QWidget* topLeftParent = new QWidget;
topLeftParent->setLayout(new QVBoxLayout);
QScrollArea *topLeftScrollArea = new QScrollArea(this);
topLeftScrollArea->setWidget(energyGraph->GetPlot());
topLeftScrollArea->setWidgetResizable(true);
topLeftScrollArea->setFrameShape(QFrame::NoFrame);
topLeftParent->layout()->addWidget(topLeftScrollArea);
m_pTopLeftHorizontalSplitter->setMinimumWidth(500);
m_pTopLeftHorizontalSplitter->addWidget(topLeftParent);
On dragging the splitter horizontally, the bar graphs expand/shrink horizontally till the axes tick labels overlap and ultimately at a very small value of width, the horizontal scrollbar appears, which is useless.在水平拖动拆分器时,条形图水平扩展/收缩,直到轴刻度标签重叠,最终宽度值非常小,水平滚动条出现,这是无用的。 Same is the case for resizing the window as well.
调整窗口大小的情况也是如此。
However, I seek a different behavior.但是,我寻求不同的行为。 I want the bar graphs to be horizontally scrollable without them resizing on dragging the splitter ie dragging the splitter left/right should reveal more/less of the graphs, and not resize them
我希望条形图可以水平滚动,而无需在拖动拆分器时调整它们的大小,即向左/向右拖动拆分器应该显示更多/更少的图形,而不是调整它们的大小
I have tried setting minimum size for the plot, but it does not work.我试过为情节设置最小尺寸,但它不起作用。 I have also tried specifying the stretch factor for the splitter to 0, but that also has no effect ie the behavior is auto resizing bar graphs in both the cases with scrollbar appearing too late.
我还尝试将拆分器的拉伸因子指定为 0,但这也没有效果,即在滚动条出现太晚的两种情况下,行为都是自动调整条形图的大小。
To achieve the required behavior you can use the QTableWidget
widget.要实现所需的行为,您可以使用
QTableWidget
小部件。 You need to:你需要:
QTableWidget
widget with two columns and and one row.QTableWidget
小部件。QScrollArea
widget as the parent of the QTableWidget
widget.QScrollArea
小部件设置为QTableWidget
小部件的父级。horizontalHeaderVisible
and verticalHeaderVisible
to false
.horizontalHeaderVisible
和verticalHeaderVisible
设置为false
。QCustomPlot
widgets into the table using the setCellWidget(int row, int column, QWidget * widget)
method.setCellWidget(int row, int column, QWidget * widget)
方法将QCustomPlot
小部件添加到表中。这就是它的解决方法:我只需要为滚动区域调用setWidgetResizable
和false
,现在我有了一个永久滚动条,并且在拖动拆分器时自定义绘图不会调整大小。
Find if you have this line:查找您是否有此行:
ui->my_plot->setInteractions(QCP::iRangeZoom | QCP::iRangeDrag);
And edit it to whatever you want, for example just range zoom:并将其编辑为您想要的任何内容,例如仅范围缩放:
ui->my_plot->setInteractions(QCP::iRangeZoom);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.