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

QHeaderView::paintSection 做了什么,以至于我在之前或

What does QHeaderView::paintSection do such that all I do to the painter before or after is ignored(QHeaderView::paintSection 做了什么,以至于我在之前或之后對(duì)畫家所做的一切都被忽略了) - IT屋-程序員軟件開發(fā)技
本文介紹了QHeaderView::paintSection 做了什么,以至于我在之前或之后對(duì)畫家所做的一切都被忽略了的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

這個(gè)問題是這篇文章 是不同的,雖然看起來與 這個(gè).

This question is further development of this post and is different, though may seem similar as this one.

我正在嘗試重新實(shí)現(xiàn) QHeaderView::paintSection,以便從模型返回的背景得到尊重.我試著這樣做

I am trying to reimplement QHeaderView::paintSection, so that the background returned from the model would be honored. I tried to do this

void Header::paintSection(QPainter * painter, const QRect & rect, int logicalIndex) const
{
    QVariant bg = model()->headerData(logicalIndex, Qt::Horizontal, Qt::BackgroundRole);
    // try before
    if(bg.isValid())                // workaround for Qt bug https://bugreports.qt.io/browse/QTBUG-46216
        painter->fillRect(rect, bg.value<QBrush>());             
    QHeaderView::paintSection(painter, rect, logicalIndex);
    // try after
    if(bg.isValid())                // workaround for Qt bug https://bugreports.qt.io/browse/QTBUG-46216
        painter->fillRect(rect, bg.value<QBrush>());             
}

但是,它不起作用 - 如果我調(diào)用 QHeaderView::paintSection ,我用畫家繪制的任何東西都不可見(我也嘗試?yán)L制對(duì)角線).如果我刪除 QHeaderView::paintSection 調(diào)用,線條和背景將可見.在 QHeaderView::paintSection 之前和之后調(diào)用 fillRect 沒有任何區(qū)別.

However, it didn't work - if I make QHeaderView::paintSection call, nothing I draw with the painter is visible (I also tried drawing a diagonal line). If I remove QHeaderView::paintSection call, the line and the background will be visible. Making the fillRect call before vs. after the QHeaderView::paintSection doesn't make any difference.

我想知道,QHeaderView::paintSection 是什么讓我無法在它上面畫一些東西.以及是否有一種方法可以在不重新實(shí)現(xiàn) QHeaderView::paintSection 所做的一切的情況下克服它?

I wonder, what is it that QHeaderView::paintSection does that makes it impossible for me to draw something on top of it. And whether there is a way to overcome it without reimplementing everythning what QHeaderView::paintSection does?

我需要做的就是為某個(gè)單元格添加某種陰影 - 我仍然希望單元格中的所有內(nèi)容(文本、圖標(biāo)、漸變背景等)都按照現(xiàn)在的方式繪制...

All I need to do is to add a certain shade to a certain cell - I still want everything in the cell (text, icons, gradient background etc.) to be painted as it is now...

推薦答案

很明顯為什么第一個(gè) fillRect 不起作用.您在 paintSection 之前繪制的所有內(nèi)容都將被基礎(chǔ)繪制覆蓋.

It is obvious why the first fillRect doesn't work. Everything that you paint before paintSection is overridden by base painting.

第二個(gè)調(diào)用更有趣.

通常所有的繪制方法都會(huì)保留 painter 狀態(tài).這意味著當(dāng)你調(diào)用 paint 時(shí),它看起來像畫家狀態(tài)沒有改變.

Usually all paint methods preserves painter state. It means that when you call paint it looks like the painter state hasn't been changed.

盡管如此,QHeaderView::paintSection 破壞了畫家的狀態(tài).

Nevertheless QHeaderView::paintSection spoils the painter state.

要繞過這個(gè)問題,您需要自己保存和恢復(fù)狀態(tài):

To bypass the issue you need to save and restore the state by yourself:

void Header::paintSection(QPainter * painter, const QRect & rect, int logicalIndex) const
{
    QVariant bg = model()->headerData(logicalIndex, Qt::Horizontal, Qt::BackgroundRole);
    painter->save();
    QHeaderView::paintSection(painter, rect, logicalIndex);
    painter->restore();
    if(bg.isValid())               
        painter->fillRect(rect, bg.value<QBrush>());             
}

這篇關(guān)于QHeaderView::paintSection 做了什么,以至于我在之前或之后對(duì)畫家所做的一切都被忽略了的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(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精品国产91久久久久久不卞 | 久国产精品 | 欧美精品在线一区二区三区 | www.日韩 | 亚洲高清视频一区二区 | 国产欧美一区二区三区久久 | 欧美vide| 日本高清精品 | 欧美激情视频一区二区三区免费 | 午夜精品视频 | 欧美精品网 | 精品av久久久久电影 | 精品国产一区二区三区久久久四川 | 亚洲一区二区久久 | 西西裸体做爰视频 | 欧美视频第三页 | 视频一区 国产精品 | 国产午夜精品一区二区三区四区 | 精品国产乱码一区二区三区a | 国产美女视频 | 精品亚洲视频在线 | 国产高清在线精品 | 午夜精品一区二区三区在线观看 | 在线播放一区 | 国产一区二区欧美 | 亚洲视频一区 | 国产精品国产三级国产aⅴ原创 | 成人免费观看男女羞羞视频 | 曰批视频在线观看 | 男人亚洲天堂 | av免费网站在线 | 国产乱码久久久久久一区二区 | 91在线精品秘密一区二区 | 亚洲黄色片免费观看 | 狠狠干影院 | 一区二区三区欧美大片 | 国产一二三区精品视频 | 激情欧美日韩一区二区 | 91久久精品国产免费一区 | 婷婷成人在线 | 九九热精品在线 |