QLabel not starting from 0,0
-
@sierdzio @m-sue All my values are as per default.
Yeah I have fixed my window size as
700,700.
My layoutLeftMargin is also set as 0.My UI window part : https://pastebin.com/TAEBh1Wx

Hi,
use setContentsMargin(0,0,0,0); method for both main layout and label. -
@sierdzio @m-sue All my values are as per default.
Yeah I have fixed my window size as
700,700.
My layoutLeftMargin is also set as 0.My UI window part : https://pastebin.com/TAEBh1Wx

-
@m.sue said in QLabel not starting from 0,0:
<layoutdefault spacing="6" margin="11"/>
That section has a GUI and the XML is not editable. Any way that change can be done?
Hi @Arqam
I thought you wrote the XML. Then see above:
@Venkatesh-V said in QLabel not starting from 0,0:
use setContentsMargin(0,0,0,0); method for both main layout and label.
-Michael.
-
Hi,
use setContentsMargin(0,0,0,0); method for both main layout and label.@Venkatesh-V @m-sue
How can I do that, I know for my QLabel containing the image I can do
ui->label_image->setContentsMargins(0,0,0,0);Constructor :
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { this->setFixedSize(700,700); ui->setupUi(this); ui->label_image->setContentsMargins(0,0,0,0); }So how can we change for main layout also, as just changing the value for label didn't do any thing.
-
@Arqam ,
First add your label to main layout and then call,
mainLayout->setContentMargins(-1,-1,-1,-1);
-
@Arqam ,
First add your label to main layout and then call,
mainLayout->setContentMargins(-1,-1,-1,-1);
@Vinod-Kuntoji
I did :this->setContentsMargins(-1,-1,-1,-1); ui->label_image->setContentsMargins(0,0,0,0);What it did is just that a bit to the left (and other direction) the margin is reduced.
When I give the default value i.e. -11 that is given in the XML then it starts from the leftmost region.
But when given for the top position i.e (-11,-11,0,0) QLabel doesn't start from the topmost part. -
@Arqam ,
I tried like this.
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
mLabel = new QLabel(this);
mLayout = new QVBoxLayout(this);QPixmap pix(":/image.PNG"); mLabel->setPixmap(pix); mLayout->addWidget(mLabel);// mLayout->setContentsMargins(0,0,0,0);
mLayout->setMargin(0);
mLayout->setSpacing(0);
mLayout->setAlignment(mLabel,Qt::AlignTop);
QWidget *widget = new QWidget(this);
widget->setLayout(mLayout);this->setCentralWidget(widget);}
There is a toolbar on top of the label, thats why it is showing some space on top of label. If you dont want the toolbar then remove it.
-
@Arqam ,
I tried like this.
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
mLabel = new QLabel(this);
mLayout = new QVBoxLayout(this);QPixmap pix(":/image.PNG"); mLabel->setPixmap(pix); mLayout->addWidget(mLabel);// mLayout->setContentsMargins(0,0,0,0);
mLayout->setMargin(0);
mLayout->setSpacing(0);
mLayout->setAlignment(mLabel,Qt::AlignTop);
QWidget *widget = new QWidget(this);
widget->setLayout(mLayout);this->setCentralWidget(widget);}
There is a toolbar on top of the label, thats why it is showing some space on top of label. If you dont want the toolbar then remove it.
@Vinod-Kuntoji said in QLabel not starting from 0,0:
this->setCentralWidget(widget);
My widget main window is not having a toolbar, it was having a status bar which I removed.
The structure of my window is like this :If going by your example my mLayout should be Central Widget?
-
@Arqam ,
Please mark your issue as solved.