×

Discussion Board

Results 1 to 6 of 6
  1. #1
    Registered User
    Join Date
    Nov 2010
    Posts
    9

    Question how to change toolbar position like this?

    Hi guys, im new to qt and i want to make the app that got tool bar which can reposition to the bottom and the right when the user rotate the phone. how could i do that?

    http://img98.imageshack.us/img98/4204/scr0000020.jpg

    http://img26.imageshack.us/img26/6366/scr000003ny.jpg


    thank you in advance

    regards,
    thanyaluk
    Last edited by thanyalukj; 2010-11-26 at 01:26. Reason: edit image link

  2. #2
    Nokia Developer Champion
    Join Date
    Feb 2008
    Location
    Ahmedabad, Gujarat, India
    Posts
    3,852

    Re: how to change toolbar position like this?

    hello thanyalukj

    I guess its a tab bar at the botton not a toolbar, i am not sure if you can achieve that using toolbar but yes you can make your own widget like that using three button and keeping them is a layout will get you what you want.

  3. #3
    Nokia Developer Expert
    Join Date
    Feb 2008
    Posts
    183

    Re: how to change toolbar position like this?

    You can do it with QToolBar. Just add QActions with icons to the toolbar. When orientation changes, you need to change the toolbar orientation from horizontal to vertical (and back).
    And you might wanna have this fix (coming in 4.7.2): http://bugreports.qt.nokia.com/browse/QTBUG-13120, unless you want to ensure yourself that the toolbar uses screen width properly
    (for hints how to do it even now, see the bug report).

  4. #4
    Registered User
    Join Date
    Nov 2010
    Posts
    9

    Re: how to change toolbar position like this?

    hi there,

    thank you for you answers.

    i tried addToolBar(toolBar) when the device rotate, i set

    toolbar->setOrientation(Qt::Vertical)

    but what i get is the toolbar is still at the bottom of the screen, the bottons is changed their layout, but not the toolbar itself.

    could you please tell me how/codes to set the position of the toolbar?

    regards,

  5. #5
    Nokia Developer Expert
    Join Date
    Feb 2008
    Posts
    183

    Re: how to change toolbar position like this?

    This seems to work for me:
    Code:
    #include <QtGui>
    
    class MainWindow : public QMainWindow
    {
        Q_OBJECT
    
    public:
        MainWindow(QWidget *parent = 0);
        ~MainWindow() { }
    
        bool event ( QEvent * event ) {
            switch(event->type()) {
                case QEvent::StyleChange:
                    if (m_tb->orientation() == Qt::Horizontal)
                        m_tb->setOrientation(Qt::Vertical);
                    else
                        m_tb->setOrientation(Qt::Horizontal);
            }
        }
    
            private:
                QToolBar *m_tb;
    };
    
    MainWindow::MainWindow(QWidget *parent)
        : QMainWindow(parent)
    {
        m_tb = new QToolBar();
        QAction *act1 = new QAction("Test", this);
        QAction *act2 = new QAction("Test2", this);
        m_tb->addAction(act1);
        m_tb->addAction(act2);
    
        QVBoxLayout* layout = new QVBoxLayout();
        layout->addWidget(m_tb);
        m_tb->setLayout(layout);
        setCentralWidget(m_tb);
    }
    
    #include "main.moc"
    int main(int argc, char *argv[])
    {
        QApplication app(argc, argv);
        MainWindow w;
        w.show();
        return app.exec();
    }
    You might wanna re-position the toolbar depending the orientation AND make it fixedWidth in vertical orientation, but the basic case should work.

  6. #6
    Registered User
    Join Date
    Nov 2010
    Posts
    9

    Re: how to change toolbar position like this?

    Eventually i found the way.

    Code:
    void MainWindow::resizeEvent(QResizeEvent *event) {
        QRect screenGeometry = QApplication::desktop()->screenGeometry();
        widgetSize = screenGeometry.size();
        if (widgetSize.width() > widgetSize.height()) {
            addToolBar(Qt::RightToolBarArea,toolBar);
            qDebug() << "MainWindow In Landscape Mode";
        }
        else {
            addToolBar(Qt::BottomToolBarArea,toolBar);
            qDebug() << "MainWindow In Portait Mode";
        }
    }
    but the toolbar doesnt rotate that smooth. not sure if there are another way around it or not?
    Last edited by thanyalukj; 2010-12-13 at 12:11. Reason: found solution

Similar Threads

  1. How to change toolbar text?
    By zs in forum General Development Questions
    Replies: 2
    Last Post: 2010-05-31, 14:17
  2. [moved] Q: How to change toolbar button text
    By bartbiemond in forum Symbian User Interface
    Replies: 1
    Last Post: 2009-10-22, 14:37
  3. change the position of a listbox...
    By nital_shah in forum Symbian
    Replies: 14
    Last Post: 2009-10-07, 13:58
  4. How to change position of ScrollBar?
    By zhangwei_Nirvana in forum Symbian User Interface
    Replies: 1
    Last Post: 2009-06-12, 14:33
  5. Change icon position
    By ajsanchez in forum Symbian
    Replies: 3
    Last Post: 2006-03-19, 20:01

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •