在Qt中,如果你发现按钮文本有位移,这通常是因为按钮的边框或内边距(padding)设置的过大。以下是一些方法来取消Qt按钮文本位移:
1. 调整内边距(Padding):
你可以通过设置按钮的`setContentsMargins()`方法来调整内边距。
```cpp
QPushButton button = new QPushButton("Button Text");
button->setContentsMargins(0, 0, 0, 0); // 设置为0以移除内边距
```
2. 调整边框(Border):
如果你使用的是`QPushButton`的样式表(StyleSheet),可以通过调整边框来实现。
```cpp
QPushButton button = new QPushButton("Button Text");
button->setStyleSheet("QPushButton { border: none;