本文整理汇总了C++中QAbstractItemView::visualRect方法的典型用法代码示例。如果您正苦于以下问题:C++ QAbstractItemView::visualRect方法的具体用法?C++ QAbstractItemView::visualRect怎么用?C++ QAbstractItemView::visualRect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QAbstractItemView
的用法示例。
在下文中一共展示了QAbstractItemView::visualRect方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: eventFilter
bool TooltipFilter::eventFilter(QObject *obj, QEvent *event)
{
if (event->type() == QEvent::ToolTip)
{
QWidget *w = static_cast<QWidget *>(obj);
QHelpEvent *helpEvent = static_cast<QHelpEvent *>(event);
QPoint pos = helpEvent->globalPos();
QString itemTooltip = w->toolTip();
QRect rect = w->rect();
// case of instrument tables inside a scrollarea viewport
if (w->objectName() == QLatin1String("qt_scrollarea_viewport"))
{
QAbstractItemView* view = qobject_cast<QAbstractItemView*>(obj->parent());
if (!view)
{
return false;
}
w = view;
QPoint position = helpEvent->pos();
QModelIndex index = view->indexAt(position);
if (!index.isValid())
{
return false;
}
rect = view->visualRect(index);
itemTooltip = view->model()->data(index, Qt::ToolTipRole).toString();
}
switch (tooltipType_)
{
case TooltipType::NoTooltip:
QToolTip::hideText();
return true;
case TooltipType::StdTooltip:
QToolTip::showText(pos, itemTooltip, w, rect);
return true;
case TooltipType::CustomTooltip:
break;
default:
QToolTip::hideText();
emit updateTooltipRequest(itemTooltip);
return true;
}
}
return QObject::eventFilter(obj, event);
}
示例2: ShowHideTip
//qt3to4 -- BW
//void ComboBoxToolTip::ShowHideTip( int index, QLabel* tipL, Q3ListBox* lb, const QString& text )
void ComboBoxToolTip::ShowHideTip( int index, QLabel* tipL, QComboBox* lb, const QString& text )
{
//if ( lb->isVisible() && !lb->isHidden() && lb->hasMouse() )
if ( lb->isVisible() && !lb->isHidden() )
{
//qt3to4 -- BW
QAbstractItemView* qv = lb->view();
//qt3to4 -- BW
//QRect rect = lb->itemRect ( lb->item( index ) );
QRect rect = qv->visualRect(lb->rootModelIndex());
tipL->setMargin(1);
tipL->setIndent(0);
//qt3to4 -- BW
//tipL->setAutoMask( FALSE );
tipL->setFrameStyle( QFrame::Plain | QFrame::Box );
tipL->setLineWidth( 1 );
tipL->setAlignment( Qt::AlignLeft | Qt::AlignTop );
//tipL->polish();
tipL->setText(text);
tipL->adjustSize();
QPoint pos;
pos.setX( rect.right() + 15 );
pos.setY( rect.top() );
pos = lb->mapToGlobal( pos );
tipL->move( pos.x(), pos.y() );
tipL->show();
tipL->raise();
return;
}
else{
if (!tipL->isHidden() )
tipL->hide();
}
/*
if ( !lb->isVisible() || lb->isHidden() ||
!lb->hasMouse()) {
tipL->hide();
}
*/
}
示例3: eventFilter
bool TableViewTooltip::eventFilter(QObject * obj, QEvent * event)
{
if (event->type() != QEvent::ToolTip) {
return false;
}
QAbstractItemView* view = qobject_cast<QAbstractItemView*>(obj->parent());
if (!view) {
return false;
}
QHelpEvent * helpEvent = static_cast<QHelpEvent*>(event);
QPoint pos = helpEvent->pos();
QModelIndex index = view->indexAt(pos);
if (!index.isValid()) {
return false;
}
QString itemTooltip = view->model()->data(index, Qt::ToolTipRole).toString();
if (itemTooltip.isEmpty()) {
QToolTip::hideText();
return true;
}
QString itemText = view->model()->data(index).toString();
QFontMetrics fm(view->font());
int textIdentWidth =6;// fm.width('r'); // don't know how to calculate an ident for text in an item :-(
int itemTextWidth = fm.width(itemText) + textIdentWidth;
QRect rect = view->visualRect(index);
int rectWidth = rect.width();
if (itemTextWidth > rectWidth) {
QToolTip::showText(helpEvent->globalPos(), itemTooltip, view, rect);
}
else {
QToolTip::hideText();
}
return true;
}
示例4: eventFilter
bool ColumnToolTip::eventFilter(QObject* obj, QEvent* event)
{
if (event->type() == QEvent::ToolTip)
{
QAbstractItemView* view = qobject_cast<QAbstractItemView*>(obj->parent());
if (!view)
{
return false;
}
QHelpEvent* helpEvent = static_cast<QHelpEvent*>(event);
QPoint pos = helpEvent->pos();
QModelIndex index = view->indexAt(pos);
if (!index.isValid())
return false;
QString itemText = view->model()->data(index).toString();
QString itemTooltip = view->model()->data(index, Qt::ToolTipRole).toString();
QFontMetrics fm(view->font());
int itemTextWidth = fm.width(itemText);
QRect rect = view->visualRect(index);
int rectWidth = rect.width();
if ((itemTextWidth > rectWidth) && !itemTooltip.isEmpty())
{
QToolTip::showText(helpEvent->globalPos(), itemTooltip, view, rect);
}
else
{
QToolTip::hideText();
}
return true;
}
return false;
}