Save and Restore QToolbar position
-
Please do not extend your posts...
[quote author="ddriver" date="1331816587"]QToolBar has NO save and restore state methods! Unless someone else knows a standard way to do it with the Qt API, you will have to do it yourself in the manner I keep on describing to you.[/quote]
[quote author="ddriver" date="1331818311"]I already told you how, both in short and in detail, and you still ask?[/quote]
So, it is impossible, isn't it?Otherwise, could you show me how to get and restore the position?
[code]
ostream << m_toolBar1->position();
...
m_toolBar1->setPosition(getPosition(istream));
[/code] -
Can't you read English? I already told you HOW to do it, by what type of logic you assume it is impossible? Judging from your responses it seems like you need to work on your C++ and basic programming skills before you rush into building applications.
QToolBar inherits a QPoint returning member function called pos from QWidget that holds the position of the toolbar in its parent widget.
Start off by a bool isToolBar1Created, set it to false, when your user creates the toolbar, then set it to true.
Then have another one, bool isToolBar1Docked, when the user docks the toobar, set it to true, when the user detaches the toolbar to be floating, set it to false.
Then have a third variable that depending on whether the toolbar is floating or not, contains either its position or the location it is docked at.
When the user quits the application, write the three variables to a file. When the application is ran again, read in the file, if the first variable is false, then you don't create a toolbar, if it is true, then you create the toolbar, when you create it, check the second variable, if it is true then read the third for the dock location and dock the toolbar in that location. If it is false, set the toobar to floating and move it to the position stored in the third variable.
100% possible as you see.
-
Please stop editing your posts.
[quote author="ddriver" date="1331819488"]I already told you HOW to do it, by what type of logic you assume it is impossible?[/quote]
You said everything, but not a word about a position. I need a postion, a relative position, a floation position, not visibility, not if its dockable or not, not orientation. A position. Just a position. -
[quote author="ddriver" date="1331819488"]
QToolBar inherits a QPoint returning member function called pos from QWidget that holds the position of the toolbar in its parent widget.[/quote]Also, learn how to use the PLENTIFUL and DETAILED Qt documentation.
bq. pos : QPoint
This property holds the position of the widget within its parent widget.You also have:
@void move ( const QPoint & )@
which, in case you cannot figure out, moves the widget to the QPoint location.
http://qt-project.org/doc/qt-4.8/qtoolbar-members.html
http://qt-project.org/doc/qt-4.8/qwidget.html#pos-propAs you probably (don't) see, it is not only ENTIRELY possible, but QUITE EASY...
I also suggest you remove that foolish "[Impossible in Qt!]" qualifier from your thread and rethink your strategy - I really don't think you will go far into programming if you expect others to do the thinking and reading for you.
-
It is cool how you change your posts in the past from the future...
-
Certainly not as cool as being a lazy ungrateful jackass to people who waste their time to help you. Good luck, I am done with you!
-
[quote author="ddriver" date="1331829830"]Certainly not as cool as being a lazy ungrateful jackass to people who waste their time to help you. Good luck, I am done with you![/quote]
I hope you will not come back, dude. -
ddriver: There is no need to call people names here. Just move on to another thread if somebody annoys you.
-
[quote author="ddriver" date="1331819988"][quote author="ddriver" date="1331819488"]
QToolBar inherits a QPoint returning member function called pos from QWidget that holds the position of the toolbar in its parent widget.[/quote]
This property holds the position of the widget within its parent widget.
You also have:
@void move ( const QPoint & )@
which, in case you cannot figure out, moves the widget to the QPoint location.
[/quote]It just does not work with QToolBar, dude.
Try it youself:[code]
QPoint posa(m_toolBar1->pos());
m_toolBar1->move(pos.x()+10, pos.y());
[/code]The toolbar stays where it was.
-
Both pos() and move() work for me perfectly well, when the toolbar is docked it returns and moves to coordinates, relative to the application window, when floating, it is relative to the active display, so the problem is all in your "TV", dude!
@Tobias Hunger - it wasn't a name, but a definition, it is offensive only when it is degrading, if it is justified and objective - I don't think there is something wrong with calling things what they are :)
-
O, really?
[code]
#include <QtGui>int main(int argc, char argv[])
{
QApplication a(argc, argv);
QMainWindow wnd1;
QMainWindow wnd(&wnd1);
QToolBar* m_toolBar1 = new QToolBar(wnd);
QAction* action1 = new QAction("test 1", m_toolBar1);
action1->setText("1");
m_toolBar1->addAction(action1);QToolBar* m_toolBar2 = new QToolBar(wnd); QAction* action2 = new QAction("test 2", m_toolBar2); m_toolBar2->addAction(action2); action2->setText("2"); wnd->addToolBar(m_toolBar1); wnd->addToolBar(m_toolBar2); wnd->setCentralWidget(new QLabel("text")); wnd1.show(); m_toolBar2->resize(200, 100); m_toolBar2->move(200, 200); return a.exec();
}
[/code] -
Is that why you deleted your profile? I assumed you were just ashamed and went for a fresh and better start, but seeing how you mock my username, which further solidifies my theory that you are indeed a jackass, I see I overestimated you. I suggest you delete that profile as well, because your behavior gives me a good reason to report you on personal basis, then make yourself a normal profile and start behaving like a grown man, not a spoiled brat.
And just to assure you the methods work perfectly fine, here is a few screenshots in an animated gif and some code:
!http://i39.tinypic.com/2119xmu.gif!
@void MainWindow::setPos()
{
ui->mainToolBar->move(ui->spinX->value(), ui->spinY->value());
}void MainWindow::getPos()
{
ui->spinX->setValue(ui->mainToolBar->pos().x());
ui->spinY->setValue(ui->mainToolBar->pos().y());
}@