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. How to center a QToolButton in QToolBar?

How to center a QToolButton in QToolBar?

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 5.7k 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.
  • B Offline
    B Offline
    Bambo
    wrote on last edited by
    #1

    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
    0
    • B Offline
      B Offline
      b1gsnak3
      wrote on last edited by
      #2

      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
      0
      • B Offline
        B Offline
        Bambo
        wrote on last edited by
        #3

        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
        0
        • B Offline
          B Offline
          b1gsnak3
          wrote on last edited by
          #4

          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
          0
          • JeroentjehomeJ Offline
            JeroentjehomeJ Offline
            Jeroentjehome
            wrote on last edited by
            #5

            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
            0

            • Login

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