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

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

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

問題描述

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

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.

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

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.

在我看來,它的行為是隨機(jī)的.為什么會發(fā)生這種情況?

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 無法調(diào)整大小超過 GraphicView 的右側(cè)(水平)和底部(垂直)邊緣.如果你讓場景足夠大,比如 2000x2000 (setSceneRect(2000, 2000);),滾動條就會出現(xiàn).如果您手動移動滾動條,您將能夠進(jìn)一步放大您的小部件.

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 函數(shù)來試驗自動滾動條移動:

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.

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

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

相關(guān)文檔推薦

How can I read and manipulate CSV file data in C++?(如何在 C++ 中讀取和操作 CSV 文件數(shù)據(jù)?)
In C++ why can#39;t I write a for() loop like this: for( int i = 1, double i2 = 0; (在 C++ 中,為什么我不能像這樣編寫 for() 循環(huán): for( int i = 1, double i2 = 0;)
How does OpenMP handle nested loops?(OpenMP 如何處理嵌套循環(huán)?)
Reusing thread in loop c++(在循環(huán) C++ 中重用線程)
Precise thread sleep needed. Max 1ms error(需要精確的線程睡眠.最大 1ms 誤差)
Is there ever a need for a quot;do {...} while ( )quot; loop?(是否需要“do {...} while ()?環(huán)形?)
主站蜘蛛池模板: 国产精品久久精品 | 麻豆视频在线免费看 | 天色综合网 | 日韩亚洲欧美综合 | 精品国产91亚洲一区二区三区www | 婷婷在线视频 | 久久久久国产一区二区三区四区 | 日韩成人精品一区二区三区 | 国产成人免费视频网站视频社区 | 综合激情av | 九九久久精品 | 国产精品日韩一区二区 | 日韩av成人| 国产综合久久 | 久久不卡 | 国产在线视频一区二区董小宛性色 | 国产精品久久久久久久久久免费看 | 国产精品嫩草影院精东 | 亚洲午夜在线 | 久久亚洲春色中文字幕久久久 | 高清免费av | 看真人视频一级毛片 | 欧美精品一二区 | 亚洲视频免费在线观看 | 另类二区 | 网站国产 | 亚洲国产一区在线 | 欧美精品一区二区三区在线播放 | 亚洲国产精品一区二区久久 | 综合久久网 | 精品欧美一区二区三区久久久 | 亚洲免费精品 | 91国内精品 | 久草福利| 很黄很污的网站 | 国产精品特级毛片一区二区三区 | 欧美激情久久久 | av先锋资源| 狠狠操电影 | 国产精品视频综合 | 国产黄色大片 |