What is the rule for choosing “central widget” in QMainWindow? and why is it important?

前端 未结 2 551
攒了一身酷
攒了一身酷 2021-01-13 16:35

I understand setCentralWidget is required in QMainWindow implementation, and at first sight, it seemed extremely self-explaining what central widget means.

2条回答
  •  一整个雨季
    2021-01-13 17:29

    Usually you don't need a QMainWindow!

    If you don't need docking nor MDI, then don't use QMainWindow: a QWidget or a QDialog will do instead.

    Central means "in the center", as in "in the middle", not as in "important!". QMainWindow's provides docking and multiple document interface (MDI) functionality, and there the notion of a central widget is useful. There can only be one central widget, so "which of many" should be made central is moot: you can't have more than one. One of the fundamental aspects of Qt object design is that QObject is a container of other objects, and so is a QWidget: it's a canvas that you can place other widgets on. So, if you absolutely need docking and/or MDI, then the central widget will be any QWidget that you put other non-docking widgets on. That' all.

提交回复
热议问题