LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-07-2011, 08:55 PM   #1
binary_pearl
Member
 
Registered: Jul 2007
Location: Chicago Illinois
Distribution: SLES 10 SP2/SP3, SLES 11 SP1, OpenSUSE, Sabayon, Gentoo, Fedora 14, RHEL 3/4/5/6
Posts: 98
Blog Entries: 3

Rep: Reputation: 23
Qt - How to reference a widget in code


I'm using Qt Creator, and I'm trying to figure out how to change the color of a LineEdit widget in a .cpp file based upon certain conditions.

The code below is what I have to try to change the color of the "thrull_01_le" LineEdit widget. "thrull_01_le" is the value set to 'objectName' of the LineEdit widget in Design mode. I confirmed that the the name "thrull_01_le" is defined as a LineEdit widget name in the .ui file.

However when I try to compile everything, I get the error "thrull_01_le' was not declared in this scope". Is there something I need to include, or is there a different way I should be referencing the widget? If you need more details on what I'm doing in the code, let me know, thanks!


Code:
QPalette p_thrull_01 (thrull_01_le->palette());

if (thrull_01_vitality == 100) {
    p_thrull_01 (QPalette::Base,Qt::green);
    thrull_01_le->setPalette(p_thrull_01);
}
--Shaun
 
Old 08-08-2011, 01:38 AM   #2
pielas
Member
 
Registered: Jan 2009
Location: Poland
Distribution: Arch Linux
Posts: 50

Rep: Reputation: 17
How do you use your UI? Do you inherit from it?
 
Old 08-08-2011, 06:33 AM   #3
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
By default, Qt puts the UI in a separate class and adds it as a member named "ui" to your main window class. So I would try this:

Code:
ui->thrull_01_le->setPalette(p_thrull_01);
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
compiling MESA-Motif widget app....undefined reference to `glwM2DrawingAreaWidgetClas planetfarer Linux - Software 0 06-15-2010 03:58 PM
Showing a widget above a widget in GTK aarontwc Programming 4 11-26-2008 11:40 AM
c++ code syntax help, : Passing by Reference or val ?? vikasumit Programming 4 06-15-2006 08:54 AM
How to get Source code of Gtk File Selection Widget chaits Linux - General 0 04-14-2004 09:43 AM
Need Assembly Code Reference Table marky782 Linux - General 6 02-16-2004 06:53 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:26 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration