0

I want to implement a vertical scroll bar. I have implemented layouts for this(see the attached layouts.jpg), and also scroll area(see snippet in below code). Yet, when I run, the window does not have menubar. What am I missing here? I tried adding the menubar and submenus through Qt designer, as well as through code, but the window does not show the menubar.

If i use scroll area snippet, i can use the scrollbar, but don't see menubar. However If i comment out the scroll area snippet, i can see the menubar, but lose the scroll bar. I need both of them. How to solve this?

layouts.JPG

Here is the code:- mainwindow.h

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QScrollArea>
namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

private:
    Ui::MainWindow *ui;


};

#endif // MAINWINDOW_H

mainwindow.cpp

#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    layout()->setMenuBar(menuBar());
    QMenu *viewMenu;
    viewMenu = menuBar()->addMenu("VIEW");
    QMenu *resolutionSubMenu = viewMenu->addMenu("Resolution");
    QAction *QVGA = resolutionSubMenu->addAction("QVGA");


    QImage image(":\\image.jpg");
    ui->referenceImageLabel->setPixmap(QPixmap::fromImage(image));
    ui->deltaImageLabel->setPixmap(QPixmap::fromImage(image));
    ui->reconstructedImageLabel->setPixmap(QPixmap::fromImage(image));
    ui->referenceImageLabel->setMinimumSize(480, 640);ui->referenceImageLabel->setMinimumSize(480, 640);ui->referenceImageLabel->setMinimumSize(480, 640);

    /*Scroll area snippet*/
    QScrollArea *p_ScrollArea = new QScrollArea(this);
    p_ScrollArea->setAutoFillBackground(true);
    p_ScrollArea->setMinimumSize(width(), height());
    p_ScrollArea->setWidget(ui->centralWidget);

}

MainWindow::~MainWindow()
{
    delete ui;
}

main.cpp

#include "mainwindow.h"
#include <QApplication>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;
    w.show();

    return a.exec();
}
cappy0704
  • 557
  • 2
  • 9
  • 30
  • Can you try without `layout()->setMenuBar(menuBar())`? I don't think that is needed. – PrisonMonkeys May 20 '14 at 14:47
  • Hi, @PrisonMonkeys, when i added menubar through the designer, and run the program, the menubar was not there. so i added the line programmatically, but that did not help either. – cappy0704 May 21 '14 at 04:59

0 Answers0