The compose layout

The GoMail compose layout is even simpler: we use widgets.QFormLayout again, though the To field is the only line with a label included. For this simpler window, we create widgets.QDialog and set the layout directly on the dialog widget. To add the buttons at the bottom of the screen, we use a new widgets.QWidget with the layout set to widgets.NewQHBoxLayout() to lay the buttons out horizontally. To manage the right alignment, we first include widgets.NewQSpacerItem() in the button box before the buttons. Note lastly that we call SetDefault(true) on the send button so it becomes the default action:

package main

import "github.com/therecipe/qt/widgets"

func showCompose() {
dialog := widgets.NewQDialog(nil, 0)
dialog.SetModal(false)
dialog.SetWindowTitle("New GoMail")

form := widgets.NewQFormLayout(dialog)
dialog.SetLayout(form)
dialog.SetMinimumSize2(400, 320)

form.AddRow5(widgets.NewQLineEdit2("subject", dialog))
form.AddRow3("To", widgets.NewQLineEdit2("email", dialog))
form.AddRow5(widgets.NewQTextEdit2("content", dialog))

buttons := widgets.NewQWidget(dialog, 0)
buttons.SetLayout(widgets.NewQHBoxLayout())
buttons.Layout().AddItem(widgets.NewQSpacerItem(0, 0, widgets.QSizePolicy__Expanding, 0))
buttons.Layout().AddWidget(widgets.NewQPushButton2("Cancel", buttons))
send := widgets.NewQPushButton2("Send", buttons)
send.SetDefault(true)
buttons.Layout().AddWidget(send)
form.AddRow5(buttons)

dialog.Show()
}

From the preceding code, we get the following desired outcomea simple and familiar compose dialog window:

The email compose dialog using qt widgets

Now that the layout is complete, let's connect our test email server to show some email data.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.168.214