【发布时间】:2014-02-14 22:14:21
【问题描述】:
我想转换(缩放、死记硬背)QWidget 对象(例如按钮)。基于此讨论: Scalable painting of a Qt application 我的主窗口的构造函数中有以下内容。 CMyGraphicsView 是从 QGraphicsView 派生的,直到现在都没有变化。
文本被转换,但按钮没有。这是实现这一目标的正确方法吗?使用内置工具可以做到这一点吗?
CMyGraphicsView *view = new CMyGraphicsView(this);
view->setGeometry(0, 0, geometry().width(), geometry().height());
view->setHorizontalScrollBarPolicy ( Qt::ScrollBarAlwaysOff );
view->setVerticalScrollBarPolicy ( Qt::ScrollBarAlwaysOff );
view->win = this;
this->setCentralWidget(view);
QGraphicsScene *scene = new QGraphicsScene(0, 0, geometry().width(), geometry().height(), this);
scene->addText("Hello, world!");
view->setScene(scene);
QToolButton *btn = new QToolButton(this);
btn->move(10,20);
btn->setStyleSheet("background-color: gray");
btn->setStyleSheet("QToolButton:pressed{background-color: red}");
btn->setStyleSheet("QToolButton:checked{background-color: red}");
scene->addWidget(btn);
view->scale(1.5,0.7);
view->rotate(9);
【问题讨论】:
-
你的代码适合我:screenshot
-
呸,这很奇怪。我不得不将按钮的构造函数更改为“new QToolButton(NULL)”,还生成了一条警告消息,昨晚我可能忽略了该消息,说按钮无法嵌入......不过,现在它可以工作了!感谢您的支持!
-
它对我有用,因为我省略了
this(因为我在main函数中写了它)。您可以自己发布答案以帮助未来的访问者。
标签: qt widget transformation