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. custom toolbar layout
Forum Updated to NodeBB v4.3 + New Features

custom toolbar layout

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 2 Posters 2.5k Views 2 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.
  • U Offline
    U Offline
    user4592357
    wrote on last edited by
    #1

    i need to have a layout like this:
    action, action (a lot space) action

    so i thought to create a toolbar, and add actions to it.

    i also created a layout where i added widgetForActions for all the 3 actions:

    layout->addWidget(toolbar->widgetForAction(action));
    layout->addStretch();
    layout->addWidget(toolbar->widgetForAction(action));
    

    but well i can't set the layout on the toolbar since it already has one.
    is there a solution to this?

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      You can try using a QSpacerItem.
      http://doc.qt.io/qt-5/qspaceritem.html

      U 1 Reply Last reply
      0
      • mrjjM mrjj

        Hi
        You can try using a QSpacerItem.
        http://doc.qt.io/qt-5/qspaceritem.html

        U Offline
        U Offline
        user4592357
        wrote on last edited by
        #3

        @mrjj
        hi, thanks

        i added it like this:

        toolbar->addWidget(QSpacerItem(4000, 1)->widget());
        

        but it only occupies as much space as other actions (i.e. actions which became tool buttons on tool bar)

        mrjjM 1 Reply Last reply
        0
        • U user4592357

          @mrjj
          hi, thanks

          i added it like this:

          toolbar->addWidget(QSpacerItem(4000, 1)->widget());
          

          but it only occupies as much space as other actions (i.e. actions which became tool buttons on tool bar)

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by mrjj
          #4

          That looks a bit odd syntax. )
          Anyway i checked the docs. not sure it takes one. sorry. my bad.

          Anyway, you can do like this

          ... insert left actions first ..
           QWidget* empty = new QWidget();
            empty->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
            ui->mainToolBar->addWidget(empty);
          // this will be right aligned
            QAction *test= new QAction(this);
            test->setText("RIGHT");
             ui->mainToolBar->addAction(test);
          

          alt text

          U 1 Reply Last reply
          3
          • mrjjM mrjj

            That looks a bit odd syntax. )
            Anyway i checked the docs. not sure it takes one. sorry. my bad.

            Anyway, you can do like this

            ... insert left actions first ..
             QWidget* empty = new QWidget();
              empty->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
              ui->mainToolBar->addWidget(empty);
            // this will be right aligned
              QAction *test= new QAction(this);
              test->setText("RIGHT");
               ui->mainToolBar->addAction(test);
            

            alt text

            U Offline
            U Offline
            user4592357
            wrote on last edited by
            #5

            @mrjj
            learned something new today. thanks.

            mrjjM 1 Reply Last reply
            0
            • U user4592357

              @mrjj
              learned something new today. thanks.

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @user4592357
              me too. i thought Spacers could be put in any layout :)

              U 1 Reply Last reply
              0
              • mrjjM mrjj

                @user4592357
                me too. i thought Spacers could be put in any layout :)

                U Offline
                U Offline
                user4592357
                wrote on last edited by
                #7

                @mrjj :)

                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