gpt4 book ai didi

c++ - 使用 QScrollArea 滚动条

转载 作者:搜寻专家 更新时间:2023-10-31 02:05:12 24 4
gpt4 key购买 nike

我在 Qt Designer 中创建了两个滚动区域。它们每个的大小分别为 [(31,48) 1141 x 161] 和 [(31, 310) 1141 x 101]。然后我创建了两个 TimeDiagram 类的小部件拷贝,我将它们的大小设置为大于各自滚动区域的大小。然后我将对象设置为区域。启用垂直和水平滚动条。

窗口的构造函数:

GraphicScaleDialog::GraphicScaleDialog(OutputData *outputData, QWidget *parent) :
QDialog(parent),
ui(new Ui::GraphicScaleDialog) {
ui->setupUi(this);

data = outputData;

commonSAGridSpacing = 120;
commonSAScale = 15;
resultsSAGridSpacing = 120;
resultsSAScale = 15;

ui->commonSAGridSpacing_line->setText(QString::number(commonSAGridSpacing));
ui->commonSAScale_line->setText(QString::number(commonSAScale));
ui->resultsSAGridSpacing_line->setText(QString::number(resultsSAGridSpacing));
ui->resultsSAScale_line->setText(QString::number(resultsSAScale));

commonArea = ui->commonScrollArea;
commonArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
commonArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
resultsArea = ui->resultsScrollArea;
resultsArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
resultsArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);

commonDiagramWidget = new TimeDiagram(20, this);
commonDiagramWidget->setGeometry(31, 41, 2000, static_cast<int>(data->outputSettings.flowQuantity * commonDiagramWidget->rowHeight));
resultsDiagramWidget = new TimeDiagram(100, this);
resultsDiagramWidget->setGeometry(31, 114, 2000, 101);

commonArea->setWidget(commonDiagramWidget);
resultsArea->setWidget(resultsDiagramWidget);

commonArea->show();
resultsArea->show();
}

Diagrams

问题是创建两个带有时间轴的网格​​。

我需要使用 QPainter 来解决这个问题吗?

更新:可能是 TimeDiagram 的方法有问题?

void TimeDiagram::paintEvent(QPaintEvent * /* event */) {
QPainter painter(this);
draw(&painter);
}

//--------------------------------------------------------------

void TimeDiagram::draw(QPainter *painter) {
painter->setRenderHint(QPainter ::NonCosmeticDefaultPen, true);
QPen* pen = new QPen();
pen->setWidth(1);

pen->setColor(Qt::black);
painter->setPen(*pen);
for (int i = static_cast<int>(rowHeight); i < this->height(); i += static_cast<int>(rowHeight))
//for (unsigned int counter = 0; counter < static_cast<GraphicScaleDialog *>(this->parent())->data->outputSettings.flowQuantity; counter++)
painter->drawLine(0, i, this->width(), i);

pen->setColor(Qt::lightGray);
painter->setPen(*pen);
for(int i = 0; i < this->width(); i += 30)
painter->drawLine(i, 0, i, this->height());

delete pen;
}

最佳答案

在 Designer 中,在您的 QScrollArea 中取消选中 widgetResizable 属性或使用 QScrollArea::setWidgetResizable 以编程方式将其关闭。

关于c++ - 使用 QScrollArea 滚动条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52331329/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com