Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Adding a Toolbar to children widget of a QSplitter
Forum Updated to NodeBB v4.3 + New Features

Adding a Toolbar to children widget of a QSplitter

Scheduled Pinned Locked Moved General and Desktop
8 Posts 3 Posters 14.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    julio jerez
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • S Offline
      S Offline
      situ117
      wrote on last edited by
      #2

      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();
      

      @

      1 Reply Last reply
      0
      • J Offline
        J Offline
        julio jerez
        wrote on last edited by
        #3

        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?

        1 Reply Last reply
        0
        • J Offline
          J Offline
          julio jerez
          wrote on last edited by
          #4

          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?

          1 Reply Last reply
          0
          • J Offline
            J Offline
            julio jerez
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0
            • S Offline
              S Offline
              situ117
              wrote on last edited by
              #6

              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

              1 Reply Last reply
              0
              • G Offline
                G Offline
                giesbert
                wrote on last edited by
                #7

                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);
                

                }@

                Nokia Certified Qt Specialist.
                Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                1 Reply Last reply
                0
                • J Offline
                  J Offline
                  julio jerez
                  wrote on last edited by
                  #8

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

                  Thank you, very much

                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved