久久久久久久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 ()?環形?)
主站蜘蛛池模板: 久久久久av| 国产精品成人一区二区三区夜夜夜 | 色吊丝2288sds中文字幕 | 中文字幕成人 | 久久国产精品视频 | av中文字幕在线播放 | 精品欧美一区免费观看α√ | 国产欧美在线一区 | 日韩视频一区二区三区 | 中文字幕精品一区二区三区精品 | 精品一区二区三区在线观看国产 | 国产一级片久久久 | 久久久久一区二区 | 国产精品99久久久精品免费观看 | 亚洲精选一区二区 | 亚洲网视频 | 日日欧美 | 日韩精品一区二区三区四区视频 | 99爱在线免费观看 | 狠狠婷婷综合久久久久久妖精 | 伊人久久在线 | 亚洲成人精品在线 | 久久综合一区二区三区 | 亚洲国产成人精品女人 | 久久99精品久久久 | av免费网站在线观看 | 成人午夜激情 | 久久久久久免费精品一区二区三区 | 久久精品国产久精国产 | 欧美一区二区成人 | 高清国产一区二区 | 九色.com | 日本一区视频在线观看 | 亚洲一区国产 | 久久97精品 | 蜜桃视频一区二区三区 | 综合久久av | 伊人网站| 国产精品乱码一区二三区小蝌蚪 | 日日日日操 | 羞羞视频网站免费观看 |