问题
I'm in charge of a large-ish (100+KLOC) Qt app with dozens of windows and hundreds of different types of widgets in it.
Today, a user asked me if there was any way to make some of the app's larger windows fit better on his 13" laptop's display.
Of course there are ways to make the windows more space-efficient, reorganize the GUI to allow more showing/hiding of various things, use a smaller font, and so on... but I think what he really wants is a way to simply scale the entire window uniformly down by a certain percent.... an effect something like the what Apple's Expose does, or what some VNC clients do.
So my question is... is there any way to tell Qt to scale an entire window down by x% that doesn't involve modifying/redesigning the majority of the codebase? I know that QPainter has a setScale() method, and QGraphicsView allows nice global scaling, but my app is of the hierarchy-of-QWidgets variety, so I would need a way to scale the entire hierarchy, not just scale within a particular QWidget's canvas.
回答1:
Using stylesheets you can modify the margins and spacing of the widgets, you can change the fonts to be smaller. Anything else would probably require you to rethink the UI design.
回答2:
I don't know about your main program and the GUI that you are using, but assuming you are using a GUi based on a QMainWindow this would work:
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Window w;
w.show();
w.resize(new_width, new_height);
return a.exec();
}
with Window:
namespace Ui {
class Window;
}
class Window : public QMainWindow
{
Q_OBJECT
public:
explicit Window(QWidget *parent = 0);
~Window();
private:
Ui::Window *ui;
};
Assuming you are using QML, there is the same method in the responsible class displaying the qml file.
来源:https://stackoverflow.com/questions/9189238/is-it-possible-to-rescale-a-qt-gui-without-rewriting-the-code