BreakpointWidget: Fix Qt centering issues with a Custom Delegate
This commit is contained in:
parent
d96840f808
commit
b7b0842d2f
|
@ -3,9 +3,13 @@
|
|||
|
||||
#include "DolphinQt/Debugger/BreakpointWidget.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QHeaderView>
|
||||
#include <QMenu>
|
||||
#include <QPainter>
|
||||
#include <QSignalBlocker>
|
||||
#include <QStyleOptionViewItem>
|
||||
#include <QStyledItemDelegate>
|
||||
#include <QTableWidget>
|
||||
#include <QToolBar>
|
||||
#include <QVBoxLayout>
|
||||
|
@ -36,6 +40,39 @@ enum CustomRole
|
|||
};
|
||||
}
|
||||
|
||||
// Fix icons not centering properly in a QTableWidget.
|
||||
class CustomDelegate : public QStyledItemDelegate
|
||||
{
|
||||
public:
|
||||
CustomDelegate(BreakpointWidget* parent) : QStyledItemDelegate(parent) {}
|
||||
|
||||
private:
|
||||
void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
|
||||
{
|
||||
Q_ASSERT(index.isValid());
|
||||
|
||||
// Fetch normal drawing logic.
|
||||
QStyleOptionViewItem opt = option;
|
||||
initStyleOption(&opt, index);
|
||||
|
||||
// Disable drawing icon the normal way.
|
||||
opt.icon = QIcon();
|
||||
opt.decorationSize = QSize(0, 0);
|
||||
|
||||
// Default draw command for paint.
|
||||
QApplication::style()->drawControl(QStyle::CE_ItemViewItem, &opt, painter, 0);
|
||||
|
||||
// Draw pixmap at the center of the tablewidget cell
|
||||
QPixmap pix = qvariant_cast<QPixmap>(index.data(Qt::DecorationRole));
|
||||
if (!pix.isNull())
|
||||
{
|
||||
const QRect r = option.rect;
|
||||
const QPoint p = QPoint((r.width() - pix.width()) / 2, (r.height() - pix.height()) / 2);
|
||||
painter->drawPixmap(r.topLeft() + p, pix);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
BreakpointWidget::BreakpointWidget(QWidget* parent)
|
||||
: QDockWidget(parent), m_system(Core::System::GetInstance())
|
||||
{
|
||||
|
@ -88,6 +125,7 @@ void BreakpointWidget::CreateWidgets()
|
|||
m_toolbar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
|
||||
|
||||
m_table = new QTableWidget;
|
||||
m_table->setItemDelegate(new CustomDelegate(this));
|
||||
m_table->setTabKeyNavigation(false);
|
||||
m_table->setContentsMargins(0, 0, 0, 0);
|
||||
m_table->setColumnCount(6);
|
||||
|
|
|
@ -17,6 +17,8 @@ namespace Core
|
|||
class System;
|
||||
}
|
||||
|
||||
class CustomDelegate;
|
||||
|
||||
class BreakpointWidget : public QDockWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
|
Loading…
Reference in New Issue