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?
[url]http://img98.imageshack.us/img98/4204/scr0000020.jpg[/url]
[url]http://img26.imageshack.us/img26/6366/scr000003ny.jpg[/url]
thank you in advance:)
regards,
thanyaluk
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.
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): [url]http://bugreports.qt.nokia.com/browse/QTBUG-13120[/url], 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).
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,
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();
}
[/CODE]
You might wanna re-position the toolbar depending the orientation AND make it fixedWidth in vertical orientation, but the basic case should work.
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";
}
}[/CODE]
but the toolbar doesnt rotate that smooth. not sure if there are another way around it or not?