In Mac platform, qt widget sometime will display blank,how to deal with it?
-
mac, os x yosemite 10.10.2
normal display
blank display
When my mouse move on the contact list, blank will display.
To resolve this problem, i add update when receive mouse move event.
but, in this case, the widget will flash(first blank, second i update it), not a good experience。
Anyone could give me some advice? Thanks very much. -
Hi and welcome to devnet,
You should post a minimal sample code that reproduces that behavior
-
Hi and welcome to devnet,
You should post a minimal sample code that reproduces that behavior
@SGaist
Thanks, the same code can run well on window7 platform.
When on Mac, sometimes it will be blank, most time it run well.
This is the mouseMoveEvent():void CombineListView::mouseMoveEvent(QMouseEvent event)
{
QModelIndex index = indexAt(event->pos());
QRect closeBtnRect = index.data(IM_POS).toRect();
QStandardItemModel p =dynamic_cast<QStandardItemModel*>(this->model()) ;
QStandardItem* item = p->itemFromIndex(index);
if(NULL != item)
{
if(closeBtnRect.contains(event->pos()))
{
item->setData(CLOSEBTN_HOVER,IM_ADDICON);
item->setToolTip("ClickToClose");
}
else
{
item->setData(CLOSEBTN_NORMAL,IM_ADDICON);
item->setToolTip(item->data(IM_NAME).toString());
}
}QListView::mouseMoveEvent(event);
}
-
Are you using a custom delegate ?
-
@SGaist
Thank you ,and there a another question.
My app's UI always has a blue frame on mac os when it get focus,like this:
blue frame
When the username get focus, it has a blue frame.
I know that is the os's setting in General-Appearance-Blue
So what should i to do to avoid this ?
Thanks very much. -
Then I'd check the delegate implementation of the paint function for something fishy.
Please, keep that question on the other thread you opened, otherwise it's going to get messy.
-
Then I'd check the delegate implementation of the paint function for something fishy.
Please, keep that question on the other thread you opened, otherwise it's going to get messy.
@SGaist
The code is transplant from WIN32 platform, and the app runs well on WIN32.
The blank happens when move mouse on contact list, where will raise mousemove event.
Another case, when other app's frame covers my app for a little time, then move out, my app's frame display blank, unless I click on the blank it will display normal -
Can you share the delegate paint implementation ? Without seeing any code it's pretty much Crystal Ball debugging.
-
Can you share the delegate paint implementation ? Without seeing any code it's pretty much Crystal Ball debugging.
@SGaist Yes,here it is:
void CombineListDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { const QStandardItemModel* modelTemp = dynamic_cast<const QStandardItemModel*>(index.model()) ; if (NULL == modelTemp) { LOG_WARNING<<"modelTemp is null"<<LOG_END; return; } QStandardItem* sitem = modelTemp->itemFromIndex(index); if(NULL == sitem) { LOG_WARNING<<"sitem is null"<<LOG_END; return; } bool selected=option.state &QStyle::State_Selected;; QPalette palette(option.palette); palette.setColor(QPalette::Active, QPalette::Window, selected ? option.palette.highlight().color() : option.palette.base().color()); palette.setColor(QPalette::Active, QPalette::WindowText, selected ? option.palette.highlightedText().color() : option.palette.text().color()); //鼠标悬浮着色 if (selected) { QRect fill_rect(option.rect.x(),option.rect.y(),option.rect.width(),option.rect.height()); QBrush brush(cSelectColor); painter->fillRect(fill_rect, brush); } if(option.state&QStyle::State_MouseOver && m_bHover) { if(!selected) { QRect fill_rect(option.rect.x(),option.rect.y(),option.rect.width(),option.rect.height()); QBrush brush(cHoverColor); painter->fillRect(fill_rect,brush); } //关闭窗口按钮 QPixmap closeBtn; closeBtn.load(sitem->data(IM_ADDICON).toString()); QRect closeBtnRect = QRect(option.rect.right() - ADAPT_DPI_INT(3) - ADAPT_DPI_INT(closeBtn.width()), option.rect.y() + ADAPT_DPI_INT(9), ADAPT_DPI_INT(closeBtn.width()), ADAPT_DPI_INT(closeBtn.height())); painter->drawPixmap(closeBtnRect,closeBtn); sitem->setData(closeBtnRect,IM_POS); } if(sitem->data(IM_ISALERT).toBool()) { QBrush brush(cAlertColor); QRect fill_rect(option.rect.x(),option.rect.y(),option.rect.width(),option.rect.height()); painter->fillRect(fill_rect,brush); if(option.state&QStyle::State_MouseOver && m_bHover) { //关闭窗口按钮 QPixmap closeBtn; closeBtn.load(sitem->data(IM_ADDICON).toString()); QRect closeBtnRect = QRect(option.rect.right() - ADAPT_DPI_INT(3) - ADAPT_DPI_INT(closeBtn.width()), option.rect.y() + ADAPT_DPI_INT(9), ADAPT_DPI_INT(closeBtn.width()), ADAPT_DPI_INT(closeBtn.height())); painter->drawPixmap(closeBtnRect,closeBtn); sitem->setData(closeBtnRect,IM_POS); } } /**************************设置状态图标*********************************/ QPixmap statusIcon; QString iconPath; QString strStatusName; QList<QPixmap> pixmapStatus; QPixmap iconfirst; QPixmap iconSecond; bool bIsMuc = sitem->data(IM_ISMUC).toBool(); if (!bIsMuc) { int iStatus = sitem->data(IM_ONLINESTATUE).toInt(); int iPlatForm = sitem->data(IM_MOBILEPLATFORM).toInt(); strStatusName = CommonFun::getStatusTypeName(iStatus, iPlatForm); if (sitem->data(IM_ISSYSNOTICE).toBool()) { strStatusName = QString(QChar(0xe6e9)); // 系统通知的小图标 } // pixmapStatus = CommonFun::getStatusIcon(iStatus, iPlatForm); // iconfirst = pixmapStatus.first(); // iconSecond = pixmapStatus.last(); } /**************************设置名字*********************************/ QFont font; font.setFamily("微软雅黑"); font.setPixelSize(ADAPT_DPI_INT(12)); painter->setFont(font); painter->setPen(cFontColor); QRect nameRect; if (!bIsMuc) { nameRect = QRect(ADAPT_DPI_INT(15), option.rect.y(), option.rect.right()-ADAPT_DPI_INT(66), option.rect.height()); } else { nameRect = QRect(ADAPT_DPI_INT(15), option.rect.y(), option.rect.right()-ADAPT_DPI_INT(22), option.rect.height()); } QString text= QAbstractItemDelegate::elidedText(painter->fontMetrics(),nameRect.width(),Qt::ElideRight,sitem->data(IM_NAME).toString());// + strStatusName; QTextOption textop(Qt::AlignVCenter); painter->drawText(nameRect, text, textop); int i = nameRect.right(); QFont font_icon(CommonFun::getIconFont()); font_icon.setPixelSize(ADAPT_DPI_INT(14)); painter->setFont(font_icon); QRect statusRect(nameRect.right()+ADAPT_DPI_INT(18), nameRect.y()+ADAPT_DPI_INT(7),painter->fontMetrics().width(strStatusName), painter->fontMetrics().height() ); painter->drawText(statusRect, strStatusName); // QRect statusRectFirst(nameRect.right()+18, nameRect.y()+7,iconfirst.width(), iconfirst.height() ); // painter->drawPixmap(statusRectFirst, iconfirst); // QRect statusRectSecond(nameRect.right(), statusRectFirst.y(),iconSecond.width(), iconfirst.height() ); // painter->drawPixmap(statusRectSecond, iconSecond); //拖动排序时的悬浮效果 if(m_bDraging) { if (!selected && option.state&QStyle::State_MouseOver) { painter->drawRect(option.rect); } } }
[edit: added missing coding tags SGaist]
-
Are you sure that you don't return early when you have that white cell showing ?
-
@SGaist Thanks again. There is another question.
If there has another app covers my widget for a while, after I move the app out, my widget will be blank.The same code runs well on WIN32 platform.
Normal widget
Blank widget
For this situation, if I click on the widget, it will be ok.
How could i to do for the blank widget? -
The files are not available currently
-
No, error 400