Благодаря ответам Донроби и Дэвида, я думаю, что я понимаю, что основная проблема с введением контрастной дисперсии параметра - интеграция с механизмом перегрузки .
Таким образом, проблема не только с одним переопределением для нескольких методов, но и с другой стороны:
class A {
public void f(String s) {...}
}
class B extends A {
public void f(String s) {...} // this can override A.f
public void f(Object o) {...} // with contra-variance, so can this!
}
И теперь есть два допустимых переопределения для одного и того же метода:
A a = new B();
a.f(); // which f is called?
Кроме проблем с перегрузкой, я не мог думать ни о чем другом.
Редактировать: С тех пор я нашел эту запись C ++ FQA (20.8) , которая согласуется с вышесказанным - наличие перегрузки создает серьезную проблему для противоречивости параметров.
Automatic solution:
Use layouts and set size policies to QSizePolicy::Expanding
. In QtDesigner, once all your children are placed on your QDialog, then click on the Adjust Size button next layout ones. Your QDialog will be automatically resized at runtime.
Manual solution:
The QWidget
class has a method adjustSize
that resize the QWidget to fit its content. Just call it when all children are set.
Set your dialog to be expanding, and very small. Then, be sure to set your message before showing the dialog. When shown, it will try to find its proper size, based on the size of the objects it contains. (This happens recursively, so if the dialog isn't the direct parent of the label in which you show your message, make sure everything between the label and the dialog is set to use layouts.)