简体   繁体   English

在 QSplitter 中设置最小固定尺寸 QCustomPlot 条形图

[英]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);

Existing Behaviour:现有行为:

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.调整窗口大小的情况也是如此。

Required Behavior必需的行为

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我希望条形图可以水平滚动,而无需在拖动拆分器时调整它们的大小,即向左/向右拖动拆分器应该显示更多/更少的图形,而不是调整它们的大小

Queries查询

  1. How do I specify that the bar graph should have a minimum size and expand from that depending on the number of ticks on x-axis?如何指定条形图应具有最小尺寸并根据 x 轴上的刻度数从中扩展?
  2. How do I stop the plot from automatically expanding/shrinking?如何阻止绘图自动扩展/收缩?

What I have tried so far到目前为止我尝试过的

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:你需要:

  1. Create a QTableWidget widget with two columns and and one row.创建一个具有两列和一行的QTableWidget小部件。
  2. Set the QScrollArea widget as the parent of the QTableWidget widget.QScrollArea小部件设置为QTableWidget小部件的父级。
  3. Hide the horizontal and vertical headers.隐藏水平和垂直标题。 To do so set horizontalHeaderVisible and verticalHeaderVisible to false .为此,将horizontalHeaderVisibleverticalHeaderVisible设置为false
  4. Add QCustomPlot widgets into the table using the setCellWidget(int row, int column, QWidget * widget) method.使用setCellWidget(int row, int column, QWidget * widget)方法将QCustomPlot小部件添加到表中。

这就是它的解决方法:我只需要为滚动区域调用setWidgetResizablefalse ,现在我有了一个永久滚动条,并且在拖动拆分器时自定义绘图不会调整大小。

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.

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