Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    How to center a QToolButton in QToolBar?

    General and Desktop
    3
    5
    5275
    Loading More Posts
    • 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.
    • B
      Bambo last edited by

      Hi,
      I add QToolButton into vertical QToolBar (using addWidget() method) and it is aligned to the left.
      How can I aligned it to the center??

      Picture:
      Top I have
      Bottom I need
      !http://www.stud.fit.vutbr.cz/~xadami06/qt.png(qtoolbuttons)!

      In C++, Qt 5.0.1.
      Thanks for quick answer!

      1 Reply Last reply Reply Quote 0
      • B
        b1gsnak3 last edited by

        use a vertical box layout, add the toolbutton to the layout with Qt::AlignCenter and then set the layout to the toolbar

        1 Reply Last reply Reply Quote 0
        • B
          Bambo last edited by

          QVBoxLayout is not good solution, because I have a QActions in ToolBar and QAction can not insert into Layout. Some easier solution did not exist? Something like stylesheet?

          1 Reply Last reply Reply Quote 0
          • B
            b1gsnak3 last edited by

            What you can do is fiddle with the setContentsMargins of the toolbar and work your way untill you align the items as you want.

            1 Reply Last reply Reply Quote 0
            • Jeroentjehome
              Jeroentjehome last edited by

              QAction is nothing more then a quick way to utilize the signal/slot methode. An other option is to remove the actions and in the constructor of the window set the signal / slots as needed.
              Greetz

              Greetz, Jeroen

              1 Reply Last reply Reply Quote 0
              • First post
                Last post