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

Qt:調整包含 QPixmap 的 QLabel 的大小,同時保持其縱

Qt: resizing a QLabel containing a QPixmap while keeping its aspect ratio(Qt:調整包含 QPixmap 的 QLabel 的大小,同時保持其縱橫比)
本文介紹了Qt:調整包含 QPixmap 的 QLabel 的大小,同時保持其縱橫比的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我使用 QLabel 向用戶顯示更大的、動態變化的 QPixmap 的內容.根據可用空間使這個標簽更小/更大會很好.屏幕尺寸并不總是像 QPixmap 一樣大.

I use a QLabel to display the content of a bigger, dynamically changing QPixmap to the user. It would be nice to make this label smaller/larger depending on the space available. The screen size is not always as big as the QPixmap.

如何修改 QLabel 的 QSizePolicysizeHint() 來調整 QPixmap 的大小,同時保持原始 QPixmap 的縱橫比?

How can I modify the QSizePolicy and sizeHint() of the QLabel to resize the QPixmap while keeping the aspect ratio of the original QPixmap?

我無法修改 QLabel 的 sizeHint(),將 minimumSize() 設置為零也無濟于事.在 QLabel 上設置 hasScaledContents() 允許增長,但會破壞縱橫比...

I can't modify sizeHint() of the QLabel, setting the minimumSize() to zero does not help. Setting hasScaledContents() on the QLabel allows growing, but breaks the aspect ratio thingy...

子類化 QLabel 確實有幫助,但是這個解決方案為一個簡單的問題添加了太多代碼......

Subclassing QLabel did help, but this solution adds too much code for just a simple problem...

是否有任何聰明的提示如何在沒有子類化的情況下實現這個?

Any smart hints how to accomplish this without subclassing?

推薦答案

為了更改標簽大小,您可以為標簽選擇合適的大小策略,例如擴展或最小擴展.

In order to change the label size you can select an appropriate size policy for the label like expanding or minimum expanding.

您可以通過在每次更改時保持縱橫比來縮放像素圖:

You can scale the pixmap by keeping its aspect ratio every time it changes:

QPixmap p; // load pixmap
// get label dimensions
int w = label->width();
int h = label->height();

// set a scaled pixmap to a w x h window keeping its aspect ratio 
label->setPixmap(p.scaled(w,h,Qt::KeepAspectRatio));

您應該在兩個地方添加此代碼:

There are two places where you should add this code:

  • 更新像素圖時
  • 在包含標簽的小部件的resizeEvent

這篇關于Qt:調整包含 QPixmap 的 QLabel 的大小,同時保持其縱橫比的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 ()?環形?)
主站蜘蛛池模板: 午夜电影福利 | 91精品国产综合久久香蕉922 | 国产精品视频久久 | 天天干天天爱天天操 | 天堂久久网 | 免费不卡视频 | 精品国产精品国产偷麻豆 | 国产一区二区三区在线视频 | 亚洲成人精品免费 | 精品综合久久 | 国产真实乱全部视频 | 一级aaaa毛片| 亚洲区视频 | 天天天操操操 | 精品欧美一区二区三区久久久小说 | 91久久精品国产 | 欧美日韩中 | 欧美精品乱码99久久影院 | 国产视频导航 | 亚洲午夜精品 | 无码一区二区三区视频 | av中文字幕在线播放 | 九色 在线 | 免费毛片网站 | 99精品久久 | 亚洲理论在线观看电影 | 欧美bondage紧缚视频 | 久久精品毛片 | 免费观看一级特黄欧美大片 | 日韩av成人 | 国产一区二区三区久久久久久久久 | 国产精品免费一区二区三区 | 欧美一级视频免费看 | 久久男人| 午夜精品久久久久久久星辰影院 | 久久精品免费一区二区 | 黄网站涩免费蜜桃网站 | 伊人在线 | 国产欧美一区二区三区久久 | 最新国产精品视频 | 久久三级影院 |