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. Border of QToolBar not showing
QtWS25 Last Chance

Border of QToolBar not showing

Scheduled Pinned Locked Moved General and Desktop
7 Posts 3 Posters 3.5k Views
  • 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.
  • 8 Offline
    8 Offline
    8Wallace8
    wrote on last edited by
    #1

    I'm having trouble getting the border of my toolbar to show, which is located on a QWidget. Not sure if i have to set parents or something similar.

    My code: ( I'm only setting up p1 for now to save code. )

    @MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)

    {
    QWidget *p1 = new QWidget;
    QWidget *p2 = new QWidget;
    QWidget *p3 = new QWidget;
    QWidget *p4 = new QWidget;

    QWidget *view = new QTextEdit;
    
    QVBoxLayout *vbox = new QVBoxLayout;
    
    QToolBar *toolBar = new QToolBar;
    toolBar->addAction("file");
    
    vbox->addWidget(toolBar);
    vbox->addWidget(view);
    vbox->setContentsMargins(0,0,0,0);
    vbox->setSpacing(0);
    
    p1->setLayout(vbox);
    
    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;
    
    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);
    

    }@

    1 Reply Last reply
    0
    • raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      since QToolBar derives from QWidget and not from QFrame you won't be able to add a (drawn) border to it.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • N Offline
        N Offline
        NicuPopescu
        wrote on last edited by
        #3

        imho QToolBar,QWidget can have border ... :)

        I tested your code and it's working:

        @...
        QToolBar *toolBar = new QToolBar;
        toolBar->setStyleSheet("QToolBar{border:1px solid rgb(255,0,0);}");
        ...@

        1 Reply Last reply
        0
        • raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #4

          right ... i checked the style painting code.
          My fault ... sorry for that!

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          0
          • 8 Offline
            8 Offline
            8Wallace8
            wrote on last edited by
            #5

            Thanks for the help! But I thought that QToolBar had a default border.

            I'm looking for something like this:
            !http://img69.imageshack.us/img69/1155/cyfi.png!

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

            1 Reply Last reply
            0
            • raven-worxR Offline
              raven-worxR Offline
              raven-worx
              Moderators
              wrote on last edited by
              #6

              you could place the tool bar inside a QFrame though and set the frame style on it. This should give you something like in the first screenshot.

              --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
              If you have a question please use the forum so others can benefit from the solution in the future

              1 Reply Last reply
              0
              • 8 Offline
                8 Offline
                8Wallace8
                wrote on last edited by
                #7

                The picture I referenced is using the same code as me, but I'm getting a different result. I think it has to do with setting up the parents, but not sure. Here is the "link":http://qt-project.org/forums/viewthread/3647to his code.

                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