Dear friends,
I created UI for widget using QtDesigner, and now I want to customize it a little bit before showing to the user. So I'm trying to do this in the widget's constructor:
public:
{
ui.setupUi(this);
....
// For example: let's move the checkbox
ui.
checkBox->setStyleSheet
(QString("margin-left:%1px;").
arg(p1.
x()-p2.
x()));
// oops ...
}
public:
MyWidget(QWidget *_parent) : QWidget(_parent)
{
ui.setupUi(this);
....
// For example: let's move the checkbox
QPoint p1 = ui.checkBox1->mapToGlobal(QPoint(0, 0));
QPoint p2 = ui.checkBox2->mapToGlobal(QPoint(0, 0));
ui.checkBox->setStyleSheet(QString("margin-left:%1px;").arg(p1.x()-p2.x())); // oops
...
}
To copy to clipboard, switch view to plain text mode
But here I face the problem: p1 and p2 are just the same.
So, I'm wondering:
1. Why they are the same?
2. Is it possible to perform such customization in widget's constructor? I know that "QTimer::singleShot(0, this, SLOT(moveMyCheckbox() ))" will solve this, but I'm not sure if it is not a "dirty hack".
3. What is the best way to do such things?
Bookmarks