简体   繁体   English

如何禁用Qlabel中的对齐方式?

[英]How to disable alignment in Qlabel?

I'm developing a little C++ program using QT 5.8 framework. 我正在使用QT 5.8框架开发一个C ++程序。 It has a window with one label and I want to draw a sine wave in the label. 它有一个带有一个标签的窗口,我想在标签中绘制一个正弦波。

The sine wave should start at ten pixel from the left margin of the label but it is drawn according the alignment parameter of the label. 正弦波应从标签的左边缘开始十个像素处开始,但它是根据标签的对齐参数绘制的。

Is there any possibility to disable the alignment parameter of the label ? 是否有可能禁用标签的对齐参数? Did you have similar problem and how do you fix it ? 您是否有类似的问题,并且该如何解决?

Thank you very much for your help and cooperation regards 非常感谢您的帮助和合作

This is my code: 这是我的代码:

#define SPAZIO_SX 10 // ten pixel from left
#define SPAZIO_BASSO 10 // ten pixel from bottom
void MainWindow::setGraphic()
{
  int i;
  QPicture pi;
  QPainter p(&pi);
  int x0,x1,y0,y1;
  int yCoord;
  yCoord=this->ui->GraphicLabel->geometry().height();

  p.setRenderHint(QPainter::Antialiasing);
  p.setPen(QPen(Qt::white, 4, Qt::SolidLine,Qt::RoundCap,Qt::RoundJoin));
  x0=SPAZIO_SX;
  y0=yCoord-SPAZIO_BASSO-pvalMedia->getValue(0);  // return value(0-255)
  for(i=1;i<512;i=i++) {
      y1=yCoord-SPAZIO_BASSO-pvalMedia->getValue(i); 
      x1=x0+1;
      p.drawLine(x0, y0, x1, y1);
      y0=y1;
      x0=x1;
    }

  p.end(); //
  this->ui->GraphicLabel->setPicture(pi);
}

In your situation margin will do the job. 在您的情况下,保证金可以胜任。

set QLabel margin with CSS, in order from top , right , down , left : 使用CSS按从toprightdownleft顺序设置QLabel边距:

ui->label->setStyleSheet("margin: 0px 0px 0px 10px;"); //10px left margin

or set margin all 4 sides: 或在所有4边设置边距:

ui->label->setStyleSheet("margin:10px;");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM