QToolBar not functioning properly



  • I'm having a problem getting my toolbar to show it's border or even be set as movable. I have four different instances, located on my app, that I'm splitting using QSplitter's and each one has a toolbar.I'm unable to solve the problem, I'm new to Qt, so any help will be really appreciated.

    My Code:

    @
    QWidget *view = new QTextEdit(this);
    QVBoxLayout *vbox = new QVBoxLayout(this);

    fileToolBar = new QToolBar(this);
    fileToolBar->addAction("file");
    fileToolBar->setMovable(true);

    vbox->addWidget(fileToolBar);
    vbox->addWidget(view);
    vbox->setContentsMargins(0,0,0,0);
    vbox->setSpacing(0);
    setLayout(vbox);
    @

    Here is a picture of what my app looks like.
    I got the idea from this "link":http://qt-project.org/forums/viewthread/3647, but my app doesn't look the same.

    !http://img15.imageshack.us/img15/3606/7onj.png!



  • Who is the parent of your setLayout function? This setLayout is done on a QWidget?



  • header file: "pane.h"

    @
    class Pane : public QWidget
    {
    Q_OBJECT

    public:
    Pane(QWidget* parent = 0);

    private:
    void createActions();
    void createToolBars();
    QAction *newAction;
    QToolBar *fileToolBar;
    };

    @

    Source File: "pane.cpp"
    createToolBars() is called by Pane::Pane(QWidget* parent)

    @
    void Pane::createToolBars()
    {

    QWidget *view = new QTextEdit(this);
    QVBoxLayout *vbox = new QVBoxLayout(this);
    
    fileToolBar = new QToolBar(this);
    fileToolBar->addAction("file");
    fileToolBar->setMovable(true);
    
    vbox->addWidget(fileToolBar);
    vbox->addWidget(view);
    vbox->setContentsMargins(0,0,0,0);
    vbox->setSpacing(0);
    setLayout(vbox);    
    

    }@

    I'm extremely new to Qt and not sure if it is a QWidget or Q_OBJECT.



  • I create the instances in QMainWindow
    @
    MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)

    {
    QWidget *wnd = new QWidget;
    QWidget *container_1 = new QWidget;
    QWidget *container_2 = new QWidget;

    QHBoxLayout *h_layout1 = new QHBoxLayout;
    QHBoxLayout *h_layout2 = new QHBoxLayout;
    QVBoxLayout *v_layout3 = new QVBoxLayout;
    
    QSplitter *split1 = new QSplitter;
    QSplitter *split2 = new QSplitter;
    QSplitter *split3 = new QSplitter;
    
    Pane *p1 = new Pane;
    Pane *p2 = new Pane;
    Pane *p3 = new Pane;
    Pane *p4 = new Pane;
    
    split1->addWidget(p1);
    split1->addWidget(p2);
    
    split2->addWidget(p3);
    split2->addWidget(p4);
    
    h_layout1->addWidget(split1);
    h_layout2->addWidget(split2);
    
    container_1->setLayout(h_layout1);
    container_2->setLayout(h_layout2);
    
    split3->setOrientation(Qt::Vertical);
    split3->addWidget(container_1);
    split3->addWidget(container_2);
    
    v_layout3->addWidget(split3);
    wnd->setLayout(v_layout3);
    
    setCentralWidget(wnd);
    

    }
    @



  • Hi,

    your toolbar can't be movable. This functionality can only be used with a toolbar in a QMainWindow (using "QMainWindow::addToolBar()":http://qt-project.org/doc/qt-5.1/qtwidgets/qmainwindow.html#addToolBar, see the documentation of the "movable property":http://qt-project.org/doc/qt-5.1/qtwidgets/qtoolbar.html#movable-prop).


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.