qt 簡易記事本 4

2021-07-08 12:18:43 字數 1909 閱讀 1923

接上次

qpalette:調色盤 用來管理控制項或者窗體的所有顏色資訊

在設定文字區文字的顏色時使用 和 設定文字區背景顏色時使用

不能使用qtextedit::settextcolor(qcolor ) 來設定文字的顏色 這樣當文字清空後 新增的文字顏色又恢復為原來的顏色

需要使用qtextedit::setpalette(qpalette ) 給文字區設定調色盤 

qcolordialog color_dlg;  //顏色對話方塊

qcolor color;    //字型預設定的顏色

qpalette palette = edit->palette(); //首先獲得 文字區的調色盤物件

color = color_dlg.getcolor(qt::black); //預設為黑色

if (color.isvalid())  //顏色有效

qpalette::setcolor(qpalette::colorrole ,qcolor ) //設定調色盤的屬性 和調色盤的顏色

上面設定的就是文字區的前景色(qpalette::text) 也就是文字的顏色 預設定的顏色為從顏色對話方塊返回的顏色

類似的還有qpalette::base 就是文字區的背景色 也就是文字區的背景顏色 

qpalette::window 視窗部件的背景色

qpalette::button 按鈕部件的背景色

qpalette::buttontext 按鈕部件的前景色

還有一些 去看文件吧

qstatusbar:狀態列

qstatusbar::show() //顯示狀態列

qstatusbar::hide() //隱藏狀態列

在模仿windows檢視選單中的 狀態列項 時使用

在狀態列的右下角顯示當前游標所在行 和 列

列好獲取

textcursor = edit->textcursor(); //獲取文字區的游標

int col = textcursor.columnnumber(); //這樣就獲取到了游標所在的列

行就不好了獲取了

textcursor.blocknumber(); //這樣獲取不對 這樣獲取的是段落號碼

textcursor = edit->textcursor();

qtextlayout *textlayout = textcursor.block().layout();

int temp_raw = textcursor.position() - textcursor.block().position();

int raw = textlayout->linefortextposition(temp_raw).linenumber() + textcursor.block().firstlinenumber();

raw++; 這句不要忘了 不然行號是從0開始的

qlabel *raw_col;

raw_col->settext(tr("第%1行,第%2列").arg(raw).arg(col)); //這樣就給標籤設定了 游標的行 和 列 //qstring::arg()//用字串變數引數依次替代字串中最小數值

///

qmessagebox:訊息提示框

qmessagebox::settext(qstring ) //設定訊息提示框 顯示的內容

還有許多的成員函式 可以定製出隨心所欲的提示框

不要使用qmessagebox::show() //這樣寫 提示框會一閃而過

應該使用qmessagebox::exec() //這樣寫 是對的 阻塞別的視窗

效果:

不對的地方 請批評指正



qt 簡易記事本 6

接上次 qdialog 基礎對話方塊 一般將其作為基類 繼承該類 qdialog setwindowtitle qstring 設定視窗的標題 函式名很是淺顯易懂 qdialog setwindowflags qt windowflags 設定視窗的一些風格 下面是一些常用的 qt windowcl...

簡易記事本 C 窗體

using system using system.collections.generic using system.componentmodel using system.data using system.drawing using system.text using system.window...

個人記事本

size t strlen const char s the strlen function calculates the length of the string s,excluding 不包括 the terminating null byte 0 計算長度時,不包括末尾的結束符 0 但是,換行...