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 make a tabbar last one ???
QtWS25 Last Chance

How to make a tabbar last one ???

Scheduled Pinned Locked Moved General and Desktop
9 Posts 4 Posters 3.2k 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.
  • A Offline
    A Offline
    alonso15
    wrote on last edited by
    #1

    hi I have a QTabBar and i'd like to have a tab that should be like the last tab in a Browser (the addTab "+") but I don't know how to make it the last one (especially when the others move )
    thanks for your help :)

    1 Reply Last reply
    0
    • H Offline
      H Offline
      HuXiKa
      wrote on last edited by
      #2

      There is another way, but I think "this":http://doc.qt.nokia.com/latest/qtabbar.html#setTabButton should do the trick too. If not, I'll post my version tomorrow if I don't forget.

      If you can find faults of spelling in the text above, you can keep them.

      1 Reply Last reply
      0
      • A Offline
        A Offline
        alonso15
        wrote on last edited by
        #3

        thank you HuXiKa but i think that you didn't understand my question i'd like to have this
        http://img4.hostingpics.net/pics/965793Sanstitre.png

        1 Reply Last reply
        0
        • H Offline
          H Offline
          HuXiKa
          wrote on last edited by
          #4

          I understood, and I have a solution, I'll post it :) Although, in my solution the "+" button is the first tab, but it shouldn't be hard to change it.

          If you can find faults of spelling in the text above, you can keep them.

          1 Reply Last reply
          0
          • D Offline
            D Offline
            dbzhang800
            wrote on last edited by
            #5

            If you use QTabWidget, you can consider this:

            void QTabWidget::setCornerWidget ( QWidget * widget, Qt::Corner corner = Qt::TopRightCorner )

            1 Reply Last reply
            0
            • A Offline
              A Offline
              alonso15
              wrote on last edited by
              #6

              Thank you very much HuXiKa
              1+1=2 : setCornerWidget is not a solution because the widget will be in the top right in the corner not near other tabs

              1 Reply Last reply
              0
              • H Offline
                H Offline
                HuXiKa
                wrote on last edited by
                #7

                So, as I'm looking at it, my solution is what 1 + 1 = 2 said (and even more complicated, because I subclassed QTabWidget to have editable tab names):

                @
                QToolButton *newTabButton = new QToolButton(this);
                setCornerWidget(newTabButton, Qt::TopLeftCorner);
                newTabButton->setCursor(Qt::ArrowCursor);
                newTabButton->setAutoRaise(true);
                newTabButton->setIcon(QIcon("add_tab.png"));
                QObject::connect(newTabButton, SIGNAL(clicked()), this, SLOT(addNewTab()));
                newTabButton->setToolTip(tr("New Tab"));
                @

                And the important part of addNewTab slot is:

                @
                void EditableTabWidget::addNewTab()
                {
                QWidget *widget = new QWidget(this);
                addTab(widget,"");
                }@

                The difference here is that the button is in the top left corner, so it's not that far from the tabs.
                If I remember correctly when I tried to solve this problem this was the easiest way, it's complicated to achive the behavior that you want. But google is your friend, try to look for a solution :)

                If you can find faults of spelling in the text above, you can keep them.

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  alonso15
                  wrote on last edited by
                  #8

                  yes I tried this code but the problem is that the button is on the left side and if we change
                  @setCornerWidget(newTabButton, Qt::TopLeftCorner);@ to @setCornerWidget(newTabButton, Qt::TopRightCorner);@ it will be in top right so I don't think that is a solution
                  but i'm trying some codes and like this

                  @MytabWidget::MytabWidget() : QTabWidget
                  {
                  showMaximized();
                  setTabsClosable(true);
                  setMovable(true);
                  QWidget *wid1 = new QWidget;
                  QWidget *wid2 = new QWidget;
                  addTab(wid1, "wid1");
                  addTab(wid2, "+");
                  tabBar()->setTabButton(1, QTabBar::RightSide, 0);

                  connect(this, SIGNAL(currentChanged(int)), this, SLOT(tabChanged(int)));
                          connect(this, SIGNAL(tabCloseRequested(int)), this, SLOT(fermerautreonglet(int)));
                  

                  }@

                  @void MytabWidget::tabChanged(int idx)
                  {
                  if (idx == count()-1)
                  {
                  QWidget *wid3 = new QWidget;
                  insertTab(count()-1, wid3, "new tab");
                  setCurrentIndex(count()-2);
                  }
                  }
                  void MytabWidget::fermerautreonglet(int index)
                  {
                  if (count() > 1)
                  {
                  removeTab(index);
                  }
                  else
                  {
                  qApp->quit();
                  }
                  }@
                  I think that this this code is the best but my problem is when tabs move the "+" tab will lose the last position but i think there is a class that can help us to resolve this problem wich is "QStyleOptionTab":http://doc.trolltech.com/4.7/qstyleoptiontab.html
                  in Public Variables we have TabPosition position i think that this can do it
                  but I'm a newbie and i didn't know how to use it i need your help! thanks

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    maxim.prishchepa
                    wrote on last edited by
                    #9

                    In my project i have some model on the basic of witch i do reinit a tabBar (delete all tabs, and create them again), then if my model talk me what in model no one item to visualize, i create an "empty" tab (like in browser), and at end, i create "Add" tab. And i have connect with TabBar and my class, and when user push at some of tabs, i get a signal, then in connected with this signal slot's i analyze if this tab bar is "Add", then create a new item at model.

                    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

                    • Login

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