Qt:: how to get rid of the gap between widget and toolbar in a qmainwindow

381 Views Asked by At

basically I have a QLabel* in the mainwindow. I tried to set it as the centralWidget. When the program is running, it is fine if the mainWindow stays the original size. However, if I enlarge the size, there suddenly comes a gap between the QLabel and the toolBar from no where!!!! How can I do to get rid of it!!!

The funny thing is, although there is gap being created, the x and y coordinate of the QLabel did not change!!!! How could this happen!!!!

........................................................................

I used QTCreator to make a ScrollArea as the centralWidget. This way, when I enlarge the QMainWindow, the ScrollArea enlarges automatically. However, the problem is. When I tried to call setWidget function to set the Label into the ScrollArea, the same problem above occured again!!!!

Someone, please help!!!!!!!!!!!!!

This is what I tried, but apparently does not work:

the code is:

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    imageLabel = new QLabel();
    image = new QPixmap(480,320);
    image->fill();
    imageLabel->setPixmap(*image);
    setCentralWidget(imageLabel);
}

enter image description here

1

There are 1 best solutions below

1
Nicholas Smith On

To me it looks like a layout issue, you've set the size of the label already, once you resize your window it stays at the size already set unless you specifically set it's size again, or you're using one of the QLayout layout managers.