在QRubberband上实现调整大小的句柄? QSizeGrip相关吗? [英] Implementing resize handles on QRubberband? Is QSizeGrip relevant?
问题描述
我想让我的QRubberband
实例用户可调整大小.我已经在此处看到了这个问题,但是没有解决方案.
I'd like to make my QRubberband
instance user resizeable. I've seen this question here but there isn't a solution.
用例是用户可以在照片上拖出一个选框,然后通过拖动QRubberband
边距进行精细调整以更改几何形状,或者通过拖动选区来重新定位现有几何.我已经实现了重新定位,但是我想知道用于改变QRubberband几何形状的调整手柄大小.
The use case is that the user can drag out a selection marquee over a photo and then make fine adjustments by dragging on the QRubberband
margins to change geometry, or reposition existing geometry by dragging the selection. I have the repositioning implemented but I am wondering about resize handles for changing the geometry of the QRubberband.
在这里可以使用QSizeGrip吗?除此以外,是否有标准的方法可以检查Qt
中的空白处"鼠标事件或其他实现此方法的方法?这是针对不需要此功能或无需为此付出很多努力的研究应用程序,但是拥有它会很好.
Is it possible to use QSizeGrip here? Barring that, is there a standard way of checking for mouse-within-margin type events within Qt
or some other way to implement this? This is for a research app that doesn't need or warrant lots of effort on this feature but it would be good to have.
推荐答案
是的,有可能.这是实现:
Yes, it's possible. Here is the implementation:
标题:
class Resizable_rubber_band : public QWidget {
public:
Resizable_rubber_band(QWidget* parent = 0);
private:
QRubberBand* rubberband;
void resizeEvent(QResizeEvent *);
};
来源:
Resizable_rubber_band::Resizable_rubber_band(QWidget *parent) : QWidget(parent) {
//tell QSizeGrip to resize this widget instead of top-level window
setWindowFlags(Qt::SubWindow);
QHBoxLayout* layout = new QHBoxLayout(this);
layout->setContentsMargins(0, 0, 0, 0);
QSizeGrip* grip1 = new QSizeGrip(this);
QSizeGrip* grip2 = new QSizeGrip(this);
layout->addWidget(grip1, 0, Qt::AlignLeft | Qt::AlignTop);
layout->addWidget(grip2, 0, Qt::AlignRight | Qt::AlignBottom);
rubberband = new QRubberBand(QRubberBand::Rectangle, this);
rubberband->move(0, 0);
rubberband->show();
show();
}
void Resizable_rubber_band::resizeEvent(QResizeEvent *) {
rubberband->resize(size());
}
用法:(ui->label
是用于显示要裁剪的图像的标签)
Usage: (ui->label
is the label used for displaying the image to be cropped)
Resizable_rubber_band* band = new Resizable_rubber_band(ui->label);
band->move(100, 100);
band->resize(50, 50);
band->setMinimumSize(30, 30);
这篇关于在QRubberband上实现调整大小的句柄? QSizeGrip相关吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!