久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

為什么我不能放大 QSizeGrip 添加到 QGraphicScene 的小

Why I can#39;t enlarge a widget added to QGraphicScene by QSizeGrip?(為什么我不能放大 QSizeGrip 添加到 QGraphicScene 的小部件?)
本文介紹了為什么我不能放大 QSizeGrip 添加到 QGraphicScene 的小部件?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我通過 QGraphicsProxyWidget 添加了一個小部件到圖形場景 QGraphicScene.為了移動它,我將 QGraphicsRectitem 設置為它的父級.使用 sizegrip 調整小部件的大小.

I have added a widget to a graphic scene QGraphicScene through a QGraphicsProxyWidget. To move it I have set QGraphicsRectitem as its parent. The widget is resized with the use of a sizegrip.

第一次創建對象時,我可以將其放大到某個尺寸.第二次我可以把它放大得比第一次小.第三次小于第二次以此類推.

The first time I create an object I can enlarge it upto some dimension. The second time I can enlarge it less than the first one. The third time less than the second one and so on.

在我看來,它的行為是隨機的.為什么會發生這種情況?

It seems to me that it behaves randomly. Why is this happening?

代碼如下:

void GraphicsView::dropEvent(QDropEvent *event)// subclass of QGraphicsView
{

  if(event->mimeData()->text() == "Dial")
  {
   auto *dial= new Dial;      // The widget
   auto *handle = new QGraphicsRectItem(QRect(event->pos().x(),event->pos().y(), 120, 120));    // Created to move and select on scene
   auto *proxy = new QGraphicsProxyWidget(handle); // Adding the widget through the proxy
   dial->setGeometry(event->pos().x()+10,event->pos().y()+10, 100, 100);
   proxy->setWidget(dial);
   QSizeGrip * sizeGrip = new QSizeGrip(dial);
   QHBoxLayout *layout = new QHBoxLayout(dial);
   layout->setContentsMargins(0, 0, 0, 0);
   layout->addWidget(sizeGrip, 0, Qt::AlignRight | Qt::AlignBottom);

   handle->setPen(QPen(Qt::transparent));
   handle->setBrush(Qt::gray);
   handle->setFlags(QGraphicsItem::ItemIsMovable |
   QGraphicsItem::ItemIsSelectable);

   scene->addItem(handle); // adding to scene 

   connect(dial, &Dial::sizeChanged, [dial, handle](){ handle->setRect(dial->geometry().adjusted(-10, -10, 10, 10));}); 
  }  }  

我不能將小部件放大更多,如圖所示.

I cannot enlarge the widget more than that, what is shown in the image.

推薦答案

您的 Dial 無法調整大小超過 GraphicView 的右側(水平)和底部(垂直)邊緣.如果你讓場景足夠大,比如 2000x2000 (setSceneRect(2000, 2000);),滾動條就會出現.如果您手動移動滾動條,您將能夠進一步放大您的小部件.

Your Dial can't be resized past the GraphicView's right (horizonally) and bottom (vertically) edges. If you make the scene big enough, say 2000x2000 (setSceneRect(2000, 2000);), scrollbars will appear. If you move the scrollbars manually, you will be able to enlarge your widgets more.

您還可以通過像這樣更改 lambda 函數來試驗自動滾動條移動:

You could also experiment with automatic scrollbar movement by changing the lambda function like this:

connect(dial, &Dial::sizeChanged, [this, dial, handle](){
    handle->setRect(dial->geometry().adjusted(-10, -10, 10, 10));

    int dx = handle->rect().bottomRight().x() > viewport()->rect().bottomRight().x();
    int dy = handle->rect().bottomRight().y() > viewport()->rect().bottomRight().y();

    if (dx > 0) {
        horizontalScrollBar()->setValue(horizontalScrollBar()->value() + dx);
    }

    if (dy > 0) {
        verticalScrollBar()->setValue(verticalScrollBar()->value() + dy);
    }
});

請注意,雖然此代碼有效,但非常繁瑣.但是,它可以讓您了解如何開始.

Please note, that although this code works, is is very cumbersome. However, it could give you an idea how to start.

這篇關于為什么我不能放大 QSizeGrip 添加到 QGraphicScene 的小部件?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

How can I read and manipulate CSV file data in C++?(如何在 C++ 中讀取和操作 CSV 文件數據?)
In C++ why can#39;t I write a for() loop like this: for( int i = 1, double i2 = 0; (在 C++ 中,為什么我不能像這樣編寫 for() 循環: for( int i = 1, double i2 = 0;)
How does OpenMP handle nested loops?(OpenMP 如何處理嵌套循環?)
Reusing thread in loop c++(在循環 C++ 中重用線程)
Precise thread sleep needed. Max 1ms error(需要精確的線程睡眠.最大 1ms 誤差)
Is there ever a need for a quot;do {...} while ( )quot; loop?(是否需要“do {...} while ()?環形?)
主站蜘蛛池模板: 午夜xxx | 久久久久亚洲精品 | 日韩综合一区 | 国产成人福利 | 日韩在线精品视频 | 一区二区三区四区在线播放 | 日韩av在线免费播放 | 一区二区视频在线播放 | 亚洲成人免费 | 日本欧美视频 | 国产成人毛片 | 97精品国产97久久久久久免费 | 欧美精品一级片 | 激情五月婷婷综合 | 超碰人人干 | 欧美日韩国产一区二区三区 | 国产成人av一区二区三区在线观看 | 亚洲69 | 中文字幕免费观看 | 久久日本 | 中文字幕av在线播放 | 性做久久久久久久免费看 | 国产区一区| 黄色片视频在线观看 | 一区二区欧美日韩 | 色片网址 | 黄色片一级 | 两性午夜视频 | 国产精品视频免费 | 久久精品导航 | 一级看片免费视频 | 97超碰资源 | 久久精品中文字幕 | 一区二区欧美日韩 | 国产精品亚洲综合 | 欧美黄网站 | 中文字幕三级 | 欧美日韩一区在线 | 色涩av | 人人综合网 | aaaa级片|