Adding a Toolbar to children widget of a QSplitter



  • Hi again, this question is very similar to the first one about the layout in teh main window.
    Basically the first question was answered by me calling setCentralWidget(child)
    to setting the child widget of the Maninwindow as a central frame.

    Now I my problem is that each child of my four way splitter is the client area of a graphics editor.
    Each pane must has a Toolbar and a QGLWidget,
    The problem is that I cannot figure out how to add the toolbar to the top, in a way similarly to a QMainWindow .

    I had trying many options and none seem to work.
    Here is my class declaration and constructor

    @//class alchemediaViewport: public QWidget
    //class alchemediaViewport: public QGLWidget
    class alchemediaViewport: public QTextEdit
    //class alchemediaViewport: public QMainWindow
    {
    public:
    alchemediaViewport(QWidget* const parent);
    ~alchemediaViewport(void);
    };

    alchemediaViewport::alchemediaViewport(QWidget* const parent)
    // :QWidget(parent)
    // :QGLWidget(parent)
    :QTextEdit(parent)
    // :QMainWindow(parent)
    {
    // QTextEdit* xxx = new QTextEdit (this);
    // QGLWidget* xxx = new QGLWidget (this);

    // QVBoxLayout* layout = new QVBoxLayout(this);
    // layout->setObjectName(QString::fromUtf8("horizontalLayout"));

    QToolBar* toolBar = new QToolBar(this);
    toolBar->setObjectName(QString::fromUtf8("viewportToolBar"));
    toolBar->setGeometry(QRect(0, 0, 300, 26));
    // layout->addWidget (toolBar);
    // addToolBar(Qt::TopToolBarArea, toolBar);
    // layout->addWidget(xxx);
    }@

    I am looking for a look like this
    !http://www.newtondynamics.com/downloads/alchemdiaLook.jpg(image)!

    That is the font page of the same application that I wrote using MFC,
    but that I am having a huge problem since it is too much work to rewite it for Mac, Linux and even other OS.
    This is the main reason I am moving it to Qt.

    can somebody suggest an idea of how to go about achieving a look like that



  • Hi,

    "Now I my problem is that each child of my four way splitter is the client area of a graphics editor.
    Each pane must has a Toolbar and a QGLWidget,
    The problem is that I cannot figure out how to add the toolbar to the top, in a way similarly to a QMainWindow ."

    Well to create such pane you can just say:

    @
    QToolBar* toolBar = new QToolBar();

        toolBar->addAction("first");
        toolBar->addAction("second");
        QWidget* view = new QWidget();
    
        QVBoxLayout* vbox = new QVBoxLayout();        
        vbox->addWidget(toolBar);
        vbox->addWidget(view);
        QWidget* widget = new QWidget(); //This is the pane
        widget->setLayout(vbox);
        widget->show();
    

    @



  • where do a place that code?
    the code that add the panes for the spliter is this
    @alchemediaVerticalSpliter::alchemediaVerticalSpliter(QWidget* const parent)
    :QSplitter (Qt::Vertical, parent), m_updating(false)
    {
    alchemediaViewport* const topVp = new alchemediaViewport(this);
    alchemediaViewport* const lowVp = new alchemediaViewport(this);
    addWidget(topVp);
    addWidget(lowVp);
    }@

    alchemediaViewport is the class that creates the viewport that must has the QGLwidget and its own local toolbar.
    how do I use you code, in that context?



  • I just pasted your sample into my veiwport class like this
    @alchemediaViewport::alchemediaViewport(QWidget* const parent)
    :QWidget(parent)
    // :QGLWidget(parent)
    // :QTextEdit(parent)
    // :QMainWindow(parent)
    {
    /*
    // QTextEdit* xxx = new QTextEdit (this);
    // QGLWidget* xxx = new QGLWidget (this);

    // QVBoxLayout* layout = new QVBoxLayout(this);
    // layout->setObjectName(QString::fromUtf8("horizontalLayout"));

    QToolBar* toolBar = new QToolBar(this);
    toolBar->setObjectName(QString::fromUtf8("viewportToolBar"));
    toolBar->setGeometry(QRect(0, 0, 300, 26));
    // layout->addWidget (toolBar);
    // addToolBar(Qt::TopToolBarArea, toolBar);
    // layout->addWidget(xxx);
    */

    QToolBar* toolBar = new QToolBar();
    toolBar->addAction("first");
    toolBar->addAction("second");
    QWidget* view = new QWidget();
    QVBoxLayout* vbox = new QVBoxLayout();
    vbox->addWidget(toolBar);
    vbox->addWidget(view);
    QWidget* widget = new QWidget(); //This is the pane
    widget->setLayout(vbox);
    widget->show();
    }@

    and all I have is four floating windows with thick frames each and a toobar with the
    buttons "first secund", not exactly what I want.
    Again, if this is the solution I must be using it wrong,
    can you tell me how to use that code?



  • Ok I modified like this

    @alchemediaViewport::alchemediaViewport(QWidget* const parent)
    :QWidget(parent)
    // :QGLWidget(parent)
    // :QTextEdit(parent)
    // :QMainWindow(parent)
    {
    /*
    // QTextEdit* xxx = new QTextEdit (this);
    // QGLWidget* xxx = new QGLWidget (this);

    // QVBoxLayout* layout = new QVBoxLayout(this);
    // layout->setObjectName(QString::fromUtf8("horizontalLayout"));

    QToolBar* toolBar = new QToolBar(this);
    toolBar->setObjectName(QString::fromUtf8("viewportToolBar"));
    toolBar->setGeometry(QRect(0, 0, 300, 26));
    // layout->addWidget (toolBar);
    // addToolBar(Qt::TopToolBarArea, toolBar);
    // layout->addWidget(xxx);
    */

    QToolBar* toolBar = new QToolBar(this);
    toolBar->addAction("first");
    toolBar->addAction("second");

    QWidget* view = new QTextEdit(this);
    QVBoxLayout* vbox = new QVBoxLayout(this);
    vbox->addWidget(toolBar);
    vbox->addWidget(view);
    // QWidget* widget = new QWidget(); //This is the pane
    // widget->setLayout(vbox);
    // widget->show();
    setLayout(vbox);
    }@

    This is how it looks now
    !http://www.newtondynamics.com/downloads/alchemdiaLook1.jpg(image)!

    And it is better but still does not look like the one made with MFC

    It think the problem is that it has a thick frame, but I do not know how to get rid of it.



  • Hello,

    You should try settings contents margin of layout on which you're placing these four widgets:

    http://doc.qt.nokia.com/latest/qlayout.html#setContentsMargins



  • Use this code:

    @
    alchemediaViewport::alchemediaViewport(QWidget* const parent)
    :QWidget(parent)
    {
    QToolBar* toolBar = new QToolBar(this);
    toolBar->addAction("first");
    toolBar->addAction("second");

    QWidget* view = new QTextEdit(this); 
    QVBoxLayout* vbox = new QVBoxLayout(this); 
    vbox->addWidget(toolBar);
    vbox->addWidget(view);
    vbox->setContentsMargins(0,0,0,0);
    vbox->setSpacing(0);
    setLayout(vbox);
    

    }@



  • It works, Awesometly
    I am very happy with the result so far.

    Thank you, very much


Log in to reply
 

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